Skip to content

Commit

Permalink
fix layer vtop after rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Dec 20, 2024
1 parent 0971b72 commit b3917ea
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions nimbus/db/aristo/aristo_delta.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ proc deltaPersistent*(
db.stoLeaves.put(mixPath, vtx)

# Done with txRef, all saved to backend
db.txRef.layer.cTop = db.txRef.layer.vTop
db.txRef.layer.sTab.clear()
db.txRef.layer.kMap.clear()
db.txRef.layer.accLeaves.clear()
Expand Down
6 changes: 2 additions & 4 deletions nimbus/db/aristo/aristo_desc/desc_structural.nim
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type
accLeaves*: Table[Hash32, VertexRef] ## Account path -> VertexRef
stoLeaves*: Table[Hash32, VertexRef] ## Storage path -> VertexRef

cTop*: VertexID ## Last committed vertex ID

GetVtxFlag* = enum
PeekCache
## Peek into, but don't update cache - useful on work loads that are
Expand All @@ -148,10 +150,6 @@ func setUsed*(vtx: VertexRef, nibble: uint8, used: static bool): VertexID =
vtx.used and (not (1'u16 shl nibble))
vtx.bVid(nibble)

func init*(T: type LayerRef): T =
## Constructor, returns empty layer
T()

func hash*(node: NodeRef): Hash =
## Table/KeyedQueue/HashSet mixin
cast[pointer](node).hash
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_init/memory_only.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ proc init*(

let db =
when B is VoidBackendRef:
AristoDbRef(txRef: AristoTxRef(layer: LayerRef.init()))
AristoDbRef(txRef: AristoTxRef(layer: LayerRef()))

elif B is MemBackendRef:
AristoDbRef(txRef: AristoTxRef(layer: LayerRef.init()), backend: memoryBackend())
AristoDbRef(txRef: AristoTxRef(layer: LayerRef()), backend: memoryBackend())
db.txRef.db = db
db

Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_init/persistent.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ proc newAristoRdbDbRef(
return err(rc.error)
rc.value
db = (AristoDbRef(
txRef: AristoTxRef(layer: LayerRef(vTop: vTop)),
txRef: AristoTxRef(layer: LayerRef(vTop: vTop, cTop: vTop)),
backend: be,
accLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
stoLeaves: LruCache[Hash32, VertexRef].init(ACC_LRU_SIZE),
Expand Down
13 changes: 9 additions & 4 deletions nimbus/db/aristo/aristo_tx/tx_frame.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ proc txFrameBegin*(db: AristoDbRef, parent: AristoTxRef): Result[AristoTxRef,Ari

let
vTop = parent.layer.vTop
layer = LayerRef(
vTop: vTop)
layer = LayerRef(vTop: vTop, cTop: vTop)

ok AristoTxRef(
db: db,
Expand All @@ -58,7 +57,10 @@ proc rollback*(
## performed for this transactio. The previous transaction is returned if
## there was any.
# TODO Everyone using this txref should repoint their parent field
tx.layer = LayerRef()

let vTop = tx.layer[].cTop
tx.layer[] = Layer(vTop: vTop, cTop: vTop)

ok()


Expand All @@ -69,8 +71,11 @@ proc commit*(
##
# TODO Everyone using this txref should repoint their parent field
doAssert tx.parent != nil, "should not commit the base tx"
mergeAndReset(tx.parent.layer[], tx.layer[])

# A rollback after commit should reset to the new vTop!
tx.layer[].cTop = tx.layer[].vTop

mergeAndReset(tx.parent.layer[], tx.layer[])
ok()


Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/kvt/kvt_tx/tx_frame.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ proc rollback*(
## there was any.
##

tx.layer = LayerRef()
tx.layer[] = Layer()
ok()

proc commit*(
Expand Down

0 comments on commit b3917ea

Please sign in to comment.