Skip to content

Commit

Permalink
fix: update node buffer list logs
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Jun 24, 2024
1 parent 6800685 commit 6f4b548
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 47 deletions.
25 changes: 9 additions & 16 deletions trie/triedb/pathdb/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
var (
overflow bool
oldest uint64
limit = dl.db.config.StateHistory
)
if dl.db.freezer != nil {
err := writeHistory(dl.db.freezer, bottom)
Expand All @@ -293,7 +294,6 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
if err != nil {
return nil, err
}
limit := dl.db.config.StateHistory
if limit != 0 && bottom.stateID()-tail > limit {
overflow = true
oldest = bottom.stateID() - limit + 1 // track the id of history **after truncation**
Expand Down Expand Up @@ -322,10 +322,6 @@ 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
Expand All @@ -334,26 +330,23 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
// to 'oldest-1' due to the offset between the freezer index and the history ID.
if overflow {
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)
persistentID := rawdb.ReadPersistentStateID(dl.db.diskdb)
if persistentID > limit {
oldest = persistentID - limit + 1
log.Info("Forcing 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")
log.Info("No prune ancient under nodebufferlist, less than 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)
log.Error("Failed to truncate from tail", "ntail", oldest-1, "error", err)
return nil, err
}
log.Debug("Pruned state history", "items", pruned, "tailid", oldest)
log.Debug("Pruned state history", "items", pruned, "tail_id", oldest)
}
return ndl, nil
}
Expand Down
10 changes: 0 additions & 10 deletions trie/triedb/pathdb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,4 @@ var (
baseNodeBufferDifflayerAvgSize = metrics.NewRegisteredGauge("pathdb/basenodebuffer/difflayeravgsize", nil)
proposedBlockReaderSuccess = metrics.NewRegisteredMeter("pathdb/nodebufferlist/proposedblockreader/success", nil)
proposedBlockReaderMismatch = metrics.NewRegisteredMeter("pathdb/nodebufferlist/proposedblockreader/mismatch", nil)

// temp metrics for test purpose
nblCountGauge = metrics.NewRegisteredGauge("pathdb/nbl/count", nil)
nblLayersGauge = metrics.NewRegisteredGauge("pathdb/nbl/layers", nil)
nblPersistIDGauge = metrics.NewRegisteredGauge("pathdb/nbl/persistid", nil)
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)
)
24 changes: 3 additions & 21 deletions trie/triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +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)
log.Info("keep multiDiffLayer in node bufferList for getting withdrawal proof",
"reserved_multidiflayer", nf.rsevMdNum, "bufferList_count", nf.count)
return false
}
if err := nf.base.commit(buffer.root, buffer.id, buffer.block, buffer.layers, buffer.nodes); err != nil {
Expand All @@ -281,10 +281,8 @@ func (nf *nodebufferlist) flush(db ethdb.KeyValueStore, clean *fastcache.Cache,
_ = nf.popBack()
return true
}

nf.traverseReverse(commitFunc)
// delete after testing
prePersistID := nf.persistID
preBaseLayers := nf.base.layers
persistID := nf.persistID + nf.base.layers
err := nf.base.flush(nf.db, nf.clean, persistID)
if err != nil {
Expand All @@ -294,22 +292,6 @@ func (nf *nodebufferlist) flush(db ethdb.KeyValueStore, clean *fastcache.Cache,
nf.base.reset()
nf.persistID = persistID

nblCountGauge.Update(int64(nf.count))
nblLayersGauge.Update(int64(nf.layers))
nblPersistIDGauge.Update(int64(nf.persistID))
nblPrePersistIDGauge.Update(int64(prePersistID))
nblBaseLayersGauge.Update(int64(nf.base.layers))
nblPreBaseLayersGauge.Update(int64(preBaseLayers))
// add metrics, delete after testing
// 1. nf.count nf.layers => Guard type
// 2. nf.persistID prePersistID => Guard type
// 2. nf.base.layers preBaseLayes => Guard type

// test:
// 1. setup private seq
// 2. 10 accounts, 1qps, native transfer
// 3. add metrics(above)
// 4. wait more 9w
return nil
}

Expand Down

0 comments on commit 6f4b548

Please sign in to comment.