core, ethdb, trie: mode dirty data to clean cache on flush (#19307)
This PR is a more advanced form of the dirty-to-clean cacher (#18995), where we reuse previous database write batches as datasets to uncache, saving a dirty-trie-iteration and a dirty-trie-rlp-reencoding per block.
This commit is contained in:
committed by
Felix Lange
parent
df717abc99
commit
59e1953246
@ -416,3 +416,32 @@ func (b *batch) Reset() {
|
||||
b.b.Reset()
|
||||
b.size = 0
|
||||
}
|
||||
|
||||
// Replay replays the batch contents.
|
||||
func (b *batch) Replay(w ethdb.Writer) error {
|
||||
return b.b.Replay(&replayer{writer: w})
|
||||
}
|
||||
|
||||
// replayer is a small wrapper to implement the correct replay methods.
|
||||
type replayer struct {
|
||||
writer ethdb.Writer
|
||||
failure error
|
||||
}
|
||||
|
||||
// Put inserts the given value into the key-value data store.
|
||||
func (r *replayer) Put(key, value []byte) {
|
||||
// If the replay already failed, stop executing ops
|
||||
if r.failure != nil {
|
||||
return
|
||||
}
|
||||
r.failure = r.writer.Put(key, value)
|
||||
}
|
||||
|
||||
// Delete removes the key from the key-value data store.
|
||||
func (r *replayer) Delete(key []byte) {
|
||||
// If the replay already failed, stop executing ops
|
||||
if r.failure != nil {
|
||||
return
|
||||
}
|
||||
r.failure = r.writer.Delete(key)
|
||||
}
|
||||
|
Reference in New Issue
Block a user