Skip to content

Commit 42bb640

Browse files
authored
Simplify shared rocksdb instance / write batch handling (#3063)
By introducing the "shared rocksdb instance" concept to the backend, we can remove the "piggybacking" mode , thus reducing the complexity of database initialisation and opening the possibility of extending how write batching works across kvt/aristo. The change makes explicit the hidden shared state that was previously hiding in closures and provides the first step towards simplifying the "commit/persist" interface of coredb, preparing it for optimizations to reduce the "layering tax" that `forked-layers` introduced.
1 parent bd65a01 commit 42bb640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+451
-1183
lines changed

execution_chain/core/chain/forked_chain.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ proc forkChoice*(c: ForkedChainRef,
567567

568568
# Save and record the block number before the last saved block state.
569569
if newBaseNumber > 0:
570-
c.com.db.persistent(newBaseNumber).isOkOr:
570+
c.com.db.persist(newBaseNumber).isOkOr:
571571
return err("Failed to save state: " & $$error)
572572

573573
ok()

execution_chain/core/chain/forked_chain/chain_kvt.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import
2424
../../../db/core_db,
2525
./chain_desc
2626

27-
proc fcKvtPersistent*(c: ForkedChainRef) =
27+
proc fcKvtPersist*(c: ForkedChainRef) =
2828
## Save cached `kvt` data if possible. This function has the side effect
2929
## that it saves all cached db data including `Aristo` data (although there
3030
## should not be any.)
3131
##
3232
let db = c.com.db
33-
db.persistent(c.baseTxFrame.getSavedStateBlockNumber()).isOkOr:
34-
raiseAssert "fcKvtPersistent: persistent() failed: " & $$error
33+
db.persist(c.baseTxFrame.getSavedStateBlockNumber()).isOkOr:
34+
raiseAssert "fcKvtPersist: persistent() failed: " & $$error
3535

3636
proc fcKvtHasKey*(c: ForkedChainRef, key: openArray[byte]): bool =
3737
## Check whether the argument `key` exists on the `kvt` table (i.e. `get()`

execution_chain/core/chain/persist_blocks.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ proc checkpoint*(p: var Persister): Result[void, string] =
101101
)
102102

103103
# Save and record the block number before the last saved block state.
104-
p.c.db.persistent(p.parent.number).isOkOr:
104+
p.c.db.persist(p.parent.number).isOkOr:
105105
return err("Failed to save state: " & $$error)
106106

107107
ok()

execution_chain/db/aristo/aristo_api.nim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import
1919
./aristo_desc/desc_backend,
2020
./aristo_init/memory_db,
2121
"."/[aristo_delete, aristo_desc, aristo_fetch, aristo_init, aristo_merge,
22-
aristo_part, aristo_path, aristo_profile, aristo_tx]
22+
aristo_part, aristo_path, aristo_persist, aristo_profile, aristo_tx_frame]
2323

2424
export
2525
AristoDbProfListRef
@@ -246,10 +246,11 @@ type
246246
## `seq[byte]`, i.e. `PathID` type paths with an even number of nibbles.
247247

248248
AristoApiPersistFn* =
249-
proc(db: AristoDbRef;
249+
proc(
250+
db: AristoDbRef;
251+
batch: PutHdlRef;
250252
nxtSid = 0u64;
251-
): Result[void,AristoError]
252-
{.noRaise.}
253+
) {.noRaise.}
253254
## Persistently store data onto backend database. If the system is
254255
## running without a database backend, the function returns immediately
255256
## with an error. The same happens if there is a pending transaction.
@@ -393,7 +394,7 @@ proc dup(be: BackendRef): BackendRef =
393394
of BackendMemory:
394395
return MemBackendRef(be).dup
395396

396-
of BackendRocksDB, BackendRdbHosting:
397+
of BackendRocksDB:
397398
when AristoPersistentBackendOk:
398399
return RdbBackendRef(be).dup
399400

execution_chain/db/aristo/aristo_check.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ proc checkBE*(
6969
case db.backend.kind:
7070
of BackendMemory:
7171
return MemBackendRef.checkBE db
72-
of BackendRocksDB, BackendRdbHosting:
72+
of BackendRocksDB:
7373
return RdbBackendRef.checkBE db
7474
of BackendVoid:
7575
return VoidBackendRef.checkBE db

execution_chain/db/aristo/aristo_debug.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ proc pp*(
683683
case be.kind:
684684
of BackendMemory:
685685
result &= be.MemBackendRef.ppBe(db, limit, indent+1)
686-
of BackendRocksDB, BackendRdbHosting:
686+
of BackendRocksDB:
687687
result &= be.RdbBackendRef.ppBe(db, limit, indent+1)
688688
of BackendVoid:
689689
result &= "<NoBackend>"

execution_chain/db/aristo/aristo_delta.nim

Lines changed: 0 additions & 96 deletions
This file was deleted.

execution_chain/db/aristo/aristo_desc.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import
3131

3232

3333
from ./aristo_desc/desc_backend
34-
import BackendRef
34+
import BackendRef, PutHdlRef
3535

3636
# Not auto-exporting backend
3737
export
3838
tables, aristo_constants, desc_error, desc_identifiers, desc_nibbles,
39-
desc_structural, minilru, hashes
39+
desc_structural, minilru, hashes, PutHdlRef
4040

4141
type
4242
AristoTxRef* = ref object

execution_chain/db/aristo/aristo_desc/desc_backend.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# nimbus-eth1
2-
# Copyright (c) 2023-2024 Status Research & Development GmbH
2+
# Copyright (c) 2023-2025 Status Research & Development GmbH
33
# Licensed under either of
44
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
55
# http://www.apache.org/licenses/LICENSE-2.0)

execution_chain/db/aristo/aristo_desc/desc_error.nim

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ type
8686

8787

8888
# Functions from `aristo_delta.nim`
89-
FilBackendMissing
9089
FilBackendRoMode
9190
FilSiblingsCommitUnfinshed
9291

@@ -227,8 +226,4 @@ type
227226
RdbHashKeyExpected
228227

229228

230-
# Transaction wrappers
231-
TxBackendNotWritable
232-
TxStackGarbled
233-
234229
# End

0 commit comments

Comments
 (0)