2023-08-07 17:45:23 +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.
|
|
|
|
|
|
|
|
## Non persistent constructors for Aristo DB
|
|
|
|
## =========================================
|
|
|
|
##
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
../aristo_desc,
|
2023-08-25 22:53:59 +00:00
|
|
|
../aristo_desc/desc_backend,
|
|
|
|
"."/[init_common, memory_db]
|
2023-08-07 17:45:23 +00:00
|
|
|
|
2023-08-10 20:01:28 +00:00
|
|
|
type
|
2023-08-11 17:23:57 +00:00
|
|
|
VoidBackendRef* = ref object of TypedBackendRef
|
2023-09-15 15:23:53 +00:00
|
|
|
## Dummy descriptor type, used as `nil` reference
|
|
|
|
|
|
|
|
MemOnlyBackend* = VoidBackendRef|MemBackendRef
|
2023-08-10 20:01:28 +00:00
|
|
|
|
2023-08-07 17:45:23 +00:00
|
|
|
export
|
2023-08-18 19:46:55 +00:00
|
|
|
BackendType,
|
2023-09-18 20:20:28 +00:00
|
|
|
MemBackendRef,
|
|
|
|
QidLayoutRef
|
2023-09-05 13:57:20 +00:00
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public helpers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc kind*(
|
|
|
|
be: BackendRef;
|
|
|
|
): BackendType =
|
|
|
|
## Retrieves the backend type symbol for a `be` backend database argument
|
|
|
|
## where `BackendVoid` is returned for the`nil` backend.
|
|
|
|
if be.isNil:
|
|
|
|
BackendVoid
|
|
|
|
else:
|
|
|
|
be.TypedBackendRef.beKind
|
|
|
|
|
2023-08-07 17:45:23 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public database constuctors, destructor
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2023-09-26 09:21:13 +00:00
|
|
|
proc init*(
|
|
|
|
T: type AristoDbRef; # Target type
|
|
|
|
B: type MemBackendRef; # Backend type
|
|
|
|
qidLayout: QidLayoutRef; # Optional fifo schedule
|
|
|
|
): T =
|
|
|
|
## Memory backend constructor.
|
|
|
|
##
|
|
|
|
## If the `qidLayout` argument is set `QidLayoutRef(nil)`, the a backend
|
|
|
|
## database will not provide filter history management. Providing a different
|
|
|
|
## scheduler layout shoud be used with care as table access with different
|
|
|
|
## layouts might render the filter history data unmanageable.
|
|
|
|
##
|
|
|
|
when B is MemBackendRef:
|
|
|
|
AristoDbRef(top: LayerRef(), backend: memoryBackend(qidLayout))
|
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
proc init*(
|
|
|
|
T: type AristoDbRef; # Target type
|
|
|
|
B: type MemOnlyBackend; # Backend type
|
|
|
|
): T =
|
|
|
|
## Memory backend constructor.
|
2023-09-05 13:57:20 +00:00
|
|
|
##
|
|
|
|
## If the `qidLayout` argument is set `QidLayoutRef(nil)`, the a backend
|
|
|
|
## database will not provide filter history management. Providing a different
|
|
|
|
## scheduler layout shoud be used with care as table access with different
|
|
|
|
## layouts might render the filter history data unmanageable.
|
|
|
|
##
|
2023-09-15 15:23:53 +00:00
|
|
|
when B is VoidBackendRef:
|
2023-08-18 19:46:55 +00:00
|
|
|
AristoDbRef(top: LayerRef())
|
2023-08-07 17:45:23 +00:00
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
elif B is MemBackendRef:
|
2023-09-26 09:21:13 +00:00
|
|
|
let qidLayout = DEFAULT_QID_QUEUES.to(QidLayoutRef)
|
2023-09-05 13:57:20 +00:00
|
|
|
AristoDbRef(top: LayerRef(), backend: memoryBackend(qidLayout))
|
2023-08-07 17:45:23 +00:00
|
|
|
|
2023-09-15 15:23:53 +00:00
|
|
|
proc init*(
|
|
|
|
T: type AristoDbRef; # Target type
|
|
|
|
): T =
|
|
|
|
## Shortcut for `AristoDbRef.init(VoidBackendRef)`
|
|
|
|
AristoDbRef.init VoidBackendRef
|
2023-08-07 17:45:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc finish*(db: AristoDbRef; flush = false) =
|
|
|
|
## Backend destructor. The argument `flush` indicates that a full database
|
2023-09-12 18:45:12 +00:00
|
|
|
## deletion is requested. If set `false` the outcome might differ depending
|
|
|
|
## on the type of backend (e.g. the `BackendMemory` backend will always
|
|
|
|
## flush on close.)
|
2023-08-07 17:45:23 +00:00
|
|
|
##
|
2023-08-17 13:42:01 +00:00
|
|
|
## In case of distributed descriptors accessing the same backend, all
|
|
|
|
## distributed descriptors will be destroyed.
|
|
|
|
##
|
2023-08-07 17:45:23 +00:00
|
|
|
## This distructor may be used on already *destructed* descriptors.
|
2023-08-17 13:42:01 +00:00
|
|
|
##
|
|
|
|
if not db.isNil:
|
|
|
|
if not db.backend.isNil:
|
|
|
|
db.backend.closeFn flush
|
|
|
|
|
2023-09-11 20:38:49 +00:00
|
|
|
let lebo = db.getCentre
|
|
|
|
discard lebo.forgetOthers()
|
|
|
|
lebo[] = AristoDbObj(top: LayerRef())
|
2023-08-07 17:45:23 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|