Skip to content

Commit

Permalink
fix: fix truncate failed
Browse files Browse the repository at this point in the history
Co-authored-by: will@2012 <[email protected]>
  • Loading branch information
will-2012 and will@2012 authored Jun 17, 2024
1 parent a405a93 commit 6800685
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 20 additions & 2 deletions trie/triedb/pathdb/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,35 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
if !force && rawdb.ReadPersistentStateID(dl.db.diskdb) < oldest {
force = true
}
ancientNumber, _ := ndl.db.freezer.Ancients()
ancientTail, _ := ndl.db.freezer.Tail()
nblAncientSizeGauge.Update(int64(ancientNumber))
nblAncientTailGauge.Update(int64(ancientTail))

if err := ndl.buffer.flush(ndl.db.diskdb, ndl.cleans, ndl.id, force); err != nil {
return nil, err
}
// To remove outdated history objects from the end, we set the 'tail' parameter
// to 'oldest-1' due to the offset between the freezer index and the history ID.
if overflow {
if nl, ok := dl.buffer.(*nodebufferlist); ok {
oldest = nl.persistID - dl.db.config.StateHistory + 1
if _, ok := dl.buffer.(*nodebufferlist); ok {
persistentId := rawdb.ReadPersistentStateID(dl.db.diskdb)
if persistentId > dl.db.config.StateHistory {
oldest = persistentId - dl.db.config.StateHistory + 1
log.Info("force prune ancient under nodebufferlist", "disk_persistent_state_id", persistentId, "truncate_tail", oldest)
} else {
log.Info("no prune ancient under nodebufferlist, less db config state history limit")
return ndl, nil
}
}

pruned, err := truncateFromTail(ndl.db.diskdb, ndl.db.freezer, oldest-1)
ancientNumber, _ = ndl.db.freezer.Ancients()
ancientTail, _ = ndl.db.freezer.Tail()
nblAncientSizeGauge.Update(int64(ancientNumber))
nblAncientTailGauge.Update(int64(ancientTail))
if err != nil {
log.Error("Failed to truncate from tail", "ntail", oldest-1)
return nil, err
}
log.Debug("Pruned state history", "items", pruned, "tailid", oldest)
Expand Down
2 changes: 2 additions & 0 deletions trie/triedb/pathdb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ var (
nblPrePersistIDGauge = metrics.NewRegisteredGauge("pathdb/nbl/prepersistid", nil)
nblBaseLayersGauge = metrics.NewRegisteredGauge("pathdb/nbl/baselayers", nil)
nblPreBaseLayersGauge = metrics.NewRegisteredGauge("pathdb/nbl/prebaselayers", nil)
nblAncientSizeGauge = metrics.NewRegisteredGauge("pathdb/nbl/ancient/size", nil)
nblAncientTailGauge = metrics.NewRegisteredGauge("pathdb/nbl/ancient/tail", nil)
)
2 changes: 2 additions & 0 deletions trie/triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (nf *nodebufferlist) flush(db ethdb.KeyValueStore, clean *fastcache.Cache,

commitFunc := func(buffer *multiDifflayer) bool {
if nf.count <= nf.rsevMdNum {
log.Info("Skip force flush bufferlist due to bufferlist is too less",
"bufferlist_count", nf.count, "reserve_multi_difflayer_number", nf.rsevMdNum)
return false
}
if err := nf.base.commit(buffer.root, buffer.id, buffer.block, buffer.layers, buffer.nodes); err != nil {
Expand Down

0 comments on commit 6800685

Please sign in to comment.