Skip to content

Commit

Permalink
fix: diff to base without nbl count check
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Jan 7, 2025
1 parent 7497d2d commit 56f7000
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ func (nf *nodebufferlist) recoverNodeBufferList(freezer *rawdb.ResettableFreezer
log.Info("Measure data", "nf.size", nf.size, "nf.layers", nf.layers, "nf.count", nf.count,
"rsevMdNum", nf.rsevMdNum)

nf.diffToBase()
// nf.diffToBase()
nf.diffToBaseNoCheckCount()
log.Info("After diffToBase", "base_size", nf.base.size, "base_layers", nf.base.layers,
"nbl_layers", nf.layers)
nf.backgroundFlush()
Expand Down Expand Up @@ -678,6 +679,59 @@ func (nf *nodebufferlist) traverseReverse(cb func(*multiDifflayer) bool) {
return
}

func (nf *nodebufferlist) diffToBaseNoCheckCount() {
commitFunc := func(buffer *multiDifflayer) bool {
log.Info("diffToBase function", "nf.base.size", nf.base.size, "nf.count", nf.count,
"buffer.block%nf.dlInMd", buffer.block%nf.dlInMd, "nf.base.limit", nf.base.limit, "nf.rsevMdNum", nf.rsevMdNum)

if nf.base.size >= nf.base.limit {
log.Debug("base node buffer need write disk immediately")
return false
}
if buffer.block%nf.dlInMd != 0 {
log.Crit("committed block number misaligned", "block", buffer.block)
}

if nf.keepFunc != nil { // keep in background flush stage
nf.keepFunc(&KeepRecord{
BlockID: buffer.block,
StateRoot: buffer.root,
KeepInterval: nf.wpBlocks,
PinnedInnerTrieReader: &proposedBlockReader{
nf: nf,
diff: buffer,
}})
}

nf.baseMux.Lock()
err := nf.base.commit(buffer.root, buffer.id, buffer.block, buffer.layers, buffer.nodes)
nf.baseMux.Unlock()
if err != nil {
log.Error("failed to commit nodes to base node buffer", "error", err)
return false
}

nf.mux.Lock()
_ = nf.popBack()
nodeBufferListSizeGauge.Update(int64(nf.size))
nodeBufferListCountGauge.Update(int64(nf.count))
nodeBufferListLayerGauge.Update(int64(nf.layers))
if nf.layers > 0 {
nodeBufferListDifflayerAvgSize.Update(int64(nf.size / nf.layers))
}
nf.mux.Unlock()
baseNodeBufferSizeGauge.Update(int64(nf.base.size))
baseNodeBufferLayerGauge.Update(int64(nf.base.layers))
if nf.base.layers > 0 {
baseNodeBufferDifflayerAvgSize.Update(int64(nf.base.size / nf.base.layers))
}
nf.report()

return true
}
nf.traverseReverse(commitFunc)
}

// diffToBase calls traverseReverse and merges the multiDifflayer's nodes to
// base node buffer, if up to limit size and flush to disk. It is called
// periodically in the background
Expand Down

0 comments on commit 56f7000

Please sign in to comment.