Skip to content

Commit bdde616

Browse files
authored
Merge pull request #21477 from karalabe/snapshotter-shallow-generator
core/state/snapshot: reduce disk layer depth during generation
2 parents 0f4e7c9 + 3ee91b9 commit bdde616

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

core/state/snapshot/generate.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ type generatorStats struct {
5454

5555
// Log creates an contextual log with the given message and the context pulled
5656
// from the internally maintained statistics.
57-
func (gs *generatorStats) Log(msg string, marker []byte) {
57+
func (gs *generatorStats) Log(msg string, root common.Hash, marker []byte) {
5858
var ctx []interface{}
59-
59+
if root != (common.Hash{}) {
60+
ctx = append(ctx, []interface{}{"root", root}...)
61+
}
6062
// Figure out whether we're after or within an account
6163
switch len(marker) {
6264
case common.HashLength:
@@ -120,7 +122,7 @@ func generateSnapshot(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache i
120122
func (dl *diskLayer) generate(stats *generatorStats) {
121123
// If a database wipe is in operation, wait until it's done
122124
if stats.wiping != nil {
123-
stats.Log("Wiper running, state snapshotting paused", dl.genMarker)
125+
stats.Log("Wiper running, state snapshotting paused", common.Hash{}, dl.genMarker)
124126
select {
125127
// If wiper is done, resume normal mode of operation
126128
case <-stats.wiping:
@@ -137,13 +139,13 @@ func (dl *diskLayer) generate(stats *generatorStats) {
137139
accTrie, err := trie.NewSecure(dl.root, dl.triedb)
138140
if err != nil {
139141
// The account trie is missing (GC), surf the chain until one becomes available
140-
stats.Log("Trie missing, state snapshotting paused", dl.genMarker)
142+
stats.Log("Trie missing, state snapshotting paused", dl.root, dl.genMarker)
141143

142144
abort := <-dl.genAbort
143145
abort <- stats
144146
return
145147
}
146-
stats.Log("Resuming state snapshot generation", dl.genMarker)
148+
stats.Log("Resuming state snapshot generation", dl.root, dl.genMarker)
147149

148150
var accMarker []byte
149151
if len(dl.genMarker) > 0 { // []byte{} is the start, use nil for that
@@ -192,7 +194,7 @@ func (dl *diskLayer) generate(stats *generatorStats) {
192194
dl.lock.Unlock()
193195
}
194196
if abort != nil {
195-
stats.Log("Aborting state snapshot generation", accountHash[:])
197+
stats.Log("Aborting state snapshot generation", dl.root, accountHash[:])
196198
abort <- stats
197199
return
198200
}
@@ -230,15 +232,15 @@ func (dl *diskLayer) generate(stats *generatorStats) {
230232
dl.lock.Unlock()
231233
}
232234
if abort != nil {
233-
stats.Log("Aborting state snapshot generation", append(accountHash[:], storeIt.Key...))
235+
stats.Log("Aborting state snapshot generation", dl.root, append(accountHash[:], storeIt.Key...))
234236
abort <- stats
235237
return
236238
}
237239
}
238240
}
239241
}
240242
if time.Since(logged) > 8*time.Second {
241-
stats.Log("Generating state snapshot", accIt.Key)
243+
stats.Log("Generating state snapshot", dl.root, accIt.Key)
242244
logged = time.Now()
243245
}
244246
// Some account processed, unmark the marker

core/state/snapshot/journal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (dl *diskLayer) Journal(buffer *bytes.Buffer) (common.Hash, error) {
193193
dl.genAbort <- abort
194194

195195
if stats = <-abort; stats != nil {
196-
stats.Log("Journalling in-progress snapshot", dl.genMarker)
196+
stats.Log("Journalling in-progress snapshot", dl.root, dl.genMarker)
197197
}
198198
}
199199
// Ensure the layer didn't get stale

core/state/snapshot/snapshot.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ func (t *Tree) Cap(root common.Hash, layers int) error {
263263
if !ok {
264264
return fmt.Errorf("snapshot [%#x] is disk layer", root)
265265
}
266+
// If the generator is still running, use a more aggressive cap
267+
diff.origin.lock.RLock()
268+
if diff.origin.genMarker != nil && layers > 8 {
269+
layers = 8
270+
}
271+
diff.origin.lock.RUnlock()
272+
266273
// Run the internal capping and discard all stale layers
267274
t.lock.Lock()
268275
defer t.lock.Unlock()

0 commit comments

Comments
 (0)