From 44cc4273b95112fc635e0a8d022a1165b4821666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Tue, 5 Mar 2024 19:58:27 +0800 Subject: [PATCH] Chore: fix lint warning --- .../raft-kv-memstore-generic-snapshot-data/src/lib.rs | 4 ++-- .../raft-kv-memstore-opendal-snapshot-data/src/lib.rs | 4 ++-- examples/raft-kv-memstore-singlethreaded/src/lib.rs | 4 ++-- examples/raft-kv-memstore/src/lib.rs | 4 ++-- examples/raft-kv-rocksdb/src/client.rs | 2 +- openraft/src/core/raft_core.rs | 4 ++-- openraft/src/entry/mod.rs | 2 +- openraft/src/network/network.rs | 9 +++------ openraft/src/progress/mod.rs | 8 ++++++++ openraft/src/raft_state/vote_state_reader.rs | 2 ++ openraft/src/testing/suite.rs | 4 ++-- openraft/src/timer/timeout.rs | 4 ++++ openraft/src/vote/leader_id/leader_id_adv.rs | 2 +- openraft/src/vote/leader_id/leader_id_std.rs | 5 +++-- openraft/src/vote/vote.rs | 1 + .../metrics/t20_metrics_state_machine_consistency.rs | 2 +- 16 files changed, 37 insertions(+), 24 deletions(-) diff --git a/examples/raft-kv-memstore-generic-snapshot-data/src/lib.rs b/examples/raft-kv-memstore-generic-snapshot-data/src/lib.rs index 27851cfa3..24356a7bd 100644 --- a/examples/raft-kv-memstore-generic-snapshot-data/src/lib.rs +++ b/examples/raft-kv-memstore-generic-snapshot-data/src/lib.rs @@ -36,8 +36,8 @@ openraft::declare_raft_types!( AsyncRuntime = TokioRuntime ); -pub type LogStore = crate::store::LogStore; -pub type StateMachineStore = crate::store::StateMachineStore; +pub type LogStore = store::LogStore; +pub type StateMachineStore = store::StateMachineStore; pub mod typ { use openraft::BasicNode; diff --git a/examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs b/examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs index c37bebfcb..b7cc20a0c 100644 --- a/examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs +++ b/examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs @@ -35,8 +35,8 @@ openraft::declare_raft_types!( AsyncRuntime = TokioRuntime ); -pub type LogStore = crate::store::LogStore; -pub type StateMachineStore = crate::store::StateMachineStore; +pub type LogStore = store::LogStore; +pub type StateMachineStore = store::StateMachineStore; pub mod typ { use openraft::BasicNode; diff --git a/examples/raft-kv-memstore-singlethreaded/src/lib.rs b/examples/raft-kv-memstore-singlethreaded/src/lib.rs index 72f9cd4a6..e3c4f8185 100644 --- a/examples/raft-kv-memstore-singlethreaded/src/lib.rs +++ b/examples/raft-kv-memstore-singlethreaded/src/lib.rs @@ -57,8 +57,8 @@ openraft::declare_raft_types!( AsyncRuntime = TokioRuntime ); -pub type LogStore = crate::store::LogStore; -pub type StateMachineStore = crate::store::StateMachineStore; +pub type LogStore = store::LogStore; +pub type StateMachineStore = store::StateMachineStore; pub type Raft = openraft::Raft; pub mod typ { diff --git a/examples/raft-kv-memstore/src/lib.rs b/examples/raft-kv-memstore/src/lib.rs index b0dbae181..3a3dd03af 100644 --- a/examples/raft-kv-memstore/src/lib.rs +++ b/examples/raft-kv-memstore/src/lib.rs @@ -33,8 +33,8 @@ openraft::declare_raft_types!( Entry = openraft::Entry, SnapshotData = Cursor>, AsyncRuntime = TokioRuntime ); -pub type LogStore = crate::store::LogStore; -pub type StateMachineStore = crate::store::StateMachineStore; +pub type LogStore = store::LogStore; +pub type StateMachineStore = store::StateMachineStore; pub type Raft = openraft::Raft; pub mod typ { diff --git a/examples/raft-kv-rocksdb/src/client.rs b/examples/raft-kv-rocksdb/src/client.rs index 92feb7646..f784f6137 100644 --- a/examples/raft-kv-rocksdb/src/client.rs +++ b/examples/raft-kv-rocksdb/src/client.rs @@ -34,7 +34,7 @@ impl ExampleClient { pub fn new(leader_id: NodeId, leader_addr: String) -> Self { Self { leader: Arc::new(Mutex::new((leader_id, leader_addr))), - inner: reqwest::Client::new(), + inner: Client::new(), } } diff --git a/openraft/src/core/raft_core.rs b/openraft/src/core/raft_core.rs index 921a08fb7..7bd6eb2b9 100644 --- a/openraft/src/core/raft_core.rs +++ b/openraft/src/core/raft_core.rs @@ -622,8 +622,8 @@ where /// Reject a request due to the Raft node being in a state which prohibits the request. #[tracing::instrument(level = "trace", skip(self, tx))] - pub(crate) fn reject_with_forward_to_leader(&self, tx: ResultSender) - where E: From> { + pub(crate) fn reject_with_forward_to_leader(&self, tx: ResultSender) + where E: From> + OptionalSend { let mut leader_id = self.current_leader(); let leader_node = self.get_leader_node(leader_id); diff --git a/openraft/src/entry/mod.rs b/openraft/src/entry/mod.rs index 342d09c34..f64b3f042 100644 --- a/openraft/src/entry/mod.rs +++ b/openraft/src/entry/mod.rs @@ -42,7 +42,7 @@ where impl Debug for Entry where C: RaftTypeConfig { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Entry").field("log_id", &self.log_id).field("payload", &self.payload).finish() } } diff --git a/openraft/src/network/network.rs b/openraft/src/network/network.rs index 59eb860e9..96f48ae94 100644 --- a/openraft/src/network/network.rs +++ b/openraft/src/network/network.rs @@ -4,7 +4,6 @@ use std::time::Duration; use macros::add_async_trait; use crate::error::Fatal; -use crate::error::InstallSnapshotError; use crate::error::RPCError; use crate::error::RaftError; use crate::error::ReplicationClosed; @@ -13,8 +12,6 @@ use crate::network::rpc_option::RPCOption; use crate::network::Backoff; use crate::raft::AppendEntriesRequest; use crate::raft::AppendEntriesResponse; -use crate::raft::InstallSnapshotRequest; -use crate::raft::InstallSnapshotResponse; use crate::raft::SnapshotResponse; use crate::raft::VoteRequest; use crate::raft::VoteResponse; @@ -47,11 +44,11 @@ where C: RaftTypeConfig #[deprecated(since = "0.9.0", note = "use `snapshot()` instead for sending a complete snapshot")] async fn install_snapshot( &mut self, - _rpc: InstallSnapshotRequest, + _rpc: crate::raft::InstallSnapshotRequest, _option: RPCOption, ) -> Result< - InstallSnapshotResponse, - RPCError>, + crate::raft::InstallSnapshotResponse, + RPCError>, >; /// Send a RequestVote RPC to the target. diff --git a/openraft/src/progress/mod.rs b/openraft/src/progress/mod.rs index 7beccc7f5..6e59b4782 100644 --- a/openraft/src/progress/mod.rs +++ b/openraft/src/progress/mod.rs @@ -63,6 +63,7 @@ where } /// Try to get the value by `id`. + #[allow(dead_code)] fn try_get(&self, id: &ID) -> Option<&V>; /// Returns a mutable reference to the value corresponding to the `id`. @@ -70,6 +71,7 @@ where // TODO: merge `get` and `try_get` /// Get the value by `id`. + #[allow(dead_code)] fn get(&self, id: &ID) -> &V; /// Get the greatest value that is granted by a quorum defined in [`Self::quorum_set()`]. @@ -77,9 +79,11 @@ where /// In raft or other distributed consensus, /// To commit a value, the value has to be **granted by a quorum** and has to be the greatest /// value every proposed. + #[allow(dead_code)] fn granted(&self) -> &P; /// Returns the reference to the quorum set + #[allow(dead_code)] fn quorum_set(&self) -> &QS; /// Iterate over all id and values, voters first followed by learners. @@ -327,6 +331,7 @@ where Ok(&self.granted) } + #[allow(dead_code)] fn try_get(&self, id: &ID) -> Option<&V> { let index = self.index(id)?; Some(&self.vector[index].1) @@ -337,15 +342,18 @@ where Some(&mut self.vector[index].1) } + #[allow(dead_code)] fn get(&self, id: &ID) -> &V { let index = self.index(id).unwrap(); &self.vector[index].1 } + #[allow(dead_code)] fn granted(&self) -> &P { &self.granted } + #[allow(dead_code)] fn quorum_set(&self) -> &QS { &self.quorum_set } diff --git a/openraft/src/raft_state/vote_state_reader.rs b/openraft/src/raft_state/vote_state_reader.rs index 73f85f5e2..2781ad273 100644 --- a/openraft/src/raft_state/vote_state_reader.rs +++ b/openraft/src/raft_state/vote_state_reader.rs @@ -1,7 +1,9 @@ use crate::NodeId; use crate::Vote; +// TODO: remove it? /// APIs to get vote. +#[allow(dead_code)] pub(crate) trait VoteStateReader { /// Get a reference to the current vote. fn vote_ref(&self) -> &Vote; diff --git a/openraft/src/testing/suite.rs b/openraft/src/testing/suite.rs index 49eb2a895..5038256cb 100644 --- a/openraft/src/testing/suite.rs +++ b/openraft/src/testing/suite.rs @@ -1098,8 +1098,8 @@ where } } -fn log_id_0(term: u64, index: u64) -> LogId -where NID: From { +fn log_id_0(term: u64, index: u64) -> LogId +where NID: NodeId + From { LogId { leader_id: CommittedLeaderId::new(term, NODE_ID.into()), index, diff --git a/openraft/src/timer/timeout.rs b/openraft/src/timer/timeout.rs index 05ceb712b..cd2e2e9ad 100644 --- a/openraft/src/timer/timeout.rs +++ b/openraft/src/timer/timeout.rs @@ -15,6 +15,7 @@ use crate::AsyncRuntime; use crate::Instant; use crate::OptionalSend; +#[allow(dead_code)] pub(crate) trait RaftTimer { /// Create a new instance that will call `callback` after `timeout`. fn new(callback: F, timeout: Duration) -> Self; @@ -23,6 +24,7 @@ pub(crate) trait RaftTimer { fn update_timeout(&self, timeout: Duration); } +// TODO: remove it. /// A oneshot timeout that supports deadline updating. /// /// When timeout deadline is reached, the `callback: Fn()` is called. @@ -30,6 +32,7 @@ pub(crate) trait RaftTimer { /// /// The deadline can be updated to a higher value then the old deadline won't trigger the /// `callback`. +#[allow(dead_code)] pub(crate) struct Timeout { /// A guard to notify the inner-task to quit when it is dropped. // tx is not explicitly used. @@ -40,6 +43,7 @@ pub(crate) struct Timeout { inner: Arc>, } +#[allow(dead_code)] pub(crate) struct TimeoutInner { /// The time when this Timeout is created. /// diff --git a/openraft/src/vote/leader_id/leader_id_adv.rs b/openraft/src/vote/leader_id/leader_id_adv.rs index a738a5f90..0a849c269 100644 --- a/openraft/src/vote/leader_id/leader_id_adv.rs +++ b/openraft/src/vote/leader_id/leader_id_adv.rs @@ -47,7 +47,7 @@ impl LeaderId { } } -impl std::fmt::Display for LeaderId { +impl fmt::Display for LeaderId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}-{}", self.term, self.node_id) } diff --git a/openraft/src/vote/leader_id/leader_id_std.rs b/openraft/src/vote/leader_id/leader_id_std.rs index f330183b4..ae298e525 100644 --- a/openraft/src/vote/leader_id/leader_id_std.rs +++ b/openraft/src/vote/leader_id/leader_id_std.rs @@ -67,7 +67,7 @@ impl LeaderId { } } -impl std::fmt::Display for LeaderId { +impl fmt::Display for LeaderId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}-{:?}", self.term, self.voted_for) } @@ -82,7 +82,7 @@ pub struct CommittedLeaderId { p: PhantomData, } -impl std::fmt::Display for CommittedLeaderId { +impl fmt::Display for CommittedLeaderId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.term) } @@ -96,6 +96,7 @@ impl CommittedLeaderId { } #[cfg(test)] +#[allow(clippy::nonminimal_bool)] mod tests { use crate::CommittedLeaderId; use crate::LeaderId; diff --git a/openraft/src/vote/vote.rs b/openraft/src/vote/vote.rs index 78603a97d..d72a8cb61 100644 --- a/openraft/src/vote/vote.rs +++ b/openraft/src/vote/vote.rs @@ -105,6 +105,7 @@ impl Vote { } #[cfg(test)] +#[allow(clippy::nonminimal_bool)] mod tests { #[cfg(not(feature = "single-term-leader"))] mod feature_no_single_term_leader { diff --git a/tests/tests/metrics/t20_metrics_state_machine_consistency.rs b/tests/tests/metrics/t20_metrics_state_machine_consistency.rs index bd972b449..8f1d88786 100644 --- a/tests/tests/metrics/t20_metrics_state_machine_consistency.rs +++ b/tests/tests/metrics/t20_metrics_state_machine_consistency.rs @@ -57,7 +57,7 @@ async fn metrics_state_machine_consistency() -> Result<()> { for node_id in 0..2 { router.wait_for_log(&btreeset![node_id], Some(log_index), None, "write one log").await?; let (sto, _sm) = router.get_storage_handle(&node_id)?; - assert!(sto.storage().await.get_state_machine().await.client_status.get("foo").is_some()); + assert!(sto.storage().await.get_state_machine().await.client_status.contains_key("foo")); } Ok(())