Skip to content

Commit

Permalink
Refactor: rename Command::DeleteConflictLog to TruncateLog
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Jul 5, 2024
1 parent e486124 commit 52f83c8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ where
{
tracing::debug!("append_to_log");

let (tx, rx) = C::AsyncRuntime::oneshot();
let (tx, rx) = C::oneshot();
let log_io_id = LogIOId::new(vote, Some(last_log_id));

let callback = LogFlushed::new(log_io_id, tx);
Expand Down Expand Up @@ -1622,7 +1622,7 @@ where
self.log_store.purge(upto).await?;
self.engine.state.io_state_mut().update_purged(Some(upto));
}
Command::DeleteConflictLog { since } => {
Command::TruncateLog { since } => {
self.log_store.truncate(since).await?;

// Inform clients waiting for logs to be applied.
Expand Down
8 changes: 4 additions & 4 deletions openraft/src/engine/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where C: RaftTypeConfig

/// Delete logs that conflict with the leader from a follower/learner since log id `since`,
/// inclusive.
DeleteConflictLog { since: LogId<C::NodeId> },
TruncateLog { since: LogId<C::NodeId> },

// TODO(1): current it is only used to replace BuildSnapshot, InstallSnapshot, CancelSnapshot.
/// A command send to state machine worker [`sm::worker::Worker`].
Expand Down Expand Up @@ -135,7 +135,7 @@ where
(Command::SaveVote { vote }, Command::SaveVote { vote: b }) => vote == b,
(Command::SendVote { vote_req }, Command::SendVote { vote_req: b }, ) => vote_req == b,
(Command::PurgeLog { upto }, Command::PurgeLog { upto: b }) => upto == b,
(Command::DeleteConflictLog { since }, Command::DeleteConflictLog { since: b }, ) => since == b,
(Command::TruncateLog { since }, Command::TruncateLog { since: b }, ) => since == b,
(Command::Respond { when, resp: send }, Command::Respond { when: b_when, resp: b }) => send == b && when == b_when,
(Command::StateMachine { command }, Command::StateMachine { command: b }) => command == b,
_ => false,
Expand All @@ -158,7 +158,7 @@ where C: RaftTypeConfig
Command::AppendInputEntries { .. } => CommandKind::Log,
Command::SaveVote { .. } => CommandKind::Log,
Command::PurgeLog { .. } => CommandKind::Log,
Command::DeleteConflictLog { .. } => CommandKind::Log,
Command::TruncateLog { .. } => CommandKind::Log,

Command::ReplicateCommitted { .. } => CommandKind::Network,
Command::Replicate { .. } => CommandKind::Network,
Expand Down Expand Up @@ -187,7 +187,7 @@ where C: RaftTypeConfig
Command::SaveVote { .. } => None,
Command::SendVote { .. } => None,
Command::PurgeLog { .. } => None,
Command::DeleteConflictLog { .. } => None,
Command::TruncateLog { .. } => None,
Command::Respond { when, .. } => when.as_ref(),
// TODO(1):
Command::StateMachine { .. } => None,
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/engine_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ where C: RaftTypeConfig
Command::SaveVote { .. } => {}
Command::SendVote { .. } => {}
Command::PurgeLog { .. } => {}
Command::DeleteConflictLog { .. } => {}
Command::TruncateLog { .. } => {}
Command::Respond { .. } => {}
}
self.commands.push_back(cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn test_install_snapshot_conflict() -> anyhow::Result<()> {
assert_eq!(
vec![
//
Command::DeleteConflictLog { since: log_id(2, 1, 4) },
Command::TruncateLog { since: log_id(2, 1, 4) },
Command::from(
sm::Command::install_full_snapshot(Snapshot {
meta: SnapshotMeta {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/following_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where C: RaftTypeConfig
};

self.state.log_ids.truncate(since);
self.output.push_command(Command::DeleteConflictLog { since: since_log_id });
self.output.push_command(Command::TruncateLog { since: since_log_id });

let changed = self.state.membership_state.truncate(since);
if let Some(_c) = changed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn test_truncate_logs_since_3() -> anyhow::Result<()> {
assert_eq!(
vec![
//
Command::DeleteConflictLog { since: log_id(2, 1, 3) },
Command::TruncateLog { since: log_id(2, 1, 3) },
],
eng.output.take_commands()
);
Expand All @@ -91,7 +91,7 @@ fn test_truncate_logs_since_4() -> anyhow::Result<()> {
assert_eq!(ServerState::Follower, eng.state.server_state);

assert_eq!(
vec![Command::DeleteConflictLog { since: log_id(4, 1, 4) }],
vec![Command::TruncateLog { since: log_id(4, 1, 4) }],
eng.output.take_commands()
);

Expand All @@ -107,7 +107,7 @@ fn test_truncate_logs_since_5() -> anyhow::Result<()> {
assert_eq!(Some(&log_id(4, 1, 4)), eng.state.last_log_id());
assert_eq!(&[log_id(2, 1, 2), log_id(4, 1, 4)], eng.state.log_ids.key_log_ids());
assert_eq!(
vec![Command::DeleteConflictLog { since: log_id(4, 1, 5) }],
vec![Command::TruncateLog { since: log_id(4, 1, 5) }],
eng.output.take_commands()
);

Expand All @@ -126,7 +126,7 @@ fn test_truncate_logs_since_6() -> anyhow::Result<()> {
eng.state.log_ids.key_log_ids()
);
assert_eq!(
vec![Command::DeleteConflictLog { since: log_id(4, 1, 6) }],
vec![Command::TruncateLog { since: log_id(4, 1, 6) }],
eng.output.take_commands()
);

Expand Down Expand Up @@ -181,7 +181,7 @@ fn test_truncate_logs_revert_effective_membership() -> anyhow::Result<()> {
assert_eq!(
vec![
//
Command::DeleteConflictLog { since: log_id(4, 1, 4) },
Command::TruncateLog { since: log_id(4, 1, 4) },
],
eng.output.take_commands()
);
Expand Down
6 changes: 3 additions & 3 deletions openraft/src/engine/tests/append_entries_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn test_append_entries_prev_log_id_conflict() -> anyhow::Result<()> {
Command::SaveVote {
vote: Vote::new_committed(2, 1)
},
Command::DeleteConflictLog { since: log_id(1, 1, 2) },
Command::TruncateLog { since: log_id(1, 1, 2) },
],
eng.output.take_commands()
);
Expand Down Expand Up @@ -197,7 +197,7 @@ fn test_append_entries_prev_log_id_is_committed() -> anyhow::Result<()> {
Command::SaveVote {
vote: Vote::new_committed(2, 1)
},
Command::DeleteConflictLog { since: log_id(1, 1, 2) },
Command::TruncateLog { since: log_id(1, 1, 2) },
Command::AppendInputEntries {
vote: Vote::new_committed(2, 1),
entries: vec![blank_ent(2, 1, 2)]
Expand Down Expand Up @@ -291,7 +291,7 @@ fn test_append_entries_conflict() -> anyhow::Result<()> {
Command::SaveVote {
vote: Vote::new_committed(2, 1)
},
Command::DeleteConflictLog { since: log_id(2, 1, 3) },
Command::TruncateLog { since: log_id(2, 1, 3) },
Command::AppendInputEntries {
vote: Vote::new_committed(2, 1),
entries: vec![Entry::new_membership(log_id(3, 1, 3), m34())]
Expand Down

0 comments on commit 52f83c8

Please sign in to comment.