Skip to content

Commit ce63bba

Browse files
authored
eth, triedb/pathdb: permit write buffer allowance in PBSS archive mode (#32091)
This pull request fixes a flaw in PBSS archive mode that significantly degrades performance when the mode is enabled. Originally, in hash mode, the dirty trie cache is completely disabled when archive mode is active, in order to disable the in-memory garbage collection mechanism. However, the internal logic in path mode differs significantly, and the dirty trie node cache is essential for maintaining chain insertion performance. Therefore, the cache is now retained in path mode.
1 parent 429e821 commit ce63bba

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
140140
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
141141
config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
142142
}
143-
if config.NoPruning && config.TrieDirtyCache > 0 {
143+
if config.NoPruning && config.TrieDirtyCache > 0 && config.StateScheme == rawdb.HashScheme {
144144
if config.SnapshotCache > 0 {
145145
config.TrieCleanCache += config.TrieDirtyCache * 3 / 5
146146
config.SnapshotCache += config.TrieDirtyCache * 2 / 5

triedb/pathdb/history_indexer.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ func (b *batchIndexer) finish(force bool) error {
128128
return nil
129129
}
130130
var (
131-
batch = b.db.NewBatch()
132-
batchMu sync.RWMutex
133-
eg errgroup.Group
131+
batch = b.db.NewBatch()
132+
batchMu sync.RWMutex
133+
storages int
134+
start = time.Now()
135+
eg errgroup.Group
134136
)
135137
eg.SetLimit(runtime.NumCPU())
136138

@@ -167,6 +169,7 @@ func (b *batchIndexer) finish(force bool) error {
167169
})
168170
}
169171
for addrHash, slots := range b.storages {
172+
storages += len(slots)
170173
for storageHash, idList := range slots {
171174
eg.Go(func() error {
172175
if !b.delete {
@@ -216,6 +219,7 @@ func (b *batchIndexer) finish(force bool) error {
216219
if err := batch.Write(); err != nil {
217220
return err
218221
}
222+
log.Debug("Committed batch indexer", "accounts", len(b.accounts), "storages", storages, "records", b.counter, "elapsed", common.PrettyDuration(time.Since(start)))
219223
b.counter = 0
220224
b.accounts = make(map[common.Hash][]uint64)
221225
b.storages = make(map[common.Hash]map[common.Hash][]uint64)
@@ -224,9 +228,10 @@ func (b *batchIndexer) finish(force bool) error {
224228

225229
// indexSingle processes the state history with the specified ID for indexing.
226230
func indexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.AncientReader) error {
227-
defer func(start time.Time) {
231+
start := time.Now()
232+
defer func() {
228233
indexHistoryTimer.UpdateSince(start)
229-
}(time.Now())
234+
}()
230235

231236
metadata := loadIndexMetadata(db)
232237
if metadata == nil || metadata.Last+1 != historyID {
@@ -247,15 +252,16 @@ func indexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.Ancient
247252
if err := b.finish(true); err != nil {
248253
return err
249254
}
250-
log.Debug("Indexed state history", "id", historyID)
255+
log.Debug("Indexed state history", "id", historyID, "elapsed", common.PrettyDuration(time.Since(start)))
251256
return nil
252257
}
253258

254259
// unindexSingle processes the state history with the specified ID for unindexing.
255260
func unindexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.AncientReader) error {
256-
defer func(start time.Time) {
261+
start := time.Now()
262+
defer func() {
257263
unindexHistoryTimer.UpdateSince(start)
258-
}(time.Now())
264+
}()
259265

260266
metadata := loadIndexMetadata(db)
261267
if metadata == nil || metadata.Last != historyID {
@@ -276,7 +282,7 @@ func unindexSingle(historyID uint64, db ethdb.KeyValueStore, freezer ethdb.Ancie
276282
if err := b.finish(true); err != nil {
277283
return err
278284
}
279-
log.Debug("Unindexed state history", "id", historyID)
285+
log.Debug("Unindexed state history", "id", historyID, "elapsed", common.PrettyDuration(time.Since(start)))
280286
return nil
281287
}
282288

0 commit comments

Comments
 (0)