diff --git a/nimbus/db/core_db/persistent.nim b/nimbus/db/core_db/persistent.nim index 1a908aa2c..8cd0d7557 100644 --- a/nimbus/db/core_db/persistent.nim +++ b/nimbus/db/core_db/persistent.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -16,13 +16,20 @@ {.push raises: [].} import - ../aristo, - ./backend/[aristo_rocksdb, legacy_rocksdb], - ./memory_only + ../aristo, + ./memory_only, + ../select_backend export - memory_only, - toRocksStoreRef + memory_only + +# Allow hive sim to compile with dbBackend == none +when dbBackend == rocksdb: + import + ./backend/[aristo_rocksdb, legacy_rocksdb] + + export + toRocksStoreRef proc newCoreDbRef*( dbType: static[CoreDbType]; # Database type symbol @@ -32,14 +39,15 @@ proc newCoreDbRef*( ## ## Note: Using legacy notation `newCoreDbRef()` rather than ## `CoreDbRef.init()` because of compiler coughing. - when dbType == LegacyDbPersistent: - newLegacyPersistentCoreDbRef path - - elif dbType == AristoDbRocks: - newAristoRocksDbCoreDbRef path - - else: - {.error: "Unsupported dbType for persistent newCoreDbRef()".} + when dbBackend == rocksdb: + when dbType == LegacyDbPersistent: + newLegacyPersistentCoreDbRef path + + elif dbType == AristoDbRocks: + newAristoRocksDbCoreDbRef path + + else: + {.error: "Unsupported dbType for persistent newCoreDbRef()".} proc newCoreDbRef*( dbType: static[CoreDbType]; # Database type symbol @@ -50,11 +58,12 @@ proc newCoreDbRef*( ## ## Note: Using legacy notation `newCoreDbRef()` rather than ## `CoreDbRef.init()` because of compiler coughing. - when dbType == AristoDbRocks: - newAristoRocksDbCoreDbRef(path, qlr) - - else: - {.error: "Unsupported dbType for persistent newCoreDbRef()" & - " with qidLayout argument".} + when dbBackend == rocksdb: + when dbType == AristoDbRocks: + newAristoRocksDbCoreDbRef(path, qlr) + + else: + {.error: "Unsupported dbType for persistent newCoreDbRef()" & + " with qidLayout argument".} # End diff --git a/nimbus/sync/snap/worker/db/snapdb_accounts.nim b/nimbus/sync/snap/worker/db/snapdb_accounts.nim index 009c68ec8..f84d64971 100644 --- a/nimbus/sync/snap/worker/db/snapdb_accounts.nim +++ b/nimbus/sync/snap/worker/db/snapdb_accounts.nim @@ -1,5 +1,5 @@ # nimbus-eth1 -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -20,6 +20,9 @@ import hexary_interpolate, hexary_inspect, hexary_paths, snapdb_desc, snapdb_persistent] +import + ../../../../db/select_backend + logScope: topics = "snap-db" @@ -63,13 +66,14 @@ proc persistentAccounts( ): Result[void,HexaryError] {.gcsafe, raises: [OSError,IOError,KeyError].} = ## Store accounts trie table on databse - if ps.rockDb.isNil: - let rc = db.persistentAccountsPut(ps.kvDb) - if rc.isErr: return rc - else: - let rc = db.persistentAccountsPut(ps.rockDb) - if rc.isErr: return rc - ok() + when dbBackend == rocksdb: + if ps.rockDb.isNil: + let rc = db.persistentAccountsPut(ps.kvDb) + if rc.isErr: return rc + else: + let rc = db.persistentAccountsPut(ps.rockDb) + if rc.isErr: return rc + ok() proc collectAccounts( diff --git a/nimbus/sync/snap/worker/db/snapdb_contracts.nim b/nimbus/sync/snap/worker/db/snapdb_contracts.nim index bf94655e4..4de9e5b21 100644 --- a/nimbus/sync/snap/worker/db/snapdb_contracts.nim +++ b/nimbus/sync/snap/worker/db/snapdb_contracts.nim @@ -1,5 +1,5 @@ # nimbus-eth1 -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -16,6 +16,9 @@ import ../../range_desc, "."/[hexary_desc, hexary_error, snapdb_desc, snapdb_persistent] +import + ../../../../db/select_backend + logScope: topics = "snap-db" @@ -46,15 +49,16 @@ proc persistentContracts( ): Result[void,HexaryError] {.gcsafe, raises: [OSError,IOError,KeyError].} = ## Store contract codes onto permanent database - if ps.rockDb.isNil: - let rc = data.persistentContractPut ps.kvDb - if rc.isErr: - return rc - else: - let rc = data.persistentContractPut ps.rockDb - if rc.isErr: - return rc - ok() + when dbBackend == rocksdb: + if ps.rockDb.isNil: + let rc = data.persistentContractPut ps.kvDb + if rc.isErr: + return rc + else: + let rc = data.persistentContractPut ps.rockDb + if rc.isErr: + return rc + ok() # ------------------------------------------------------------------------------ # Public constructor diff --git a/nimbus/sync/snap/worker/db/snapdb_desc.nim b/nimbus/sync/snap/worker/db/snapdb_desc.nim index 66815d29d..b60b80871 100644 --- a/nimbus/sync/snap/worker/db/snapdb_desc.nim +++ b/nimbus/sync/snap/worker/db/snapdb_desc.nim @@ -1,5 +1,5 @@ # nimbus-eth1 -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -35,7 +35,9 @@ type ## Global, re-usable descriptor keyMap: Table[RepairKey,uint] ## For debugging only (will go away) db: CoreDbRef ## General database - rocky: RocksStoreRef ## Set if rocksdb is available + # Allow hive sim to compile with dbBackend == none + when dbBackend == rocksdb: + rocky: RocksStoreRef ## Set if rocksdb is available SnapDbBaseRef* = ref object of RootRef ## Session descriptor @@ -69,14 +71,15 @@ proc keyPp(a: RepairKey; pv: SnapDbRef): string = # Private helper # ------------------------------------------------------------------------------ -proc clearRockyCacheFile(rocky: RocksStoreRef): bool = - if not rocky.isNil: - # A cache file might hang about from a previous crash - try: - discard rocky.clearCacheFile(RockyBulkCache) - return true - except OSError as e: - error "Cannot clear rocksdb cache", exception=($e.name), msg=e.msg +when dbBackend == rocksdb: + proc clearRockyCacheFile(rocky: RocksStoreRef): bool = + if not rocky.isNil: + # A cache file might hang about from a previous crash + try: + discard rocky.clearCacheFile(RockyBulkCache) + return true + except OSError as e: + error "Cannot clear rocksdb cache", exception=($e.name), msg=e.msg # ------------------------------------------------------------------------------ # Public constructor @@ -87,7 +90,8 @@ proc init*( db: CoreDbRef ): T = ## Main object constructor - T(db: db, rocky: db.backend.toRocksStoreRef) + when dbBackend == rocksdb: + T(db: db, rocky: db.backend.toRocksStoreRef) proc init*( T: type HexaryTreeDbRef; @@ -134,13 +138,14 @@ proc hexaDb*(ps: SnapDbBaseRef): HexaryTreeDbRef = ## Getter, low level access to underlying session DB ps.xDb -proc rockDb*(ps: SnapDbBaseRef): RocksStoreRef = - ## Getter, low level access to underlying persistent rock DB interface - ps.base.rocky +when dbBackend == rocksdb: + proc rockDb*(ps: SnapDbBaseRef): RocksStoreRef = + ## Getter, low level access to underlying persistent rock DB interface + ps.base.rocky -proc rockDb*(pv: SnapDbRef): RocksStoreRef = - ## Getter variant - pv.rocky + proc rockDb*(pv: SnapDbRef): RocksStoreRef = + ## Getter variant + pv.rocky proc kvDb*(ps: SnapDbBaseRef): CoreDbRef = ## Getter, low level access to underlying persistent key-value DB @@ -193,11 +198,13 @@ template toOpenArray*(k: ByteArray33): openArray[byte] = proc dbBackendRocksDb*(pv: SnapDbRef): bool = ## Returns `true` if rocksdb features are available - not pv.rocky.isNil + when dbBackend == rocksdb: + not pv.rocky.isNil proc dbBackendRocksDb*(ps: SnapDbBaseRef): bool = ## Returns `true` if rocksdb features are available - not ps.base.rocky.isNil + when dbBackend == rocksdb: + not ps.base.rocky.isNil proc mergeProofs*( xDb: HexaryTreeDbRef; ## Session database diff --git a/nimbus/sync/snap/worker/db/snapdb_storage_slots.nim b/nimbus/sync/snap/worker/db/snapdb_storage_slots.nim index 1af4bf04d..9edda6a3d 100644 --- a/nimbus/sync/snap/worker/db/snapdb_storage_slots.nim +++ b/nimbus/sync/snap/worker/db/snapdb_storage_slots.nim @@ -1,5 +1,5 @@ # nimbus-eth1 -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -21,6 +21,9 @@ import hexary_inspect, hexary_interpolate, hexary_paths, snapdb_desc, snapdb_persistent] +import + ../../../../db/select_backend + logScope: topics = "snap-db" @@ -60,13 +63,14 @@ proc persistentStorageSlots( ): Result[void,HexaryError] {.gcsafe, raises: [OSError,IOError,KeyError].} = ## Store accounts trie table on databse - if ps.rockDb.isNil: - let rc = db.persistentStorageSlotsPut(ps.kvDb) - if rc.isErr: return rc - else: - let rc = db.persistentStorageSlotsPut(ps.rockDb) - if rc.isErr: return rc - ok() + when dbBackend == rocksdb: + if ps.rockDb.isNil: + let rc = db.persistentStorageSlotsPut(ps.kvDb) + if rc.isErr: return rc + else: + let rc = db.persistentStorageSlotsPut(ps.rockDb) + if rc.isErr: return rc + ok() proc collectStorageSlots(