2023-06-20 13:26:25 +00:00
|
|
|
# nimbus-eth1
|
|
|
|
# Copyright (c) 2021 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.
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
2023-06-30 22:22:33 +00:00
|
|
|
../aristo_desc,
|
2023-06-20 13:26:25 +00:00
|
|
|
../aristo_desc/aristo_types_backend
|
|
|
|
|
|
|
|
const
|
|
|
|
verifyIxId = true # and false
|
|
|
|
## Enforce session tracking
|
|
|
|
|
|
|
|
type
|
2023-08-18 19:46:55 +00:00
|
|
|
BackendType* = enum
|
2023-08-11 17:23:57 +00:00
|
|
|
BackendVoid ## For providing backend-less constructor
|
2023-06-20 13:26:25 +00:00
|
|
|
BackendMemory
|
|
|
|
BackendRocksDB
|
|
|
|
|
2023-08-18 19:46:55 +00:00
|
|
|
StorageType* = enum
|
|
|
|
## Storage types, key prefix
|
|
|
|
Oops = 0
|
|
|
|
IdgPfx = 1 ## ID generator
|
|
|
|
VtxPfx = 2 ## Vertex data
|
|
|
|
KeyPfx = 3 ## Key/hash data
|
|
|
|
|
|
|
|
TypedBackendRef* = ref object of BackendRef
|
|
|
|
kind*: BackendType ## Backend type identifier
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
txGen: uint ## Transaction ID generator (for debugging)
|
|
|
|
txId: uint ## Active transaction ID (for debugging)
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
TypedPutHdlErrRef* = ref object of RootRef
|
2023-08-18 19:46:55 +00:00
|
|
|
case pfx*: StorageType ## Error sub-table
|
|
|
|
of VtxPfx, KeyPfx:
|
|
|
|
vid*: VertexID ## Vertex ID where the error occured
|
|
|
|
of IdgPfx, Oops:
|
|
|
|
discard
|
2023-06-30 22:22:33 +00:00
|
|
|
code*: AristoError ## Error code (if any)
|
|
|
|
|
2023-06-20 13:26:25 +00:00
|
|
|
TypedPutHdlRef* = ref object of PutHdlRef
|
2023-06-30 22:22:33 +00:00
|
|
|
error*: TypedPutHdlErrRef ## Track error while collecting transaction
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
txId: uint ## Transaction ID (for debugging)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc beginSession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == 0
|
|
|
|
if db.txGen == 0:
|
|
|
|
db.txGen = 1
|
|
|
|
db.txId = db.txGen
|
|
|
|
hdl.txId = db.txGen
|
|
|
|
db.txGen.inc
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc verifySession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == hdl.txId
|
|
|
|
|
2023-06-30 22:22:33 +00:00
|
|
|
proc finishSession*(hdl: TypedPutHdlRef; db: TypedBackendRef) =
|
2023-06-20 13:26:25 +00:00
|
|
|
when verifyIxId:
|
|
|
|
doAssert db.txId == hdl.txId
|
|
|
|
db.txId = 0
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|