-
Notifications
You must be signed in to change notification settings - Fork 401
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
Add request snapshot #243
Add request snapshot #243
Conversation
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
… already Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
if self.next_idx < 1 { | ||
self.next_idx = 1; | ||
} | ||
} else if self.pending_request_snapshot == INVALID_INDEX { |
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.
Why else if
instead of else
?
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.
We don't want to update pending request snapshot if there is one already, let's keep it simple.
// TODO: revoke pub when there is a better way to test. | ||
/// For a given message, append the entries to the log. | ||
pub fn handle_append_entries(&mut self, m: &Message) { | ||
if self.pending_request_snapshot != INVALID_INDEX { |
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.
what if the entries is more new than pending_request_snapshot?
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.
It should be dropped if a follower is requesting a snapshot. After applying a snapshot, the follower will receive raft log entries again.
@@ -1794,7 +1849,10 @@ impl<T: Storage> Raft<T> { | |||
|
|||
fn restore_raft(&mut self, snap: &Snapshot) -> Option<bool> { | |||
let meta = snap.get_metadata(); | |||
if self.raft_log.match_term(meta.get_index(), meta.get_term()) { | |||
// Do not fast-forward commit if we are requesting snapshot. |
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.
Why?
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.
Because the snapshot may be dropped if there is no further proposal after requesting a snapshot.
if self.state == ProgressState::Replicate { | ||
// the rejection must be stale if the progress has matched and "rejected" | ||
// is smaller than "match". | ||
if rejected <= self.matched { | ||
// Or rejected equals to matched and request_snapshot is the INVALID_INDEX. |
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.
Can you give more explanation for this condition?
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.
Got it.
let mut m = Message::new(); | ||
m.set_msg_type(MessageType::MsgAppendResponse); | ||
m.set_index(self.raft_log.committed); | ||
m.set_reject(true); |
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.
Why set reject?
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.
It needs to be rejected, so it can enter requesting snapshot state in leader's view. See more at handle_append_response
.
// TODO: revoke pub when there is a better way to test. | ||
/// For a given message, append the entries to the log. | ||
pub fn handle_append_entries(&mut self, m: &Message) { | ||
if self.pending_request_snapshot != INVALID_INDEX { | ||
self.send_request_snapshot(); |
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.
Does the leader can tolerant follower send_request_snapshot
multiple times with the same pending_request_snapshot
?
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.
Yes, because request snapshot message may be dropped on the network, it needs to be able to send the same message multiple times.
Signed-off-by: Neil Shen <[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.
LGTM
Signed-off-by: Nick Cameron <[email protected]>
Signed-off-by: Nick Cameron <[email protected]>
Signed-off-by: Nick Cameron <[email protected]>
Signed-off-by: Nick Cameron <[email protected]>
Signed-off-by: Neil Shen <[email protected]>
* Check pending conf change before campaign (#225) Fix #221. * Add more convenient lite-weight interfaces (#227) This PR introduces two simple and lite weight interfaces: - ping to trigger heartbeats without ticking, - status_ref to borrow the progress set instead of cloning. * *: bump to 0.4.2 (#228) * Bump to v0.4.3 (#231) * raft: leader respond to learner read index message (#220) Signed-off-by: nolouch <[email protected]> * Bump to v0.4.3 Signed-off-by: Neil Shen <[email protected]> * Request snapshot (#243) Signed-off-by: Neil Shen <[email protected]> * fix tests * cargo fmt * address comments.
This adds a feature that allows follower/learner request snapshot actively.
Impls tikv/rfcs#26