From ee88b6ce356da7917d90a68a6e69f2bd15a1520d Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 15 Mar 2023 11:36:38 +0100 Subject: [PATCH] Wires up selecting of repostore kind from config. --- codex/codex.nim | 3 ++- codex/conf.nim | 5 +---- codex/consts.nim | 6 ++++++ codex/stores/blockstoremanager.nim | 11 ++++++++++- tests/codex/stores/testkeyutils.nim | 4 ---- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/codex/codex.nim b/codex/codex.nim index 5585500b..4cf8d623 100644 --- a/codex/codex.nim +++ b/codex/codex.nim @@ -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() diff --git a/codex/conf.nim b/codex/conf.nim index 75299e51..0c879731 100644 --- a/codex/conf.nim +++ b/codex/conf.nim @@ -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" diff --git a/codex/consts.nim b/codex/consts.nim index 304bb91c..c2b547ba 100644 --- a/codex/consts.nim +++ b/codex/consts.nim @@ -1,2 +1,8 @@ + +type + RepoKind* = enum + repoFS = "fs" + repoSQLite = "sqlite" + const MiB* = 1024 * 1024 diff --git a/codex/stores/blockstoremanager.nim b/codex/stores/blockstoremanager.nim index f27d7374..62520176 100644 --- a/codex/stores/blockstoremanager.nim +++ b/codex/stores/blockstoremanager.nim @@ -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) diff --git a/tests/codex/stores/testkeyutils.nim b/tests/codex/stores/testkeyutils.nim index 734d33b9..c2348124 100644 --- a/tests/codex/stores/testkeyutils.nim +++ b/tests/codex/stores/testkeyutils.nim @@ -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