mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-16 15:25:24 +00:00
5a5cc6295e
* bump rockdb * Rename `KVT` objects related to filters according to `Aristo` naming details: filter* => delta* roFilter => balancer * Compulsory error handling if `persistent()` fails * Add return code to `reCentre()` why: Might eventually fail if re-centring is blocked. Some logic will be added in subsequent patch sets. * Add column families from earlier session to rocksdb in opening procedure why: All previously used CFs must be declared when re-opening an existing database. * Update `init()` and add rocksdb `reinit()` methods for changing parameters why: Opening a set column families (with different open options) must span at least the ones that are already on disk. * Provide write-trigger-event interface into `Aristo` backend why: This allows to save data from a guest application (think `KVT`) to get synced with the write cycle so the guest and `Aristo` save all atomically. * Use `KVT` with new column family interface from `Aristo` * Remove obsolete guest interface * Implement `KVT` piggyback on `Aristo` backend * CoreDb: Add separate `KVT`/`Aristo` backend mode for debugging * Remove `rocks_db` import from `persist()` function why: Some systems (i.p `fluffy` and friends) use the `Aristo` memory backend emulation and do not link against rocksdb when building the application. So this should fix that problem.
91 lines
3.2 KiB
Nim
91 lines
3.2 KiB
Nim
# nimbus-eth1
|
|
# 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)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
# http://opensource.org/licenses/MIT)
|
|
# at your option. This file may not be copied, modified, or distributed
|
|
# except according to those terms.
|
|
|
|
## Persistent constructor for Kvt DB
|
|
## ====================================
|
|
##
|
|
## This module automatically pulls in the persistent backend library at the
|
|
## linking stage (e.g. `rocksdb`) which can be avoided for pure memory DB
|
|
## applications by importing `./kvt_init/memory_only` (rather than
|
|
## `./kvt_init/persistent`.)
|
|
##
|
|
{.push raises: [].}
|
|
|
|
import
|
|
results,
|
|
../../aristo,
|
|
../../opts,
|
|
../kvt_desc,
|
|
"."/[rocks_db, memory_only]
|
|
|
|
export
|
|
RdbBackendRef,
|
|
memory_only
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Private helpers
|
|
# ------------------------------------------------------------------------------
|
|
|
|
func toErr0(err: (KvtError,string)): KvtError =
|
|
err[0]
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public database constuctors, destructor
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc init*(
|
|
T: type KvtDbRef;
|
|
B: type RdbBackendRef;
|
|
basePath: string;
|
|
opts: DbOptions;
|
|
): Result[KvtDbRef,KvtError] =
|
|
## Generic constructor for `RocksDb` backend
|
|
##
|
|
ok KvtDbRef(
|
|
top: LayerRef.init(),
|
|
backend: ? rocksDbKvtBackend(basePath, opts).mapErr toErr0)
|
|
|
|
proc init*(
|
|
T: type KvtDbRef;
|
|
B: type RdbBackendRef;
|
|
adb: AristoDbRef;
|
|
opts: DbOptions;
|
|
): Result[KvtDbRef,KvtError] =
|
|
## Constructor for `RocksDb` backend which piggybacks on the `Aristo`
|
|
## backend. The following changes will occur after successful instantiation:
|
|
##
|
|
## * When invoked, the function `kvt_tx.persistent()` will always return an
|
|
## error. If everything is all right (e.g. saving is possible), the error
|
|
## returned will be `TxPersistDelayed`. This indicates that the save
|
|
## request was queued, waiting for being picked up by an event handler.
|
|
##
|
|
## * There should be an invocation of `aristo_tx.persistent()` immediately
|
|
## follwing the `kvt_tx.persistent()` call (some `KVT` functions might
|
|
## return `RdbBeDelayedLocked` or similar errors while the save request
|
|
## is pending.) Once successful, the`aristo_tx.persistent()` function will
|
|
## also have commited the pending save request mentioned above.
|
|
##
|
|
## * The function `kvt_init/memory_only.finish()` does nothing.
|
|
##
|
|
## * The function `aristo_init/memory_only.finish()` will close both
|
|
## sessions, the one for `KVT` and the other for `Aristo`.
|
|
##
|
|
## * The functiond `kvt_delta.deltaUpdate()` and `tx_stow.tcStow()` should
|
|
## not be invoked directly (they will stop with an error most of the time,
|
|
## anyway.)
|
|
##
|
|
ok KvtDbRef(
|
|
top: LayerRef.init(),
|
|
backend: ? rocksDbKvtTriggeredBackend(adb, opts).mapErr toErr0)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|