Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aristo cull journal related stuff #2288

Merged
merged 9 commits into from
Jun 3, 2024
Prev Previous commit
Next Next commit
Moved vGen[] field from LayerFinalRef to LayerDeltaRef
why:
  Then a separate `FilterRef` type is not needed, anymore
  • Loading branch information
mjfh committed Jun 3, 2024
commit 0e1c09206dae6ce028c5b8d4edf1c2679a41083d
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_debug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ proc ppLayer(
result &= "<layer>".doPrefix(false)
if vGenOk:
let
tLen = layer.final.vGen.len
tLen = layer.delta.vGen.len
info = "vGen(" & $tLen & ")"
result &= info.doPrefix(0 < tLen) & layer.final.vGen.ppVidList
result &= info.doPrefix(0 < tLen) & layer.delta.vGen.ppVidList
if sTabOk:
let
tLen = layer.delta.sTab.len
Expand Down
2 changes: 1 addition & 1 deletion nimbus/db/aristo/aristo_delta.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ proc deltaFwd*(
src: srcRoot,
sTab: layer.delta.sTab,
kMap: layer.delta.kMap,
vGen: layer.final.vGen.vidReorg) # Compact recycled IDs
vGen: layer.delta.vGen.vidReorg) # Compact recycled IDs

# ------------------------------------------------------------------------------
# Public functions, apply/install filters
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ proc fork*(
if not noTopLayer:
clone.top = LayerRef.init()
if not db.roFilter.isNil:
clone.top.final.vGen = db.roFilter.vGen
clone.top.delta.vGen = db.roFilter.vGen
else:
let rc = clone.backend.getIdgFn()
if rc.isOk:
clone.top.final.vGen = rc.value
clone.top.delta.vGen = rc.value
elif rc.error != GetIdgNotFound:
return err(rc.error)

Expand Down
3 changes: 1 addition & 2 deletions nimbus/db/aristo/aristo_desc/desc_structural.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type
##
sTab*: Table[VertexID,VertexRef] ## Structural vertex table
kMap*: Table[VertexID,HashKey] ## Merkle hash key mapping
vGen*: seq[VertexID] ## Recycling state for vertex IDs

LayerFinalRef* = ref object
## Final tables fully supersede tables on lower layers when stacked as a
Expand All @@ -121,7 +122,6 @@ type
##
pPrf*: HashSet[VertexID] ## Locked vertices (proof nodes)
fRpp*: Table[HashKey,VertexID] ## Key lookup for `pPrf[]` (proof nodes)
vGen*: seq[VertexID] ## Recycling state for vertex IDs
dirty*: HashSet[VertexID] ## Start nodes to re-hashiy from

LayerRef* = ref LayerObj
Expand Down Expand Up @@ -280,7 +280,6 @@ func dup*(final: LayerFinalRef): LayerFinalRef =
LayerFinalRef(
pPrf: final.pPrf,
fRpp: final.fRpp,
vGen: final.vGen,
dirty: final.dirty)

func dup*(wp: VidVtxPair): VidVtxPair =
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_init/persistent.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ proc newAristoRdbDbRef(
rc.value
ok AristoDbRef(
top: LayerRef(
delta: LayerDeltaRef(),
final: LayerFinalRef(vGen: vGen)),
delta: LayerDeltaRef(vGen: vGen),
final: LayerFinalRef()),
backend: be)

# ------------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions nimbus/db/aristo/aristo_layers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func pPrf*(db: AristoDbRef): lent HashSet[VertexID] =
db.top.final.pPrf

func vGen*(db: AristoDbRef): lent seq[VertexID] =
db.top.final.vGen
db.top.delta.vGen

# ------------------------------------------------------------------------------
# Public getters/helpers
Expand Down Expand Up @@ -190,6 +190,7 @@ func layersMergeOnto*(src: LayerRef; trg: var LayerObj) =
trg.delta.sTab[vid] = vtx
for (vid,key) in src.delta.kMap.pairs:
trg.delta.kMap[vid] = key
trg.delta.vGen = src.delta.vGen


func layersCc*(db: AristoDbRef; level = high(int)): LayerRef =
Expand All @@ -205,7 +206,8 @@ func layersCc*(db: AristoDbRef; level = high(int)): LayerRef =
final: layers[^1].final.dup, # Pre-merged/final values
delta: LayerDeltaRef(
sTab: layers[0].delta.sTab.dup, # explicit dup for ref values
kMap: layers[0].delta.kMap))
kMap: layers[0].delta.kMap,
vGen: layers[^1].delta.vGen))

# Consecutively merge other layers on top
for n in 1 ..< layers.len:
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/aristo/aristo_tx/tx_fork.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ proc txFork*(
let rc = db.getIdgBE()
if rc.isOk:
LayerRef(
delta: LayerDeltaRef(),
final: LayerFinalRef(vGen: rc.value))
delta: LayerDeltaRef(vGen: rc.value),
final: LayerFinalRef())
elif rc.error == GetIdgNotFound:
LayerRef.init()
else:
Expand Down
3 changes: 2 additions & 1 deletion nimbus/db/aristo/aristo_tx/tx_frame.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ proc txFrameBegin*(db: AristoDbRef): Result[AristoTxRef,AristoError] =
if db.txFrameLevel != db.stack.len:
return err(TxStackGarbled)

let vGen = db.top.delta.vGen
db.stack.add db.top
db.top = LayerRef(
delta: LayerDeltaRef(),
delta: LayerDeltaRef(vGen: vGen),
final: db.top.final.dup,
txUid: db.getTxUid)

Expand Down
10 changes: 5 additions & 5 deletions nimbus/db/aristo/aristo_tx/tx_stow.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ proc txStow*(
delta: LayerDeltaRef(),
final: final)
if db.roFilter.isValid:
db.top.final.vGen = db.roFilter.vGen
db.top.delta.vGen = db.roFilter.vGen
else:
let rc = db.getIdgUbe()
if rc.isOk:
db.top.final.vGen = rc.value
db.top.delta.vGen = rc.value
else:
# It is OK if there was no `Idg`. Otherwise something serious happened
# and there is no way to recover easily.
Expand All @@ -79,12 +79,12 @@ proc txStow*(

# Special treatment for `snap` proofs (aka `chunkedMpt`)
let final =
if chunkedMpt: LayerFinalRef(vGen: db.vGen, fRpp: db.top.final.fRpp)
else: LayerFinalRef(vGen: db.vGen)
if chunkedMpt: LayerFinalRef(fRpp: db.top.final.fRpp)
else: LayerFinalRef()

# New empty top layer (probably with `snap` proofs carry over)
db.top = LayerRef(
delta: LayerDeltaRef(),
delta: LayerDeltaRef(vGen: db.vGen),
final: final,
txUid: db.top.txUid)
ok()
Expand Down
14 changes: 7 additions & 7 deletions nimbus/db/aristo/aristo_vid.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ proc vidFetch*(db: AristoDbRef; pristine = false): VertexID =
##
if db.vGen.len == 0:
# Note that `VertexID(1)` is the root of the main trie
db.top.final.vGen = @[VertexID(LEAST_FREE_VID+1)]
db.top.delta.vGen = @[VertexID(LEAST_FREE_VID+1)]
result = VertexID(LEAST_FREE_VID)
elif db.vGen.len == 1 or pristine:
result = db.vGen[^1]
db.top.final.vGen[^1] = result + 1
db.top.delta.vGen[^1] = result + 1
else:
result = db.vGen[^2]
db.top.final.vGen[^2] = db.top.final.vGen[^1]
db.top.final.vGen.setLen(db.vGen.len-1)
db.top.delta.vGen[^2] = db.top.delta.vGen[^1]
db.top.delta.vGen.setLen(db.vGen.len-1)
doAssert LEAST_FREE_VID <= result.distinctBase


Expand All @@ -64,14 +64,14 @@ proc vidDispose*(db: AristoDbRef; vid: VertexID) =
##
if LEAST_FREE_VID <= vid.distinctBase:
if db.vGen.len == 0:
db.top.final.vGen = @[vid]
db.top.delta.vGen = @[vid]
else:
let topID = db.vGen[^1]
# Only store smaller numbers: all numberts larger than `topID`
# are free numbers
if vid < topID:
db.top.final.vGen[^1] = vid
db.top.final.vGen.add topID
db.top.delta.vGen[^1] = vid
db.top.delta.vGen.add topID


proc vidReorg*(vGen: seq[VertexID]): seq[VertexID] =
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aristo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ when isMainModule:
noisy.accountsRunner(sam, resetDb=true)

when true: # and false:
let persistent = false or true
let persistent = false # or true
noisy.showElapsed("@snap_test_list"):
for n,sam in snapTestList:
noisy.accountsRunner(sam, persistent=persistent)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_aristo/test_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ proc testVidRecycleLists*(noisy = true; seed = 42): bool =
db1 = AristoDbRef.init()
rc = dbBlob.deblobify seq[VertexID]
xCheckRc rc.error == 0
db1.top.final.vGen = rc.value
db1.top.delta.vGen = rc.value

xCheck db.vGen == db1.vGen

Expand All @@ -127,7 +127,7 @@ proc testVidRecycleLists*(noisy = true; seed = 42): bool =
xCheck db.vGen.len == 1

# Repeat last test after clearing the cache
db.top.final.vGen.setLen(0)
db.top.delta.vGen.setLen(0)
for n in 0 .. 5:
let w = db.vidFetch()
xCheck w == VertexID(LEAST_FREE_VID) + n # VertexID(1) is default root ID
Expand Down