-
Notifications
You must be signed in to change notification settings - Fork 376
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
vsr: prevent state sync from breaking hash chain #1598
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Oops, something went wrong.
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.
Checking if I understand how this works:
In
on_start_view()
, we will reject the SV and transition to state sync if all of the SV's headers are beyond ourprepare_max
:So to advance our view (such that this new
jump_sync_target()
will not drop the message) we rely on pings or other messages thatjump_view()
uses to transition to view-change status (not normal status, since we will ignore the SV that we would request).And
jump_view()
does indeed precedejump_sync_target()
, so that can happen with a single ping: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.
Not exactly! This is related to me saying "the code already has the fix". My original thinking was that, indeed, accepting SV requires to do the state sync first. But to do state sync we need to change view. And when we receive a commit we don't jump view immediately, but wait for SV, which seems to create a deadlock.
So the fix I was planing to implement here was to jump to
view_change
when we receive a checkpoint target from the next log wrap and the next view.But, when I started coding, I realised that there's already code to do that! Right here:
tigerbeetle/src/vsr/replica.zig
Lines 1933 to 1935 in 7daa0b6
That is, even though we don't append any headers from an SV, we still go into view_change! And that resolves the deadlock.
So the full sequence of events is this:
.commit
with the next view & checkpointjump_view
on this commit, we send out.request_start_view
jump_sync_target
on this commit, we ignore the target, as it's in the future viewThere 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.
Ahh that makes sense, I forgot that
on_start_view
did that!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.
This made merealize that there's a subtlety here! I forgot about
view_durable
and check only forview
, but this is still correct:when view_durable is not updated, we can crash and restart into an earlier view, but that also means that we'll restart without newer sync target, so it ends up ok in the end.
Added a maybe to that effect.