Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/state/snapshot: detect and clean up dangling storage snapshot in generation #24811

Merged
merged 30 commits into from
May 23, 2022
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8604adb
core/state/snapshot: check dangling storages when generating snapshot
rjl493456442 Apr 8, 2022
51f8a0e
core/state/snapshot: polish
rjl493456442 Apr 8, 2022
0ee1ebe
core/state/snapshot: wipe the last part of the dangling storages
rjl493456442 Apr 8, 2022
9b9dba1
core/state/snapshot: fix and add tests
rjl493456442 Apr 8, 2022
617eda9
core/state/snapshot: fix comment
rjl493456442 Apr 8, 2022
bbb6b94
README: remove mentions of fast sync (#24656)
nuoomnoy02 Apr 7, 2022
816f6cb
core, cmd: expose dangling storage detector for wider usage
rjl493456442 Apr 26, 2022
af23c13
core/state/snapshot: rename variable
rjl493456442 Apr 26, 2022
87d8bc3
core, ethdb: use global iterators for snapshot generation
rjl493456442 Apr 28, 2022
f4a489d
core/state/snapshot: polish
rjl493456442 May 4, 2022
5f37c25
cmd, core/state/snapshot: polish
rjl493456442 May 4, 2022
0584fc6
core/state/snapshot: polish
rjl493456442 May 4, 2022
546ce97
Update core/state/snapshot/generate.go
rjl493456442 May 4, 2022
b88d7ac
ethdb: extend db test suite and fix memorydb iterator
rjl493456442 May 5, 2022
e00ff21
ethdb/dbtest: rollback changes
rjl493456442 May 5, 2022
54caa24
ethdb/memorydb: simplify iteration
rjl493456442 May 5, 2022
7fca158
core/state/snapshot: update dangling counter
rjl493456442 May 5, 2022
e178af1
core/state/snapshot: release iterators
rjl493456442 May 7, 2022
3acad8d
core/state/snapshot: update metrics
rjl493456442 May 7, 2022
9a1ccd9
core/state/snapshot: update time metrics
rjl493456442 May 7, 2022
5df1225
metrics/influxdb: temp solution to present counter meaningfully, remo…
rjl493456442 May 7, 2022
d3fb321
add debug log, revert later
rjl493456442 May 7, 2022
83f60af
core/state/snapshot: fix iterator panic
rjl493456442 May 7, 2022
78ed542
all: customized snapshot iterator for backward iteration
rjl493456442 May 7, 2022
254666a
core, ethdb: polish
rjl493456442 May 9, 2022
1f5442d
core/state/snapshot: remove debug log
rjl493456442 May 9, 2022
55577d0
core/state/snapshot: address comments from peter
rjl493456442 May 10, 2022
61dcb92
core/state/snapshot: reopen the iterator at the next position
rjl493456442 May 10, 2022
c80a059
ethdb, core/state/snapshot: address comment from peter
rjl493456442 May 10, 2022
25b0392
core/state/snapshot: reopen exhausted iterators
rjl493456442 May 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core/state/snapshot: release iterators
  • Loading branch information
rjl493456442 committed May 9, 2022
commit e178af17b5350b60672ddc1f7a400dc0fe06ea26
12 changes: 3 additions & 9 deletions core/state/snapshot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ func (dl *diskLayer) checkAndFlush(ctx *generatorContext, current []byte) error
ctx.stats.Log("Aborting state snapshot generation", dl.root, current)
return newAbortErr(abort) // bubble up an error for interruption
}
// Don't hold the iterators too long, release them to let compactor works
ctx.reopenIterators()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this is the appropriate location? If the snapshot is solid with only a few errors, it could happen that the iterator is held open for quite a long time, since the batch doesn't grow enough to trigger a write / reopen. Given that a node might be stuck on generation for many hours whilst still importing blocks, I think only reopening when enough snapshot errors are found might be dangerous?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right. For an almost-all-correct snapshot, this condition is not suitable.

However you said Given that a node might be stuck on generation for many hours whilst still importing blocks, I guess it only happens on some idle testnets right? Mainnet wise we will always abort and resume generation.

But I will re think about where to place this code.

}
if time.Since(ctx.logged) > 8*time.Second {
ctx.stats.Log("Generating state snapshot", dl.root, current)
Expand Down Expand Up @@ -635,10 +637,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
if len(accMarker) > 0 {
accountRange = 1
}
var (
iterTime = time.Now()
origin = common.CopyBytes(accMarker)
)
origin := common.CopyBytes(accMarker)
for {
exhausted, last, err := dl.generateRange(ctx, dl.root, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountRange, onAccount, FullAccountRLP)
if err != nil {
Expand All @@ -652,11 +651,6 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
ctx.removeStorageLeft()
break
}
// Don't hold iterator too long, re-open them to let compactor works.
if time.Since(iterTime) > time.Minute*3 {
iterTime = time.Now()
ctx.reopenIterators()
}
}
return nil
}
Expand Down