Skip to content

Commit

Permalink
Chore: adjust code format
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Jan 28, 2025
1 parent 3b76a7e commit 6f95aed
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 32 deletions.
19 changes: 4 additions & 15 deletions openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Borrow;
use std::collections::BTreeMap;
use std::fmt;
use std::fmt::Debug;
Expand Down Expand Up @@ -55,7 +54,6 @@ use crate::error::QuorumNotEnough;
use crate::error::RPCError;
use crate::error::Timeout;
use crate::log_id::LogIdOptionExt;
use crate::log_id::RaftLogId;
use crate::metrics::HeartbeatMetrics;
use crate::metrics::RaftDataMetrics;
use crate::metrics::RaftMetrics;
Expand Down Expand Up @@ -542,17 +540,8 @@ where
pub fn flush_metrics(&mut self) {
let (replication, heartbeat) = if let Some(leader) = self.engine.leader.as_ref() {
let replication_prog = &leader.progress;
let replication = Some(
replication_prog
.iter()
.map(|(id, p)| {
(
id.clone(),
<ProgressEntry<C> as Borrow<Option<LogIdOf<C>>>>::borrow(p).clone(),
)
})
.collect(),
);
let replication =
Some(replication_prog.iter().map(|(id, p)| (id.clone(), p.matching().cloned())).collect());

let clock_prog = &leader.clock_progress;
let heartbeat =
Expand Down Expand Up @@ -1746,10 +1735,10 @@ where
committed_vote: vote,
entries,
} => {
let last_log_id = entries.last().unwrap().get_log_id();
let last_log_id = entries.last().unwrap().log_id();
tracing::debug!("AppendInputEntries: {}", DisplaySlice::<_>(&entries),);

let io_id = IOId::new_log_io(vote, Some(last_log_id.clone()));
let io_id = IOId::new_log_io(vote, Some(last_log_id));
let notify = Notification::LocalIO { io_id: io_id.clone() };
let callback = IOFlushed::new(notify, self.tx_notification.downgrade());

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/snapshot_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where C: RaftTypeConfig
pub(crate) fn update_snapshot(&mut self, meta: SnapshotMeta<C>) -> bool {
tracing::info!("update_snapshot: {:?}", meta);

if meta.last_log_id <= self.state.snapshot_last_log_id().cloned() {
if meta.last_log_id.as_ref() <= self.state.snapshot_last_log_id() {
tracing::info!(
"No need to install a smaller snapshot: current snapshot last_log_id({}), new snapshot last_log_id({})",
self.state.snapshot_last_log_id().display(),
Expand Down
3 changes: 2 additions & 1 deletion openraft/src/engine/handler/vote_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Debug;
use std::time::Duration;

use crate::core::raft_msg::ResultSender;
use crate::display_ext::DisplayOptionExt;
use crate::engine::handler::leader_handler::LeaderHandler;
use crate::engine::handler::replication_handler::ReplicationHandler;
use crate::engine::handler::server_state_handler::ServerStateHandler;
Expand Down Expand Up @@ -164,7 +165,7 @@ where C: RaftTypeConfig
"become leader: node-{}, my vote: {}, last-log-id: {}",
self.config.id,
self.state.vote_ref(),
self.state.last_log_id().cloned().unwrap_or_default()
self.state.last_log_id().display()
);

if let Some(l) = self.leader.as_mut() {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where N: Node + Ord
type Term = u64;
type LeaderId = crate::impls::leader_id_adv::LeaderId<Self>;
type Vote = crate::impls::Vote<Self>;
type Entry = crate::Entry<Self>;
type Entry = crate::impls::Entry<Self>;
type SnapshotData = Cursor<Vec<u8>>;
type AsyncRuntime = TokioRuntime;
type Responder = crate::impls::OneshotResponder<Self>;
Expand Down
3 changes: 1 addition & 2 deletions openraft/src/log_id_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ mod tests {

use crate::engine::testing::UTConfig;
use crate::log_id_range::LogIdRange;
use crate::testing;
use crate::type_config::alias::LogIdOf;

fn log_id(index: u64) -> LogIdOf<UTConfig> {
testing::log_id(1, 1, index)
crate::engine::testing::log_id(1, 1, index)
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions openraft/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ mod tests {

#[test]
fn test_display() {
use crate::engine::testing::UTConfig;
use crate::MessageSummary;

let lid = crate::testing::log_id::<UTConfig>(1, 2, 3);
let lid = crate::engine::testing::log_id(1, 2, 3);
assert_eq!("T1-N2.3", lid.to_string());
assert_eq!("T1-N2.3", lid.summary());
assert_eq!("Some(T1-N2.3)", Some(&lid).summary());
Expand Down
13 changes: 3 additions & 10 deletions openraft/src/testing/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ where
C: RaftTypeConfig,
C::Term: From<u64>,
{
LogId::<C> {
leader_id: C::LeaderId::new_committed(term.into(), node_id),
index,
}
LogId::<C>::new(C::LeaderId::new_committed(term.into(), node_id), index)
}

/// Create a blank log entry for test.
Expand All @@ -30,13 +27,9 @@ where
}

/// Create a membership log entry without learner config for test.
pub fn membership_ent<C: RaftTypeConfig>(
term: u64,
node_id: C::NodeId,
index: u64,
config: Vec<BTreeSet<C::NodeId>>,
) -> crate::Entry<C>
pub fn membership_ent<C>(term: u64, node_id: C::NodeId, index: u64, config: Vec<BTreeSet<C::NodeId>>) -> crate::Entry<C>
where
C: RaftTypeConfig,
C::Term: From<u64>,
C::Node: Default,
{
Expand Down

0 comments on commit 6f95aed

Please sign in to comment.