-
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
raft: Avoid scanning raft log in become_leader #15
raft: Avoid scanning raft log in become_leader #15
Conversation
Great work @csmoe PTAL @Hoverbear @BusyJay |
src/raft.rs
Outdated
// pending log entries, and scanning the entire tail of the log | ||
// could be expensive. | ||
if ents.len() > 0 { | ||
self.pending_conf_index = ents[0].get_index() + ents.len() as u64 - 1; |
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.
You can use ents.last().map_or(0, |e| e.get_index())
.
src/raft.rs
Outdated
@@ -1819,7 +1826,8 @@ impl<T: Storage> Raft<T> { | |||
} | |||
|
|||
pub fn should_bcast_commit(&self) -> bool { | |||
!self.skip_bcast_commit || self.pending_conf | |||
let last_index = self.raft_log.last_index(); | |||
!self.skip_bcast_commit || (self.pending_conf_index == last_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.
I think it should be self.pending_conf_index > self.raft_log.applied
.
src/raft.rs
Outdated
// safe to delay any future proposals until we commit all our | ||
// pending log entries, and scanning the entire tail of the log | ||
// could be expensive. | ||
if ents.len() > 0 { |
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.
The check is unnecessary anymore.
@@ -1819,7 +1826,7 @@ impl<T: Storage> Raft<T> { | |||
} | |||
|
|||
pub fn should_bcast_commit(&self) -> bool { | |||
!self.skip_bcast_commit || self.pending_conf | |||
!self.skip_bcast_commit || (self.pending_conf_index > self.raft_log.applied) |
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 tests to cover this?
any update @csmoe |
@siddontang sorry for the delay. I'm trying to figure out the tests for |
tests/cases/test_raw_node.rs
Outdated
@@ -429,6 +429,11 @@ fn test_skip_bcast_commit() { | |||
// elect r1 as leader | |||
nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); | |||
|
|||
// Skip bcast commit when pending_conf_index <= applied |
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 we check the result of should_bcast_commit
here?
f98ab5f
to
0f0b42e
Compare
should resolve issue #11
modifications based on pull request etcd-io/etcd#9073