Skip to content

Commit

Permalink
fix: skip node buffer count check when recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Jan 20, 2025
1 parent 1d6b06a commit 4b791a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/ethereum/go-ethereum/core/state/pruner"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/txpool/blobpool"
"github.com/ethereum/go-ethereum/core/txpool/bundlepool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down
1 change: 1 addition & 0 deletions triedb/pathdb/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ func TestJournal(t *testing.T) {
}
tester.db.Close()
pathConfig := Defaults
pathConfig.UseBase = true
tester.db = New(tester.db.diskdb, pathConfig)

// Verify states including disk layer and all diff on top.
Expand Down
24 changes: 17 additions & 7 deletions triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func newNodeBufferList(
}

var base *multiDifflayer
if nodes != nil && !fastRecovery {
if nodes != nil && useBase {
// after using fast recovery, use ancient db to recover nbl for force kill and graceful kill.
// so this case for now is used in unit test
var size uint64
for _, subset := range nodes {
for path, n := range subset {
Expand All @@ -135,6 +137,7 @@ func newNodeBufferList(
waitForceKeepCh: make(chan struct{}),
keepFunc: keepFunc,
}
nf.useBase.Store(useBase)

if !useBase && fastRecovery {
if freezer == nil {
Expand All @@ -151,7 +154,6 @@ func newNodeBufferList(
nf.tail = ele
nf.count = 1
}
nf.useBase.Store(useBase)

go nf.loop()

Expand Down Expand Up @@ -223,7 +225,7 @@ func (nf *nodebufferlist) recoverNodeBufferList(freezer *rawdb.ResettableFreezer
nf.size += current.size
nf.layers += current.layers
}
nf.diffToBase()
nf.diffToBase(true)
nf.backgroundFlush()

log.Info("Succeed to recover node buffer list", "base_size", nf.base.size, "tail_state_id", nf.tail.id,
Expand Down Expand Up @@ -676,16 +678,23 @@ func (nf *nodebufferlist) traverseReverse(cb func(*multiDifflayer) bool) {
// 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
func (nf *nodebufferlist) diffToBase() {
func (nf *nodebufferlist) diffToBase(skipCountCheck bool) {
count := 0
commitFunc := func(buffer *multiDifflayer) bool {
if nf.base.size >= nf.base.limit {
log.Debug("base node buffer need write disk immediately")
return false
}
if nf.count <= nf.rsevMdNum {
log.Debug("node buffer list less, waiting more difflayer to be committed")
if skipCountCheck && count == 1 { // only force flush one buffer to base
return false
}
if !skipCountCheck {
// when using fast recovery, force flush one buffer to base to avoid exceeding pebble batch size limit
if nf.count <= nf.rsevMdNum {
log.Debug("node buffer list less, waiting more difflayer to be committed")
return false
}
}
if buffer.block%nf.dlInMd != 0 {
log.Crit("committed block number misaligned", "block", buffer.block)
}
Expand Down Expand Up @@ -724,6 +733,7 @@ func (nf *nodebufferlist) diffToBase() {
baseNodeBufferDifflayerAvgSize.Update(int64(nf.base.size / nf.base.layers))
}
nf.report()
count++

return true
}
Expand Down Expand Up @@ -804,7 +814,7 @@ func (nf *nodebufferlist) loop() {
if nf.isFlushing.Swap(true) {
continue
}
nf.diffToBase()
nf.diffToBase(false)
if nf.base.size >= nf.base.limit {
nf.backgroundFlush()
}
Expand Down

0 comments on commit 4b791a7

Please sign in to comment.