2023-09-12 18:44:45 +00:00
|
|
|
# nimbus-eth1
|
2024-02-29 21:10:24 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-09-12 18:44:45 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
## Kvt DB -- backend data types
|
|
|
|
## ============================
|
|
|
|
##
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
eth/common,
|
|
|
|
results,
|
|
|
|
./desc_error
|
|
|
|
|
|
|
|
type
|
|
|
|
GetKvpFn* =
|
2023-09-15 15:23:53 +00:00
|
|
|
proc(key: openArray[byte]): Result[Blob,KvtError] {.gcsafe, raises: [].}
|
2023-09-12 18:44:45 +00:00
|
|
|
## Generic backend database retrieval function
|
2024-06-21 07:44:10 +00:00
|
|
|
LenKvpFn* =
|
|
|
|
proc(key: openArray[byte]): Result[int,KvtError] {.gcsafe, raises: [].}
|
|
|
|
## Generic backend database retrieval function
|
2023-09-12 18:44:45 +00:00
|
|
|
|
|
|
|
# -------------
|
|
|
|
|
|
|
|
PutHdlRef* = ref object of RootRef
|
|
|
|
## Persistent database transaction frame handle. This handle is used to
|
|
|
|
## wrap any of `PutVtxFn`, `PutKeyFn`, and `PutIdgFn` into and atomic
|
|
|
|
## transaction frame. These transaction frames must not be interleaved
|
|
|
|
## by any library function using the backend.
|
|
|
|
|
|
|
|
PutBegFn* =
|
2024-06-13 18:15:11 +00:00
|
|
|
proc(): Result[PutHdlRef,KvtError] {.gcsafe, raises: [].}
|
2023-09-12 18:44:45 +00:00
|
|
|
## Generic transaction initialisation function
|
|
|
|
|
|
|
|
PutKvpFn* =
|
|
|
|
proc(hdl: PutHdlRef; kvps: openArray[(Blob,Blob)]) {.gcsafe, raises: [].}
|
|
|
|
## Generic backend database bulk storage function.
|
|
|
|
|
|
|
|
PutEndFn* =
|
|
|
|
proc(hdl: PutHdlRef): Result[void,KvtError] {.gcsafe, raises: [].}
|
|
|
|
## Generic transaction termination function
|
|
|
|
|
|
|
|
# -------------
|
|
|
|
|
|
|
|
CloseFn* =
|
2024-06-14 11:19:48 +00:00
|
|
|
proc(eradicate: bool) {.gcsafe, raises: [].}
|
|
|
|
## Generic destructor for the `Kvt DB` backend. The argument `eradicate`
|
2023-09-12 18:44:45 +00:00
|
|
|
## indicates that a full database deletion is requested. If passed
|
|
|
|
## `false` the outcome might differ depending on the type of backend
|
2024-06-14 11:19:48 +00:00
|
|
|
## (e.g. in-memory backends would eradicate on close.)
|
2023-09-12 18:44:45 +00:00
|
|
|
|
2024-06-13 18:15:11 +00:00
|
|
|
CanModFn* =
|
|
|
|
proc(): Result[void,KvtError] {.gcsafe, raises: [].}
|
|
|
|
## This function returns OK if there is nothing to prevent the main
|
|
|
|
## `KVT` descriptors being modified (e.g. by `reCentre()`) or by
|
|
|
|
## adding/removing a new peer (e.g. by `fork()` or `forget()`.)
|
|
|
|
|
|
|
|
SetWrReqFn* =
|
|
|
|
proc(db: RootRef): Result[void,KvtError] {.gcsafe, raises: [].}
|
|
|
|
## This function stores a request function for the piggiback mode
|
|
|
|
## writing to the `Aristo` set of column families.
|
|
|
|
##
|
2024-06-14 11:19:48 +00:00
|
|
|
## If used at all, this function would run thee function closure
|
|
|
|
## `rocks_db.setWrReqTriggeredFn()()` with a `KvtDbRef` type argument
|
|
|
|
## for `db`. This allows to run the `Kvt` without linking to the
|
|
|
|
## rocksdb interface unless it is really needed.
|
2024-06-13 18:15:11 +00:00
|
|
|
|
2023-09-12 18:44:45 +00:00
|
|
|
# -------------
|
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
BackendRef* = ref BackendObj
|
|
|
|
BackendObj* = object of RootObj
|
2023-09-12 18:44:45 +00:00
|
|
|
## Backend interface.
|
|
|
|
|
|
|
|
getKvpFn*: GetKvpFn ## Read key-value pair
|
2024-06-21 07:44:10 +00:00
|
|
|
lenKvpFn*: LenKvpFn ## Read key-value pair length
|
2023-09-12 18:44:45 +00:00
|
|
|
|
|
|
|
putBegFn*: PutBegFn ## Start bulk store session
|
|
|
|
putKvpFn*: PutKvpFn ## Bulk store key-value pairs
|
|
|
|
putEndFn*: PutEndFn ## Commit bulk store session
|
|
|
|
|
|
|
|
closeFn*: CloseFn ## Generic destructor
|
2024-06-13 18:15:11 +00:00
|
|
|
canModFn*: CanModFn ## Lock-alike
|
|
|
|
|
|
|
|
setWrReqFn*: SetWrReqFn ## Register main descr for write request
|
2023-09-12 18:44:45 +00:00
|
|
|
|
2024-03-14 22:17:43 +00:00
|
|
|
proc init*(trg: var BackendObj; src: BackendObj) =
|
|
|
|
trg.getKvpFn = src.getKvpFn
|
2024-06-21 07:44:10 +00:00
|
|
|
trg.lenKvpFn = src.lenKvpFn
|
2024-03-14 22:17:43 +00:00
|
|
|
trg.putBegFn = src.putBegFn
|
|
|
|
trg.putKvpFn = src.putKvpFn
|
|
|
|
trg.putEndFn = src.putEndFn
|
|
|
|
trg.closeFn = src.closeFn
|
2024-06-13 18:15:11 +00:00
|
|
|
trg.canModFn = src.canModFn
|
2024-06-14 11:19:48 +00:00
|
|
|
trg.setWrReqFn = src.setWrReqFn
|
2024-02-29 21:10:24 +00:00
|
|
|
|
2023-09-12 18:44:45 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|