mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-31 14:28:48 +00:00
5462c05dc6
* Fix copyright year * Show elapsed times with enabled `CoreDb` API tracking * Show elapsed times with enabled `LedgerRef` API tracking * Reorg `CoreDb` auto destructors for `Aristo` DB why: While `Aristo` supports some parallelism for concurrent database access, this comes with a price of management overhead. With a naive approach, the auto-destructor will slow down execution because the ledger and evm treat the database in a shared mode where a DB descriptor is just created and thrown away shortly after. This is reflected in the `Coredb` abstraction layer above `Aristo`/`Kvt` where a few `Shared` type descriptors are cached and a shared reference is returned rather than a disposable new object. * For `CoreDb` support transaction level tracking details: This is mainly an extra for the legacy DB as `Aristo` and `Kvt` support this already. Also return an error on the legacy DB backend when `persistent()` is called while there are transactions pending (the `persistent()` call does nothing otherwise on the legacy backend.) * Clear compiler warnings (remove unused variables etc.)
55 lines
1.7 KiB
Nim
55 lines
1.7 KiB
Nim
# nimbus-eth1
|
|
# Copyright (c) 2023 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.
|
|
|
|
## Rocks DB store data iterator
|
|
## ============================
|
|
##
|
|
{.push raises: [].}
|
|
|
|
import
|
|
std/sequtils,
|
|
eth/common,
|
|
rocksdb,
|
|
./rdb_desc
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public iterators
|
|
# ------------------------------------------------------------------------------
|
|
|
|
iterator walk*(rdb: RdbInst): tuple[key: Blob, data: Blob] =
|
|
## Walk over all key-value pairs of the database.
|
|
##
|
|
let rit = rdb.store.db.rocksdb_create_iterator(rdb.store.readOptions)
|
|
defer: rit.rocksdb_iter_destroy()
|
|
|
|
rit.rocksdb_iter_seek_to_first()
|
|
while rit.rocksdb_iter_valid() != 0:
|
|
var kLen: csize_t
|
|
let kData = rit.rocksdb_iter_key(addr kLen)
|
|
|
|
if not kData.isNil and 0 < kLen:
|
|
var vLen: csize_t
|
|
let vData = rit.rocksdb_iter_value(addr vLen)
|
|
|
|
if not vData.isNil and 0 < vLen:
|
|
let
|
|
key = kData.toOpenArrayByte(0,int(kLen)-1).toSeq
|
|
data = vData.toOpenArrayByte(0,int(vLen)-1).toSeq
|
|
yield (key,data)
|
|
|
|
# Update Iterator (might overwrite kData/vdata)
|
|
rit.rocksdb_iter_next()
|
|
|
|
# End while
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|