-
Notifications
You must be signed in to change notification settings - Fork 682
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
Fix Concurrency Bug In CommitToParent #1320
Merged
+115
−11
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
08b38c9
Fix Concurrency Bug In CommitToParent
dboehm-avalabs 685bc51
Update trieview.go
dboehm-avalabs 6b8de88
Merge remote-tracking branch 'origin/dev' into FixCommitToParentBug
dboehm-avalabs a6312e3
fix
dboehm-avalabs e98a428
Update x/merkledb/db.go
dboehm-avalabs 3614f1b
Merge branch 'dev' into FixCommitToParentBug
dboehm-avalabs 5e1015d
Update trie_test.go
dboehm-avalabs fd457e8
Merge branch 'FixCommitToParentBug' of https://github.com/ava-labs/av…
dboehm-avalabs 52979e8
Update trieview.go
dboehm-avalabs 4d35c96
force serial commits
dboehm-avalabs 7f8bbe8
Update trieview.go
dboehm-avalabs 4131c5d
Update trieview.go
dboehm-avalabs fc53d2e
Update trieview.go
dboehm-avalabs 749b1ff
Merge branch 'dev' into FixCommitToParentBug
dboehm-avalabs debdebc
Update trieview.go
dboehm-avalabs a66898e
Merge branch 'FixCommitToParentBug' of https://github.com/ava-labs/av…
dboehm-avalabs 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
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ const defaultPreallocationSize = 100 | |
|
||
var ( | ||
ErrCommitted = errors.New("view has been committed") | ||
ErrInvalid = errors.New("the trie this view was based on has changed, rending this view invalid") | ||
ErrInvalid = errors.New("the trie this view was based on has changed, rendering this view invalid") | ||
ErrOddLengthWithValue = errors.New( | ||
"the underlying db only supports whole number of byte keys, so cannot record changes with odd nibble length", | ||
) | ||
|
@@ -222,10 +222,8 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { | |
|
||
// ensure that the view under this one is up-to-date before potentially pulling in nodes from it | ||
// getting the Merkle root forces any unupdated nodes to recalculate their ids | ||
if t.parentTrie != nil { | ||
if _, err := t.getParentTrie().GetMerkleRoot(ctx); err != nil { | ||
return err | ||
} | ||
if _, err := t.getParentTrie().GetMerkleRoot(ctx); err != nil { | ||
return err | ||
} | ||
|
||
if err := t.applyChangedValuesToTrie(ctx); err != nil { | ||
|
@@ -567,11 +565,10 @@ func (t *trieView) commitChanges(ctx context.Context, trieToCommit *trieView) er | |
|
||
// CommitToParent commits the changes from this view to its parent Trie | ||
func (t *trieView) CommitToParent(ctx context.Context) error { | ||
// if we are about to write to the db, then we to hold the commitLock | ||
if t.getParentTrie() == t.db { | ||
t.db.commitLock.Lock() | ||
defer t.db.commitLock.Unlock() | ||
} | ||
// TODO: Only lock the commitlock when the parent is the DB | ||
// TODO: fix concurrency bugs with CommitToParent | ||
t.db.commitLock.Lock() | ||
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. Prevents multiple commits from occurring at the same time until I can figure out a way to manage the safety of this. |
||
defer t.db.commitLock.Unlock() | ||
|
||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
|
@@ -597,7 +594,7 @@ func (t *trieView) commitToParent(ctx context.Context) error { | |
return err | ||
} | ||
|
||
// overwrite this view with changes from the incoming view | ||
// write this view's changes into its parent | ||
if err := t.getParentTrie().commitChanges(ctx, t); err != nil { | ||
return err | ||
} | ||
|
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.
detects as race and no longer needed. Hold over from when views could have no parent view.