mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Force trie.Database.Commit() to write everything out in a single batch
Iteration order over db.preimages is not deterministic, sorting the batch contents when the batch is written can be used to work around this. However, when multiple batches are written out the contents of each batch will differ every time, therefore sorting the contents of each batch is not sufficient to ensure deterministic in-order writes to the underlying store. These changes ensure the trie.Database.Commit() writes everything out in a single batch to avoid that particular problem.
This commit is contained in:
parent
c4f3537b02
commit
efd5bfcded
1 changed files with 0 additions and 13 deletions
|
|
@ -622,12 +622,6 @@ func (db *Database) Commit(node common.Hash, report bool) error {
|
||||||
db.lock.RUnlock()
|
db.lock.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if batch.ValueSize() > ethdb.IdealBatchSize {
|
|
||||||
if err := batch.Write(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
batch.Reset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Move the trie itself into the batch, flushing if enough data is accumulated
|
// Move the trie itself into the batch, flushing if enough data is accumulated
|
||||||
nodes, storage := len(db.nodes), db.nodesSize
|
nodes, storage := len(db.nodes), db.nodesSize
|
||||||
|
|
@ -686,13 +680,6 @@ func (db *Database) commit(hash common.Hash, batch ethdb.Batch) error {
|
||||||
if err := batch.Put(hash[:], node.rlp()); err != nil {
|
if err := batch.Put(hash[:], node.rlp()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If we've reached an optimal batch size, commit and start over
|
|
||||||
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
|
||||||
if err := batch.Write(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
batch.Reset()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue