Skip to content

Commit

Permalink
Fix: avoid panic with "loosen-follower-log-revert" enabled
Browse files Browse the repository at this point in the history
Problem:

When "loosen-follower-log-revert" enabled, and a follower log gets
reverted, e.g., all raft-logs are removed from that follower, the leader
encounters a panic due to a `debug_assert()`.

Solution:

- Disable the assertion when this feature is enabled.

- The test `feature_loosen_follower_log_revert` is also revised to reveal this
  bug.
  • Loading branch information
drmingdrmer committed Nov 17, 2023
1 parent 7382fb1 commit 5f26219
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion openraft/src/replication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,22 @@ where
func_name!()
);

debug_assert!(self.matching <= new_matching);
if cfg!(feature = "loosen-follower-log-revert") {
if self.matching > new_matching {
tracing::warn!(
"follower log is reverted from {} to {}; with 'loosen-follower-log-revert' enabled, this is allowed",
self.matching.display(),
new_matching.display(),
);
}
} else {
debug_assert!(
self.matching <= new_matching,
"follower log is reverted from {} to {}",
self.matching.display(),
new_matching.display(),
);
}

self.matching = new_matching;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ async fn feature_loosen_follower_log_revert() -> Result<()> {
Config {
enable_tick: false,
enable_heartbeat: false,
// Make sure the replication is done in more than one steps
max_payload_entries: 1,
..Default::default()
}
.validate()?,
Expand Down

0 comments on commit 5f26219

Please sign in to comment.