-
Notifications
You must be signed in to change notification settings - Fork 406
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
Change the behavior of persisted index for snapshot #410
Conversation
Signed-off-by: gengliqi <[email protected]>
@BusyJay @NingLin-P PTAL, thanks. |
So if the |
It won't happen because the It seems it's hard to make the |
It's not true. Entries after snapshot won't cause conflict, so |
If there is no conflict, the persisted is also be changed. Lines 227 to 232 in fc1ef2f
|
If there is no conflict, Lines 217 to 236 in fc1ef2f
|
Hmmm, if it's zero, there is no new entries. |
By the way, I think we should set |
How about setting it to zero, which means unknown? Or use |
Signed-off-by: gengliqi <[email protected]>
bb7ca46
to
9324e81
Compare
It has problems because there is an invariant that After thinking for a while, I believe the most suitable method is Also, I add test for the case mentioned before, which is
|
@BusyJay @NingLin-P PTAL again, thanks. |
Signed-off-by: gengliqi <[email protected]>
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.
Rest LGTM
src/raft.rs
Outdated
// the last index of entries from previous leader when it becomes leader | ||
// (see the comments in become_leader), namely, the new persisted entries | ||
// must come from this leader. Here checking the term just for robustness. | ||
if update && self.state == StateRole::Leader && term == self.term { |
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.
How about using a log? Even if the term doesn't match self.term
in the future adaption, for example introducing paging, it's still safe to enter the if branch.
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.
Done.
@@ -565,6 +569,11 @@ impl<T: Storage> RawNode<T> { | |||
} | |||
let mut record = self.records.pop_front().unwrap(); | |||
|
|||
if let Some((i, t)) = record.snapshot { | |||
index = i; |
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.
Any case to cover?
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.
Added by changing test_async_ready_follower
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.
LGTM
Signed-off-by: gengliqi <[email protected]>
Signed-off-by: gengliqi <[email protected]>
Signed-off-by: gengliqi <[email protected]>
Signed-off-by: gengliqi <[email protected]>
f5e2215
to
147108d
Compare
This PR fixes a bug introduced by #410. Consider the case below 1. A receives a snapshot with index 10 2. A gets a ready and handles it asynchronously 3. A receives a new snapshot with index 20 4. A calls on_persist_ready for ready 1 In step 4, the persisted index can not be updated to 10 because the first_index has changed to 21 so the term check can not be passed. (details in `RaftLog::term`) I add a `maybe_persist_snap` function to fix this problem. The snapshot does not need to check the term because its data must be committed before and can not be changed in future. Signed-off-by: gengliqi <[email protected]>
This PR fixes a bug introduced by tikv/raft-rs#410. Consider the case below 1. A receives a snapshot with index 10 2. A gets a ready and handles it asynchronously 3. A receives a new snapshot with index 20 4. A calls on_persist_ready for ready 1 In step 4, the persisted index can not be updated to 10 because the first_index has changed to 21 so the term check can not be passed. (details in `RaftLog::term`) I add a `maybe_persist_snap` function to fix this problem. The snapshot does not need to check the term because its data must be committed before and can not be changed in future. Signed-off-by: gengliqi <[email protected]>
Signed-off-by: gengliqi [email protected]
In previous async ready PR(#403), After getting a snapshot and calling the
restore
function, thepersisted
is changed to the index of this snapshot. This makes thepersisted
index does not mean the data before this index is really persisted, which is not intuitive.The reason for this behavior is to maintain a invariant that
applied <= min(committed, persisted)
. However, I find it's not needed if the application calls theadvance_append
oron_persist_ready
then callsadvance_apply_to
. This is intuitive because the snapshot is persisted does not mean it is applied so it should be persisted first, then be applied.