Skip to content

Commit

Permalink
Chore: add tracing and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Mar 28, 2024
1 parent b497b3a commit 1d7a5ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 1 addition & 2 deletions openraft/src/engine/handler/replication_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ where C: RaftTypeConfig
if let Ok(inflight) = r {
Self::send_to_target(self.output, &target, inflight);
} else {
// TODO:
tracing::debug!("can not send: TODO");
tracing::debug!("nothing to send to target={target}, progress:{}", p);
}
}
}
Expand Down
30 changes: 24 additions & 6 deletions openraft/src/progress/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ impl<NID: NodeId> ProgressEntry<NID> {
Ok(())
}

/// Update conflicting log index.
///
/// Conflicting log index is the last found log index on a follower that is not matching the
/// leader log.
///
/// Usually if follower's data is lost, `conflict` is always greater than or equal `matching`.
/// But for testing purpose, a follower is allowed to clean its data and wait for leader to
/// replicate all data to it.
///
/// To allow a follower to clean its data, enable feature flag [`loosen-follower-log-revert`] .
///
/// [`loosen-follower-log-revert`]: crate::docs::feature_flags#feature_flag_loosen_follower_log_revert
pub(crate) fn update_conflicting(&mut self, request_id: u64, conflict: u64) -> Result<(), InflightError> {
tracing::debug!(
self = debug(&self),
Expand All @@ -126,11 +138,15 @@ impl<NID: NodeId> ProgressEntry<NID> {
//
// - If log reversion is allowed, just restart the binary search from the beginning.
// - Otherwise, panic it.
//
// Refer to: `docs::feature_flags#loosen_follower_log_revert`
{
#[cfg(feature = "loosen-follower-log-revert")]
if conflict < self.matching.next_index() {
tracing::warn!(
"conflict {} < last matching {}: follower log is reverted; with 'loosen-follower-log-revert' enabled, this is allowed.",
conflict,
self.matching.display(),
);

self.matching = None;
}

Expand Down Expand Up @@ -159,25 +175,27 @@ impl<NID: NodeId> ProgressEntry<NID> {
if !self.inflight.is_none() {
return Err(&self.inflight);
}
let purge_upto = log_state.purge_upto();
let snapshot_last = log_state.snapshot_last_log_id();

let last_next = log_state.last_log_id().next_index();
let purge_upto_next = purge_upto.next_index();

debug_assert!(
self.searching_end <= last_next,
"expect: searching_end: {} <= last_log_id.next_index: {}",
self.searching_end,
last_next
);

let purge_upto_next = {
let purge_upto = log_state.purge_upto();
purge_upto.next_index()
};

// `searching_end` is the max value for `start`.

// The log the follower needs is purged.
// Replicate by snapshot.
if self.searching_end < purge_upto_next {
self.curr_inflight_id += 1;
let snapshot_last = log_state.snapshot_last_log_id();
self.inflight = Inflight::snapshot(snapshot_last.copied()).with_id(self.curr_inflight_id);
return Ok(&self.inflight);
}
Expand Down

0 comments on commit 1d7a5ed

Please sign in to comment.