Skip to content

Commit

Permalink
reset max_apply_unpersisted_log_limit in become_follower
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <[email protected]>
  • Loading branch information
glorv committed Feb 20, 2025
1 parent 2fbeee5 commit 09742ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions harness/tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,12 +1874,15 @@ fn test_leader_stepdown_when_quorum_lost() {

sm.become_candidate();
sm.become_leader();
sm.raft_log.max_apply_unpersisted_log_limit = 100;

for _ in 0..=sm.election_timeout() {
sm.tick();
}

assert_eq!(sm.state, StateRole::Follower);
// check after become follower, the limit is reset.
assert_eq!(sm.raft_log.max_apply_unpersisted_log_limit, 0);
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,12 @@ impl<T: Storage> Raft<T> {
let from_role = self.state;
self.state = StateRole::Follower;
self.pending_request_snapshot = pending_request_snapshot;
// TODO: In theory, we should better control this in the caller,
// but bacuase the caller only know the leadership changes after
// call `ready()` and the committed entries is fetched within `ready()`,
// so we hard code this logic here. We may need to remove this hard code
// when we want to also support apply unpersisted log on follower.
self.raft_log.max_apply_unpersisted_log_limit = 0;
info!(
self.logger,
"became follower at term {term}",
Expand Down

0 comments on commit 09742ec

Please sign in to comment.