Wires up selecting of repostore kind from config.

This commit is contained in:
benbierens 2023-03-15 11:36:38 +01:00
parent 3599b471c2
commit ee88b6ce35
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 19 additions and 10 deletions

View File

@ -183,7 +183,8 @@ proc new*(T: type CodexServer, config: CodexConf, privateKey: CodexPrivateKey):
blockTtlSeconds: config.blockTtlSeconds,
blockMaintenanceIntervalSeconds: config.blockMaintenanceIntervalSeconds,
blockMaintenanceNumberOfBlocks: config.blockMaintenanceNumberOfBlocks,
cacheSize: config.cacheSize))
cacheSize: config.cacheSize,
repoKind: config.repoKind))
blockStore = blockStoreManager.getBlockStore()
peerStore = PeerCtxStore.new()

View File

@ -32,6 +32,7 @@ import pkg/ethers
import ./discovery
import ./stores
import ./consts
export DefaultCacheSizeMiB, net, DefaultQuotaBytes, DefaultBlockTtl, DefaultBlockMaintenanceInterval, DefaultNumberOfBlocksToMaintainPerInterval
@ -47,10 +48,6 @@ type
Json = "json"
None = "none"
RepoKind* = enum
repoFS = "fs"
repoSQLite = "sqlite"
CodexConf* = object
configFile* {.
desc: "Loads the configuration from a TOML file"

View File

@ -1,2 +1,8 @@
type
RepoKind* = enum
repoFS = "fs"
repoSQLite = "sqlite"
const
MiB* = 1024 * 1024

View File

@ -33,6 +33,7 @@ type
blockMaintenanceIntervalSeconds*: int
blockMaintenanceNumberOfBlocks*: int
cacheSize*: Natural
repoKind*: RepoKind
proc start*(self: BlockStoreManager): Future[void] {.async.} =
await self.repoStore.start()
@ -45,9 +46,17 @@ proc stop*(self: BlockStoreManager): Future[void] {.async.} =
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 = Datastore(FSDatastore.new($config.dataDir, depth = 5).expect("Should create repo data store!")),
repoDs = getRepoDatastore(config),
metaDs = SQLiteDatastore.new(config.dataDir / CodexMetaNamespace).expect("Should create meta data store!"),
quotaMaxBytes = config.storageQuota.uint,
blockTtl = config.blockTtlSeconds.seconds)

View File

@ -16,11 +16,7 @@ import pkg/questionable
import pkg/questionable/results
import pkg/codex/blocktype as bt
import pkg/codex/stores/repostore
import pkg/codex/clock
import ../helpers/mocktimer
import ../helpers/mockrepostore
import ../helpers/mockclock
import ../examples
import codex/namespaces