mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
triedb/pathdb: limit the meta batch size for single retrieval
This commit is contained in:
parent
3dc549b3d7
commit
36d6e742cb
2 changed files with 38 additions and 26 deletions
|
|
@ -398,14 +398,34 @@ func (db *Database) Recoverable(root common.Hash) bool {
|
|||
return false
|
||||
}
|
||||
// Ensure the requested state is a canonical state and all state
|
||||
// histories in range [id+1, disklayer.ID] are present and complete.
|
||||
return checkHistories(db.freezer, *id+1, dl.stateID()-*id, func(m *meta) error {
|
||||
// histories in range [id+1, diskLayer.ID] are present and linked.
|
||||
var (
|
||||
start = *id + 1
|
||||
limit = dl.stateID()
|
||||
)
|
||||
for {
|
||||
// Short circuit if nothing more to check
|
||||
if start > limit {
|
||||
break
|
||||
}
|
||||
// Cap the meta items for single retrieval
|
||||
count := limit - start + 1
|
||||
if count > 1024 {
|
||||
count = 1024
|
||||
}
|
||||
err := checkHistories(db.freezer, start, count, func(m *meta) error {
|
||||
if m.parent != root {
|
||||
return errors.New("unexpected state history")
|
||||
}
|
||||
root = m.root
|
||||
return nil
|
||||
}) == nil
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
start += count
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Close closes the trie database and the held freezer.
|
||||
|
|
|
|||
|
|
@ -519,15 +519,10 @@ func writeHistory(freezer *rawdb.ResettableFreezer, dl *diffLayer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// checkHistories retrieves a batch of meta objects with the specified range
|
||||
// and performs the callback on each item.
|
||||
// checkHistories retrieves a batch of meta objects within the specified range
|
||||
// and performs the callback on top.
|
||||
func checkHistories(freezer *rawdb.ResettableFreezer, start, count uint64, check func(*meta) error) error {
|
||||
for count > 0 {
|
||||
number := count
|
||||
if number > 10000 {
|
||||
number = 10000 // split the big read into small chunks
|
||||
}
|
||||
blobs, err := rawdb.ReadStateHistoryMetaList(freezer, start, number)
|
||||
blobs, err := rawdb.ReadStateHistoryMetaList(freezer, start, count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -540,9 +535,6 @@ func checkHistories(freezer *rawdb.ResettableFreezer, start, count uint64, check
|
|||
return err
|
||||
}
|
||||
}
|
||||
count -= uint64(len(blobs))
|
||||
start += uint64(len(blobs))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue