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

Fix lock re-entrancy in process_append_entry_request_as_follower() #43

Merged
merged 1 commit into from Sep 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 24 additions & 19 deletions little_raft/src/replica.rs
Expand Up @@ -705,25 +705,7 @@ where
return;
}

let mut state_machine = self.state_machine.lock().unwrap();
for entry in entries {
// Drop local inconsistent logs.
if entry.index <= self.get_last_log_index()
&& entry.term != self.get_term_at_index(entry.index).unwrap() {
for i in entry.index..self.log.len() {
state_machine.register_transition_state(
self.log[i].transition.get_id(),
TransitionState::Abandoned(TransitionAbandonedReason::ConflictWithLeader)
);
}
self.log.truncate(entry.index);
}

// Push received logs.
if entry.index == self.log.len() + self.index_offset {
self.log.push(entry);
}
}
self.process_entries(entries);

// Update local commit index to either the received commit index or the
// latest local log position, whichever is smaller.
Expand All @@ -745,6 +727,29 @@ where
);
}

fn process_entries(&mut self, entries: Vec<LogEntry<T>>) {
let mut state_machine = self.state_machine.lock().unwrap();
for entry in entries {
// Drop local inconsistent logs.
if entry.index <= self.get_last_log_index()
&& entry.term != self.get_term_at_index(entry.index).unwrap()
{
for i in entry.index..self.log.len() {
state_machine.register_transition_state(
self.log[i].transition.get_id(),
TransitionState::Abandoned(TransitionAbandonedReason::ConflictWithLeader),
);
}
self.log.truncate(entry.index);
}

// Push received logs.
if entry.index == self.log.len() + self.index_offset {
self.log.push(entry);
}
}
}

fn process_message_as_follower(&mut self, message: Message<T, D>) {
match message {
Message::VoteRequest {
Expand Down