From 6f4b548c3cbd3034b1dcf7991c54fd24b0d9a1aa Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 17 Jun 2024 14:56:35 +0800 Subject: [PATCH] fix: update node buffer list logs --- trie/triedb/pathdb/disklayer.go | 25 +++++++++---------------- trie/triedb/pathdb/metrics.go | 10 ---------- trie/triedb/pathdb/nodebufferlist.go | 24 +++--------------------- 3 files changed, 12 insertions(+), 47 deletions(-) diff --git a/trie/triedb/pathdb/disklayer.go b/trie/triedb/pathdb/disklayer.go index 395bec3f13..c949f0d4e2 100644 --- a/trie/triedb/pathdb/disklayer.go +++ b/trie/triedb/pathdb/disklayer.go @@ -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) @@ -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** @@ -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 @@ -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 } diff --git a/trie/triedb/pathdb/metrics.go b/trie/triedb/pathdb/metrics.go index 8d193a4974..ee91e5dc20 100644 --- a/trie/triedb/pathdb/metrics.go +++ b/trie/triedb/pathdb/metrics.go @@ -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) ) diff --git a/trie/triedb/pathdb/nodebufferlist.go b/trie/triedb/pathdb/nodebufferlist.go index 7f28eac661..12d055b06d 100644 --- a/trie/triedb/pathdb/nodebufferlist.go +++ b/trie/triedb/pathdb/nodebufferlist.go @@ -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 { @@ -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 { @@ -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 }