mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
force flush controlled in state_sizer
This commit is contained in:
parent
e1469bc414
commit
02474bd0bc
4 changed files with 12 additions and 13 deletions
|
|
@ -536,7 +536,6 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
|
||||||
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
|
stateSizer, err := state.NewSizeTracker(bc.db, bc.triedb)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
bc.stateSizer = stateSizer
|
bc.stateSizer = stateSizer
|
||||||
triedb.EnableForceFlush()
|
|
||||||
} else {
|
} else {
|
||||||
log.Info("Failed to setup size tracker", "err", err)
|
log.Info("Failed to setup size tracker", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -360,6 +360,8 @@ wait:
|
||||||
done chan buildResult
|
done chan buildResult
|
||||||
)
|
)
|
||||||
|
|
||||||
|
t.triedb.SetForceFlush(true)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-t.updateCh:
|
case u := <-t.updateCh:
|
||||||
|
|
@ -384,6 +386,8 @@ wait:
|
||||||
log.Info("Measuring persistent state size", "root", root.Hex())
|
log.Info("Measuring persistent state size", "root", root.Hex())
|
||||||
|
|
||||||
case result := <-done:
|
case result := <-done:
|
||||||
|
t.triedb.SetForceFlush(false)
|
||||||
|
|
||||||
if result.err != nil {
|
if result.err != nil {
|
||||||
return nil, result.err
|
return nil, result.err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -385,11 +385,11 @@ func (db *Database) SnapshotCompleted() bool {
|
||||||
return pdb.SnapshotCompleted()
|
return pdb.SnapshotCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableForceFlush enables the pathdb to flush any pending changes to disk immediately,
|
// SetForceFlush enables or disables the pathdb to flush any pending changes to disk
|
||||||
// regardless of the buffer size threshold. This can be used to accelerate
|
// immediately, regardless of the buffer size threshold. This can be used to accelerate
|
||||||
// state sizer initialization by making buffered state changes visible on disk.
|
// state sizer initialization by making buffered state changes visible on disk.
|
||||||
func (db *Database) EnableForceFlush() {
|
func (db *Database) SetForceFlush(enabled bool) {
|
||||||
if pdb, ok := db.backend.(*pathdb.Database); ok {
|
if pdb, ok := db.backend.(*pathdb.Database); ok {
|
||||||
pdb.EnableForceFlush()
|
pdb.SetForceFlush(enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -361,17 +361,13 @@ func (db *Database) Commit(root common.Hash, report bool) error {
|
||||||
return db.tree.cap(root, 0)
|
return db.tree.cap(root, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableForceFlush enables force flushing for the next state update.
|
// SetForceFlush enables or disables force flushing for the next state update.
|
||||||
// This will cause the next Update() call to flush the disk buffer immediately,
|
func (db *Database) SetForceFlush(enabled bool) {
|
||||||
// regardless of the buffer threshold, while preserving the 128 diff layers in memory.
|
|
||||||
func (db *Database) EnableForceFlush() {
|
|
||||||
db.lock.Lock()
|
db.lock.Lock()
|
||||||
defer db.lock.Unlock()
|
defer db.lock.Unlock()
|
||||||
|
|
||||||
if !db.forceFlush {
|
db.forceFlush = enabled
|
||||||
log.Info("Enabling force flush for next pathdb update")
|
log.Info("Set triedb force flush for next pathdb update", "enabled", enabled)
|
||||||
db.forceFlush = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable deactivates the database and invalidates all available state layers
|
// Disable deactivates the database and invalidates all available state layers
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue