Skip to content
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

Merged
merged 27 commits into from
Jul 1, 2019
Merged

Add request snapshot #243

merged 27 commits into from
Jul 1, 2019

Conversation

overvenus
Copy link
Member

This adds a feature that allows follower/learner request snapshot actively.

Impls tikv/rfcs#26

@overvenus overvenus requested review from BusyJay and hicqu June 10, 2019 07:12
proto/eraftpb.proto Outdated Show resolved Hide resolved
src/errors.rs Outdated Show resolved Hide resolved
src/progress.rs Outdated Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Outdated Show resolved Hide resolved
src/raft.rs Show resolved Hide resolved
src/storage.rs Show resolved Hide resolved
tests/integration_cases/test_raft.rs Show resolved Hide resolved
BusyJay
BusyJay previously approved these changes Jun 27, 2019
src/raft.rs Show resolved Hide resolved
if self.next_idx < 1 {
self.next_idx = 1;
}
} else if self.pending_request_snapshot == INVALID_INDEX {
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

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.
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

src/raft.rs Outdated Show resolved Hide resolved
let mut m = Message::new();
m.set_msg_type(MessageType::MsgAppendResponse);
m.set_index(self.raft_log.committed);
m.set_reject(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set reject?

Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

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.

src/storage.rs Outdated Show resolved Hide resolved
Signed-off-by: Neil Shen <[email protected]>
Copy link
Member

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@overvenus
Copy link
Member Author

PTAL @hicqu @BusyJay Thanks!

@overvenus overvenus merged commit fe10576 into 0.4.x Jul 1, 2019
nrc added a commit to nrc/raft-rs that referenced this pull request Jul 11, 2019
Signed-off-by: Nick Cameron <[email protected]>
nrc added a commit to nrc/raft-rs that referenced this pull request Jul 11, 2019
Signed-off-by: Nick Cameron <[email protected]>
nrc added a commit to nrc/raft-rs that referenced this pull request Jul 11, 2019
Signed-off-by: Nick Cameron <[email protected]>
nrc added a commit that referenced this pull request Jul 12, 2019
hicqu pushed a commit to hicqu/raft-rs that referenced this pull request Jul 17, 2019
Hoverbear pushed a commit that referenced this pull request Jul 19, 2019
* 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.
@BusyJay BusyJay mentioned this pull request Mar 3, 2020
@overvenus overvenus deleted the request-snapshot branch October 15, 2023 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants