2023-06-20 13:26:25 +00:00
|
|
|
# nimbus-eth1
|
2024-03-05 04:54:42 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-06-20 13:26:25 +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.
|
|
|
|
|
|
|
|
## Rocks DB store data iterator
|
|
|
|
## ============================
|
|
|
|
##
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
eth/common,
|
2023-09-13 02:32:38 +00:00
|
|
|
stew/endians2,
|
2023-06-20 13:26:25 +00:00
|
|
|
rocksdb,
|
2024-07-02 18:25:06 +00:00
|
|
|
./rdb_desc,
|
|
|
|
../../aristo_blobify,
|
|
|
|
../../aristo_desc/desc_identifiers
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-04-16 20:39:11 +00:00
|
|
|
const
|
|
|
|
extraTraceMessages = false
|
|
|
|
## Enable additional logging noise
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-04-16 20:39:11 +00:00
|
|
|
when extraTraceMessages:
|
|
|
|
import
|
|
|
|
chronicles
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-04-16 20:39:11 +00:00
|
|
|
logScope:
|
|
|
|
topics = "aristo-rocksdb"
|
2023-06-20 13:26:25 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public iterators
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-06-10 12:04:22 +00:00
|
|
|
iterator walkAdm*(rdb: RdbInst): tuple[xid: uint64, data: Blob] =
|
|
|
|
## Walk over key-value pairs of the admin column of the database.
|
|
|
|
##
|
|
|
|
## Non-decodable entries are are ignored.
|
2023-06-20 13:26:25 +00:00
|
|
|
##
|
2024-04-16 20:39:11 +00:00
|
|
|
block walkBody:
|
2024-06-10 12:04:22 +00:00
|
|
|
let rit = rdb.admCol.openIterator().valueOr:
|
2024-04-16 20:39:11 +00:00
|
|
|
when extraTraceMessages:
|
2024-06-10 12:04:22 +00:00
|
|
|
trace logTxt "walkAdm()", error
|
2024-04-16 20:39:11 +00:00
|
|
|
break walkBody
|
|
|
|
defer: rit.close()
|
2024-03-05 04:54:42 +00:00
|
|
|
|
2024-04-16 20:39:11 +00:00
|
|
|
for (key,val) in rit.pairs:
|
2024-06-10 12:04:22 +00:00
|
|
|
if key.len == 8 and val.len != 0:
|
|
|
|
yield (uint64.fromBytesBE key, val)
|
2023-08-22 18:44:54 +00:00
|
|
|
|
2024-07-04 13:46:52 +00:00
|
|
|
iterator walkKey*(rdb: RdbInst): tuple[rvid: RootedVertexID, data: Blob] =
|
2024-06-10 12:04:22 +00:00
|
|
|
## Walk over key-value pairs of the hash key column of the database.
|
2023-06-20 13:26:25 +00:00
|
|
|
##
|
2024-06-10 12:04:22 +00:00
|
|
|
## Non-decodable entries are are ignored.
|
2023-08-22 18:44:54 +00:00
|
|
|
##
|
2023-06-20 13:26:25 +00:00
|
|
|
block walkBody:
|
2024-06-10 12:04:22 +00:00
|
|
|
let rit = rdb.keyCol.openIterator().valueOr:
|
2024-04-16 20:39:11 +00:00
|
|
|
when extraTraceMessages:
|
2024-06-10 12:04:22 +00:00
|
|
|
trace logTxt "walkKey()", error
|
2023-06-20 13:26:25 +00:00
|
|
|
break walkBody
|
2024-04-16 20:39:11 +00:00
|
|
|
defer: rit.close()
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-06-10 12:04:22 +00:00
|
|
|
for (key,val) in rit.pairs:
|
2024-07-04 13:46:52 +00:00
|
|
|
if val.len != 0:
|
|
|
|
let rvid = key.deblobify(RootedVertexID).valueOr:
|
|
|
|
continue
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-07-04 13:46:52 +00:00
|
|
|
yield (rvid, val)
|
|
|
|
|
|
|
|
|
|
|
|
iterator walkVtx*(rdb: RdbInst): tuple[rvid: RootedVertexID, data: Blob] =
|
2024-06-10 12:04:22 +00:00
|
|
|
## Walk over key-value pairs of the hash key column of the database.
|
|
|
|
##
|
|
|
|
## Non-decodable entries are are ignored.
|
|
|
|
##
|
|
|
|
block walkBody:
|
|
|
|
let rit = rdb.vtxCol.openIterator().valueOr:
|
|
|
|
when extraTraceMessages:
|
|
|
|
trace logTxt "walkVtx()", error
|
|
|
|
break walkBody
|
|
|
|
defer: rit.close()
|
2023-06-20 13:26:25 +00:00
|
|
|
|
2024-06-10 12:04:22 +00:00
|
|
|
for (key,val) in rit.pairs:
|
2024-07-04 13:46:52 +00:00
|
|
|
if val.len != 0:
|
|
|
|
let rvid = key.deblobify(RootedVertexID).valueOr:
|
|
|
|
continue
|
|
|
|
|
|
|
|
yield (rvid, val)
|
2023-06-20 13:26:25 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|