Allow dbBackend == none to compile (#1996)

* Allow dbBackend == none to compile

* Fix copyright year
This commit is contained in:
andri lim 2024-01-31 18:55:30 +07:00 committed by GitHub
parent c635e160d9
commit 09f95962ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 93 additions and 65 deletions

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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(