Skip to content

Commit 30e0585

Browse files
committed
force flush controlled in state_sizer
1 parent e32664f commit 30e0585

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

core/blockchain.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
533533
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
534534
if err == nil {
535535
bc.stateSizer = stateSizer
536-
triedb.EnableForceFlush()
537536
} else {
538537
log.Info("Failed to setup size tracker", "err", err)
539538
}

core/state/state_sizer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ wait:
360360
done chan buildResult
361361
)
362362

363+
t.triedb.SetForceFlush(true)
364+
363365
for {
364366
select {
365367
case u := <-t.updateCh:
@@ -384,6 +386,8 @@ wait:
384386
log.Info("Measuring persistent state size", "root", root.Hex())
385387

386388
case result := <-done:
389+
t.triedb.SetForceFlush(false)
390+
387391
if result.err != nil {
388392
return nil, result.err
389393
}

triedb/database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ func (db *Database) SnapshotCompleted() bool {
385385
return pdb.SnapshotCompleted()
386386
}
387387

388-
// EnableForceFlush enables the pathdb to flush any pending changes to disk immediately,
389-
// regardless of the buffer size threshold. This can be used to accelerate
388+
// SetForceFlush enables or disables the pathdb to flush any pending changes to disk
389+
// immediately, regardless of the buffer size threshold. This can be used to accelerate
390390
// state sizer initialization by making buffered state changes visible on disk.
391-
func (db *Database) EnableForceFlush() {
391+
func (db *Database) SetForceFlush(enabled bool) {
392392
if pdb, ok := db.backend.(*pathdb.Database); ok {
393-
pdb.EnableForceFlush()
393+
pdb.SetForceFlush(enabled)
394394
}
395395
}

triedb/pathdb/database.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,13 @@ func (db *Database) Commit(root common.Hash, report bool) error {
446446
return db.tree.cap(root, 0)
447447
}
448448

449-
// EnableForceFlush enables force flushing for the next state update.
450-
// This will cause the next Update() call to flush the disk buffer immediately,
451-
// regardless of the buffer threshold, while preserving the 128 diff layers in memory.
452-
func (db *Database) EnableForceFlush() {
449+
// SetForceFlush enables or disables force flushing for the next state update.
450+
func (db *Database) SetForceFlush(enabled bool) {
453451
db.lock.Lock()
454452
defer db.lock.Unlock()
455453

456-
if !db.forceFlush {
457-
log.Info("Enabling force flush for next pathdb update")
458-
db.forceFlush = true
459-
}
454+
db.forceFlush = enabled
455+
log.Info("Set triedb force flush for next pathdb update", "enabled", enabled)
460456
}
461457

462458
// Disable deactivates the database and invalidates all available state layers

triedb/pathdb/disklayer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) {
388388
// Terminate the background state snapshot generation before mutating the
389389
// persistent state.
390390
if combined.full() || force || dl.db.forceFlush {
391-
// Mark force flush as completed if it was triggered
392-
if dl.db.forceFlush {
393-
dl.db.forceFlush = false
394-
}
395391
// Wait until the previous frozen buffer is fully flushed
396392
if dl.frozen != nil {
397393
if err := dl.frozen.waitFlush(); err != nil {

0 commit comments

Comments
 (0)