mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
Move locking into trieDB insert function Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com>
This commit is contained in:
parent
d52bfaa5ca
commit
793293f041
2 changed files with 5 additions and 6 deletions
|
|
@ -193,9 +193,7 @@ func (c *committer) store(n node, db *Database) node {
|
||||||
} else if db != nil {
|
} else if db != nil {
|
||||||
// No leaf-callback used, but there's still a database. Do serial
|
// No leaf-callback used, but there's still a database. Do serial
|
||||||
// insertion
|
// insertion
|
||||||
db.Lock.Lock()
|
|
||||||
db.insert(common.BytesToHash(hash), size, n)
|
db.insert(common.BytesToHash(hash), size, n)
|
||||||
db.Lock.Unlock()
|
|
||||||
}
|
}
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
|
@ -208,10 +206,8 @@ func (c *committer) commitLoop(db *Database) {
|
||||||
size = item.size
|
size = item.size
|
||||||
n = item.node
|
n = item.node
|
||||||
)
|
)
|
||||||
// We are pooling the trie nodes into an intermediate memory Cache
|
// We are pooling the trie nodes into an intermediate memory cache
|
||||||
db.Lock.Lock()
|
|
||||||
db.insert(hash, size, n)
|
db.insert(hash, size, n)
|
||||||
db.Lock.Unlock()
|
|
||||||
|
|
||||||
if c.onleaf != nil {
|
if c.onleaf != nil {
|
||||||
switch n := n.(type) {
|
switch n := n.(type) {
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,10 @@ func (db *Database) DiskDB() ethdb.KeyValueStore {
|
||||||
// All nodes inserted by this function will be reference tracked
|
// All nodes inserted by this function will be reference tracked
|
||||||
// and in theory should only used for **trie nodes** insertion.
|
// and in theory should only used for **trie nodes** insertion.
|
||||||
func (db *Database) insert(hash common.Hash, size int, node node) {
|
func (db *Database) insert(hash common.Hash, size int, node node) {
|
||||||
// If the Node's already cached, skip
|
db.Lock.Lock()
|
||||||
|
defer db.Lock.Unlock()
|
||||||
|
|
||||||
|
// If the node's already cached, skip
|
||||||
if _, ok := db.dirties[hash]; ok {
|
if _, ok := db.dirties[hash]; ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue