mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-05-18 01:09:29 +00:00
removes blockStoreManager module
This commit is contained in:
parent
41ae2abe62
commit
cbedb2a1d8
@ -45,7 +45,8 @@ type
|
|||||||
config: CodexConf
|
config: CodexConf
|
||||||
restServer: RestServerRef
|
restServer: RestServerRef
|
||||||
codexNode: CodexNodeRef
|
codexNode: CodexNodeRef
|
||||||
blockStoreManager: BlockStoreManager
|
repoStore: RepoStore
|
||||||
|
blockMaintainer: BlockMaintainer
|
||||||
|
|
||||||
CodexPrivateKey* = libp2p.PrivateKey # alias
|
CodexPrivateKey* = libp2p.PrivateKey # alias
|
||||||
|
|
||||||
@ -93,7 +94,8 @@ proc bootstrapInteractions(config: CodexConf, repo: RepoStore): Future[Contracts
|
|||||||
proc start*(s: CodexServer) {.async.} =
|
proc start*(s: CodexServer) {.async.} =
|
||||||
notice "Starting codex node"
|
notice "Starting codex node"
|
||||||
|
|
||||||
await s.blockStoreManager.start()
|
await s.repoStore.start()
|
||||||
|
s.blockMaintainer.start()
|
||||||
s.restServer.start()
|
s.restServer.start()
|
||||||
|
|
||||||
s.codexNode.contracts = await bootstrapInteractions(s.config, s.repoStore)
|
s.codexNode.contracts = await bootstrapInteractions(s.config, s.repoStore)
|
||||||
@ -133,10 +135,39 @@ proc stop*(s: CodexServer) {.async.} =
|
|||||||
await allFuturesThrowing(
|
await allFuturesThrowing(
|
||||||
s.restServer.stop(),
|
s.restServer.stop(),
|
||||||
s.codexNode.stop(),
|
s.codexNode.stop(),
|
||||||
s.blockStoreManager.stop())
|
s.repoStore.stop(),
|
||||||
|
s.blockMaintainer.stop())
|
||||||
|
|
||||||
s.runHandle.complete()
|
s.runHandle.complete()
|
||||||
|
|
||||||
|
proc new(_: type ContractInteractions, config: CodexConf): ?ContractInteractions =
|
||||||
|
if not config.persistence:
|
||||||
|
if config.ethAccount.isSome:
|
||||||
|
warn "Ethereum account was set, but persistence is not enabled"
|
||||||
|
return
|
||||||
|
|
||||||
|
without account =? config.ethAccount:
|
||||||
|
error "Persistence enabled, but no Ethereum account was set"
|
||||||
|
quit QuitFailure
|
||||||
|
|
||||||
|
if deployment =? config.ethDeployment:
|
||||||
|
ContractInteractions.new(config.ethProvider, account, deployment)
|
||||||
|
else:
|
||||||
|
ContractInteractions.new(config.ethProvider, account)
|
||||||
|
|
||||||
|
proc createDataStore(config: CodexConf): Datastore =
|
||||||
|
case config.repoKind
|
||||||
|
of repoFS:
|
||||||
|
return Datastore(FSDatastore.new($config.dataDir, depth = 5).expect("Should create repo file data store!"))
|
||||||
|
of repoSQLite:
|
||||||
|
return Datastore(SQLiteDatastore.new($config.dataDir).expect("Should create repo SQLite data store!"))
|
||||||
|
raise newException(Defect, "Unknown repoKind: " & $config.repoKind)
|
||||||
|
|
||||||
|
proc getLocalBlockStore(repoStore: RepoStore, configCacheSize: Natural): BlockStore =
|
||||||
|
if configCacheSize > 0:
|
||||||
|
return CacheStore.new(backingStore = repoStore, cacheSize = configCacheSize * MiB)
|
||||||
|
return repoStore
|
||||||
|
|
||||||
proc new*(T: type CodexServer, config: CodexConf, privateKey: CodexPrivateKey): T =
|
proc new*(T: type CodexServer, config: CodexConf, privateKey: CodexPrivateKey): T =
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -177,21 +208,27 @@ proc new*(T: type CodexServer, config: CodexConf, privateKey: CodexPrivateKey):
|
|||||||
wallet = WalletRef.new(EthPrivateKey.random())
|
wallet = WalletRef.new(EthPrivateKey.random())
|
||||||
network = BlockExcNetwork.new(switch)
|
network = BlockExcNetwork.new(switch)
|
||||||
|
|
||||||
blockStoreManager = BlockStoreManager.new(BlockStoreManagerConfig(
|
dataStore = createDataStore(config)
|
||||||
dataDir: config.dataDir,
|
|
||||||
storageQuota: config.storageQuota,
|
repoStore =
|
||||||
blockTtlSeconds: config.blockTtlSeconds,
|
RepoStore.new(
|
||||||
blockMaintenanceIntervalSeconds: config.blockMaintenanceIntervalSeconds,
|
repoDs = dataStore,
|
||||||
blockMaintenanceNumberOfBlocks: config.blockMaintenanceNumberOfBlocks,
|
metaDs = SQLiteDatastore.new(config.dataDir / CodexMetaNamespace).expect("Should create meta data store!"),
|
||||||
cacheSize: config.cacheSize,
|
quotaMaxBytes = config.storageQuota.uint,
|
||||||
repoKind: config.repoKind))
|
blockTtl = config.blockTtlSeconds.seconds)
|
||||||
blockStore = blockStoreManager.getBlockStore()
|
|
||||||
|
blockMaintainer = BlockMaintainer.new(
|
||||||
|
repoStore,
|
||||||
|
interval = config.blockMaintenanceIntervalSeconds.seconds,
|
||||||
|
numberOfBlocksPerInterval = config.blockMaintenanceNumberOfBlocks)
|
||||||
|
|
||||||
|
localBlockStore = getLocalBlockStore(repoStore, config.cacheSize)
|
||||||
|
|
||||||
peerStore = PeerCtxStore.new()
|
peerStore = PeerCtxStore.new()
|
||||||
pendingBlocks = PendingBlocksManager.new()
|
pendingBlocks = PendingBlocksManager.new()
|
||||||
blockDiscovery = DiscoveryEngine.new(blockStore, peerStore, network, discovery, pendingBlocks)
|
blockDiscovery = DiscoveryEngine.new(localBlockStore, peerStore, network, discovery, pendingBlocks)
|
||||||
engine = BlockExcEngine.new(blockStore, wallet, network, blockDiscovery, peerStore, pendingBlocks)
|
engine = BlockExcEngine.new(localBlockStore, wallet, network, blockDiscovery, peerStore, pendingBlocks)
|
||||||
store = NetworkStore.new(engine, blockStore)
|
store = NetworkStore.new(engine, localBlockStore)
|
||||||
erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider)
|
erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider)
|
||||||
codexNode = CodexNodeRef.new(switch, store, engine, erasure, discovery)
|
codexNode = CodexNodeRef.new(switch, store, engine, erasure, discovery)
|
||||||
restServer = RestServerRef.new(
|
restServer = RestServerRef.new(
|
||||||
@ -206,4 +243,5 @@ proc new*(T: type CodexServer, config: CodexConf, privateKey: CodexPrivateKey):
|
|||||||
config: config,
|
config: config,
|
||||||
codexNode: codexNode,
|
codexNode: codexNode,
|
||||||
restServer: restServer,
|
restServer: restServer,
|
||||||
blockStoreManager: blockStoreManager)
|
repoStore: repoStore,
|
||||||
|
blockMaintainer: blockMaintainer)
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import ./stores/blockstoremanager
|
|
||||||
import ./stores/cachestore
|
import ./stores/cachestore
|
||||||
import ./stores/blockstore
|
import ./stores/blockstore
|
||||||
import ./stores/networkstore
|
import ./stores/networkstore
|
||||||
@ -6,5 +5,6 @@ import ./stores/repostore
|
|||||||
import ./stores/memorystore
|
import ./stores/memorystore
|
||||||
import ./stores/maintenance
|
import ./stores/maintenance
|
||||||
import ./stores/keyutils
|
import ./stores/keyutils
|
||||||
|
import ./stores/consts
|
||||||
|
|
||||||
export blockstoremanager, cachestore, blockstore, networkstore, repostore, memorystore, maintenance, keyutils
|
export cachestore, blockstore, networkstore, repostore, memorystore, maintenance, keyutils, consts
|
||||||
|
|||||||
@ -1,84 +0,0 @@
|
|||||||
## Nim-Codex
|
|
||||||
## Copyright (c) 2023 Status Research & Development GmbH
|
|
||||||
## Licensed under either of
|
|
||||||
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
||||||
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
||||||
## at your option.
|
|
||||||
## This file may not be copied, modified, or distributed except according to
|
|
||||||
## those terms.
|
|
||||||
|
|
||||||
import std/os
|
|
||||||
|
|
||||||
import pkg/chronos
|
|
||||||
import pkg/datastore
|
|
||||||
import pkg/confutils
|
|
||||||
import pkg/confutils/defs
|
|
||||||
|
|
||||||
import ../namespaces
|
|
||||||
import ./consts
|
|
||||||
import ./blockstore
|
|
||||||
import ./repostore
|
|
||||||
import ./cachestore
|
|
||||||
import ./maintenance
|
|
||||||
|
|
||||||
type
|
|
||||||
BlockStoreManager* = ref object of RootObj
|
|
||||||
repoStore: RepoStore
|
|
||||||
maintenance: BlockMaintainer
|
|
||||||
blockStore: BlockStore
|
|
||||||
BlockStoreManagerConfig* = ref object
|
|
||||||
dataDir*: OutDir
|
|
||||||
storageQuota*: Natural
|
|
||||||
blockTtlSeconds*: int
|
|
||||||
blockMaintenanceIntervalSeconds*: int
|
|
||||||
blockMaintenanceNumberOfBlocks*: int
|
|
||||||
cacheSize*: Natural
|
|
||||||
repoKind*: RepoKind
|
|
||||||
|
|
||||||
proc start*(self: BlockStoreManager): Future[void] {.async.} =
|
|
||||||
await self.repoStore.start()
|
|
||||||
self.maintenance.start()
|
|
||||||
|
|
||||||
proc stop*(self: BlockStoreManager): Future[void] {.async.} =
|
|
||||||
await self.repoStore.stop()
|
|
||||||
await self.maintenance.stop()
|
|
||||||
|
|
||||||
proc getBlockStore*(self: BlockStoreManager): BlockStore =
|
|
||||||
self.blockStore
|
|
||||||
|
|
||||||
proc getRepoDatastore(config: BlockStoreManagerConfig): Datastore =
|
|
||||||
case config.repoKind
|
|
||||||
of repoFS:
|
|
||||||
return Datastore(FSDatastore.new($config.dataDir, depth = 5).expect("Should create repo file data store!"))
|
|
||||||
of repoSQLite:
|
|
||||||
return Datastore(SQLiteDatastore.new($config.dataDir).expect("Should create repo SQLite data store!"))
|
|
||||||
raise newException(Defect, "Unknown repoKind: " & $config.repoKind)
|
|
||||||
|
|
||||||
proc createRepoStore(config: BlockStoreManagerConfig): RepoStore =
|
|
||||||
RepoStore.new(
|
|
||||||
repoDs = getRepoDatastore(config),
|
|
||||||
metaDs = SQLiteDatastore.new(config.dataDir / CodexMetaNamespace).expect("Should create meta data store!"),
|
|
||||||
quotaMaxBytes = config.storageQuota.uint,
|
|
||||||
blockTtl = config.blockTtlSeconds.seconds)
|
|
||||||
|
|
||||||
proc createMaintenance(repoStore: RepoStore, config: BlockStoreManagerConfig): BlockMaintainer =
|
|
||||||
BlockMaintainer.new(
|
|
||||||
repoStore,
|
|
||||||
interval = config.blockMaintenanceIntervalSeconds.seconds,
|
|
||||||
numberOfBlocksPerInterval = config.blockMaintenanceNumberOfBlocks)
|
|
||||||
|
|
||||||
proc getBlockStore(repoStore: RepoStore, config: BlockStoreManagerConfig): BlockStore =
|
|
||||||
if config.cacheSize > 0:
|
|
||||||
return CacheStore.new(backingStore = repoStore, cacheSize = config.cacheSize * MiB)
|
|
||||||
return repoStore
|
|
||||||
|
|
||||||
proc new*(T: type BlockStoreManager, config: BlockStoreManagerConfig): T =
|
|
||||||
let
|
|
||||||
repoStore = createRepoStore(config)
|
|
||||||
maintenance = createMaintenance(repoStore, config)
|
|
||||||
blockStore = getBlockStore(repoStore, config)
|
|
||||||
|
|
||||||
T(
|
|
||||||
repoStore: repoStore,
|
|
||||||
maintenance: maintenance,
|
|
||||||
blockStore: blockStore)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user