-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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/rawdb: fix cornercase shutdown behaviour in freezer #26485
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f39e8df
core/rawdb: debug print exact numbers without prettification
holiman ebe49f4
core/rawdb: handle sync after close
holiman 3806472
core/rawdb: fix testcase, fix closed-check
holiman afd2457
core/rawdb: more verbosity after repair truncates items
holiman 63f7fba
cmd/geth: simplify freezer-inspect
holiman 40ede55
core/rawdb: fsync when closing freezer files
holiman 33b075c
core/rawdb: avoid sync on readonly files
holiman 743d702
core/rawdb: fixes re syncing files
holiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
core/rawdb: handle sync after close
- Loading branch information
commit ebe49f4252fec4a119e029efd6c2ea6c4e741afc
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -869,7 +869,9 @@ func (t *freezerTable) advanceHead() error { | |
func (t *freezerTable) Sync() error { | ||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
|
||
if t.index == nil || t.head == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also check if |
||
return errClosed | ||
} | ||
var err error | ||
trackError := func(e error) { | ||
if e != nil && err == nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,3 +407,51 @@ func TestRenameWindows(t *testing.T) { | |
t.Errorf("unexpected file contents. Got %v\n", buf) | ||
} | ||
} | ||
|
||
func TestFreezerCloseSync(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create test data. | ||
var valuesRaw [][]byte | ||
var valuesRLP []*big.Int | ||
for x := 0; x < 100; x++ { | ||
v := getChunk(256, x) | ||
valuesRaw = append(valuesRaw, v) | ||
iv := big.NewInt(int64(x)) | ||
iv = iv.Exp(iv, iv, nil) | ||
valuesRLP = append(valuesRLP, iv) | ||
} | ||
|
||
tables := map[string]bool{"raw": true, "rlp": false} | ||
f, _ := newFreezerForTesting(t, tables) | ||
defer f.Close() | ||
|
||
// Commit test data. | ||
_, err := f.ModifyAncients(func(op ethdb.AncientWriteOp) error { | ||
for i := range valuesRaw { | ||
if err := op.AppendRaw("raw", uint64(i), valuesRaw[i]); err != nil { | ||
return err | ||
} | ||
if err := op.Append("rlp", uint64(i), valuesRLP[i]); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatal("ModifyAncients failed:", err) | ||
} | ||
// Now, close and sync. This mimics the behaviour if the node is shut down, | ||
// just as the chain freezer is writing. | ||
// 1: thread-1: chain treezer writes, via freezeRange (holds lock) | ||
// 2: thread-2: Close called, waits for write to finish | ||
// 3: thread-1: finishes writing, releases lock | ||
// 4: thread-2: obtains lock, completes Close() | ||
// 5: thread-1: calls f.Sync() | ||
if err := f.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := f.Sync(); err != nil { | ||
t.Fatal(err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I'll just change this, and expect an error, and that the error (or error-string) is "closed", then? |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!