mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
trie: use batch reset instead of recreation
This commit is contained in:
parent
abd99834db
commit
a7bae8c11c
1 changed files with 7 additions and 7 deletions
|
|
@ -262,12 +262,12 @@ func (db *Database) Commit(node common.Hash) error {
|
||||||
if err := batch.Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
batch = db.diskdb.NewBatch()
|
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+db.preimagesSize
|
nodes, storage := len(db.nodes), db.nodesSize+db.preimagesSize
|
||||||
if err := db.commit(node, &batch); err != nil {
|
if err := db.commit(node, batch); err != nil {
|
||||||
log.Error("Failed to commit trie from trie database", "err", err)
|
log.Error("Failed to commit trie from trie database", "err", err)
|
||||||
db.lock.RUnlock()
|
db.lock.RUnlock()
|
||||||
return err
|
return err
|
||||||
|
|
@ -299,7 +299,7 @@ func (db *Database) Commit(node common.Hash) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit is the private locked version of Commit.
|
// commit is the private locked version of Commit.
|
||||||
func (db *Database) commit(hash common.Hash, batch *ethdb.Batch) error {
|
func (db *Database) commit(hash common.Hash, batch ethdb.Batch) error {
|
||||||
// If the node does not exist, it's a previously committed node
|
// If the node does not exist, it's a previously committed node
|
||||||
node, ok := db.nodes[hash]
|
node, ok := db.nodes[hash]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -310,15 +310,15 @@ func (db *Database) commit(hash common.Hash, batch *ethdb.Batch) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := (*batch).Put(hash[:], node.blob); err != nil {
|
if err := batch.Put(hash[:], node.blob); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If we've reached an optimal match size, commit and start over
|
// If we've reached an optimal match size, commit and start over
|
||||||
if (*batch).ValueSize() >= ethdb.IdealBatchSize {
|
if batch.ValueSize() >= ethdb.IdealBatchSize {
|
||||||
if err := (*batch).Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*batch) = db.diskdb.NewBatch()
|
batch.Reset()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue