Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

raft: introduce group commit #359

Merged
merged 6 commits into from
Apr 21, 2020
Merged

Conversation

BusyJay
Copy link
Member

@BusyJay BusyJay commented Apr 15, 2020

Every progress is assigned to a group ID. only logs replicated to at
least two different groups will be committed. The algorithm won't change
the quorum definition, it works more like delaying committing.

Close #347

Every progress is assigned to a group ID. only logs replicated to at
least two different groups will be committed. The algorithm won't change
the quorum definition, it works more like delaying committing.

Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
@BusyJay BusyJay added the Enhancement An improvement to existing code. label Apr 15, 2020
@BusyJay BusyJay requested review from hicqu and gengliqi April 15, 2020 08:33
src/raft.rs Outdated
return None;
}
if self.raft_log.term(self.raft_log.committed).unwrap_or(0) != self.term {
// Reject read only request when this leader has not committed any log entry
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the comment necessary? BTW it's better to extract the logic as a function.

(vec![4, 2, 1, 3], vec![1, 0, 0, 0], 1),
(vec![4, 2, 1, 3], vec![0, 1, 0, 2], 2),
(vec![4, 2, 1, 3], vec![0, 2, 1, 0], 1),
(vec![4, 2, 1, 3], vec![1, 1, 1, 1], 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

So if 4 peers are in one group, to commit a log needs 4 ACKs? I think we can ignore group ID if there is only 1 group.

BusyJay added 3 commits April 16, 2020 19:07
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
@gengliqi
Copy link
Member

gengliqi commented Apr 17, 2020

I think the algorithm of calculating the commit index can be:
min(quorum_commit_index, min(max match index of each group))

I miss the requirement is two different groups.

@BusyJay
Copy link
Member Author

BusyJay commented Apr 17, 2020

PTAL

hicqu
hicqu previously approved these changes Apr 20, 2020
src/raft.rs Outdated
if !self.apply_to_current_term() {
return None;
}
let (index, use_group_commit) = self.prs.as_mut().unwrap().maximal_committed_index();
Copy link
Member

Choose a reason for hiding this comment

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

Using self.mut_prs() is shorter

src/raft.rs Outdated
@@ -652,7 +721,7 @@ impl<T: Storage> Raft<T> {
/// Attempts to advance the commit index. Returns true if the commit index
/// changed (in which case the caller should call `r.bcast_append`).
pub fn maybe_commit(&mut self) -> bool {
let mci = self.prs().maximal_committed_index();
let mci = self.prs.as_mut().unwrap().maximal_committed_index().0;
Copy link
Member

Choose a reason for hiding this comment

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

self.mut_prs()

src/raft.rs Outdated
if let Some(pr) = self.mut_prs().get_mut(*peer_id) {
pr.commit_group_id = *group_id;
} else {
return;
Copy link
Member

Choose a reason for hiding this comment

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

Is it valid that the peer_id in ids can not exist in this raft group?

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, but here should be continue instead of returning.

(vec![4, 2, 1, 3], vec![0, 2, 1, 0], 1),
(vec![4, 2, 1, 3], vec![1, 1, 1, 1], 2),
(vec![4, 2, 1, 3], vec![1, 1, 2, 1], 1),
(vec![4, 2, 1, 3], vec![4, 3, 2, 1], 2),
Copy link
Member

Choose a reason for hiding this comment

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

It makes me confused about the answer of (vec![4, 2, 1, 3], vec![1, 0, 0, 0], 1) and (vec![4, 2, 1, 3], vec![1, 1, 1, 1], 2).
Maybe we can make the logic more straightforward, such as "if the kind of group number is greater than 2, we should use group commit"

Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
hicqu
hicqu previously approved these changes Apr 20, 2020
gengliqi
gengliqi previously approved these changes Apr 20, 2020
Copy link
Member

@gengliqi gengliqi left a 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: Jay Lee <BusyJayLee@gmail.com>
@BusyJay BusyJay dismissed stale reviews from gengliqi and hicqu via 2e7f00f April 20, 2020 10:04
src/raft.rs Outdated
@@ -418,9 +439,6 @@ impl<T: Storage> Raft<T> {
for (_, pr) in self.mut_prs().iter_mut() {
pr.commit_group_id = 0;
}
if StateRole::Leader == self.state && self.maybe_commit() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

If using group commit, then clearing group id will make commit index become smallest one, so no need to commit; if not using group commit, clearing group id has no effect.

@BusyJay BusyJay merged commit a1cfa63 into tikv:master Apr 21, 2020
@BusyJay BusyJay deleted the introduce-group-commit branch April 21, 2020 05:57
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Enhancement An improvement to existing code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants