Skip to content

Commit

Permalink
Chore: fix lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Mar 5, 2024
1 parent c329969 commit 44cc427
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/raft-kv-memstore-generic-snapshot-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/raft-kv-memstore-opendal-snapshot-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/raft-kv-memstore-singlethreaded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeConfig>;

pub mod typ {
Expand Down
4 changes: 2 additions & 2 deletions examples/raft-kv-memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ openraft::declare_raft_types!(
Entry = openraft::Entry<TypeConfig>, SnapshotData = Cursor<Vec<u8>>, 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<TypeConfig>;

pub mod typ {
Expand Down
2 changes: 1 addition & 1 deletion examples/raft-kv-rocksdb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: OptionalSend, E: OptionalSend>(&self, tx: ResultSender<C, T, E>)
where E: From<ForwardToLeader<C::NodeId, C::Node>> {
pub(crate) fn reject_with_forward_to_leader<T: OptionalSend, E>(&self, tx: ResultSender<C, T, E>)
where E: From<ForwardToLeader<C::NodeId, C::Node>> + OptionalSend {
let mut leader_id = self.current_leader();
let leader_node = self.get_leader_node(leader_id);

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
impl<C> Debug for Entry<C>
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()
}
}
Expand Down
9 changes: 3 additions & 6 deletions openraft/src/network/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<C>,
_rpc: crate::raft::InstallSnapshotRequest<C>,
_option: RPCOption,
) -> Result<
InstallSnapshotResponse<C::NodeId>,
RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>,
crate::raft::InstallSnapshotResponse<C::NodeId>,
RPCError<C::NodeId, C::Node, RaftError<C::NodeId, crate::error::InstallSnapshotError>>,
>;

/// Send a RequestVote RPC to the target.
Expand Down
8 changes: 8 additions & 0 deletions openraft/src/progress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,27 @@ 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`.
fn get_mut(&mut self, id: &ID) -> Option<&mut V>;

// 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()`].
///
/// 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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions openraft/src/raft_state/vote_state_reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::NodeId;
use crate::Vote;

// TODO: remove it?
/// APIs to get vote.
#[allow(dead_code)]
pub(crate) trait VoteStateReader<NID: NodeId> {
/// Get a reference to the current vote.
fn vote_ref(&self) -> &Vote<NID>;
Expand Down
4 changes: 2 additions & 2 deletions openraft/src/testing/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,8 @@ where
}
}

fn log_id_0<NID: NodeId>(term: u64, index: u64) -> LogId<NID>
where NID: From<u64> {
fn log_id_0<NID>(term: u64, index: u64) -> LogId<NID>
where NID: NodeId + From<u64> {
LogId {
leader_id: CommittedLeaderId::new(term, NODE_ID.into()),
index,
Expand Down
4 changes: 4 additions & 0 deletions openraft/src/timer/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::AsyncRuntime;
use crate::Instant;
use crate::OptionalSend;

#[allow(dead_code)]
pub(crate) trait RaftTimer<RT: AsyncRuntime> {
/// Create a new instance that will call `callback` after `timeout`.
fn new<F: FnOnce() + OptionalSend + 'static>(callback: F, timeout: Duration) -> Self;
Expand All @@ -23,13 +24,15 @@ pub(crate) trait RaftTimer<RT: AsyncRuntime> {
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.
/// `callback` is guaranteed to be called at most once.
///
/// 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<RT: AsyncRuntime> {
/// A guard to notify the inner-task to quit when it is dropped.
// tx is not explicitly used.
Expand All @@ -40,6 +43,7 @@ pub(crate) struct Timeout<RT: AsyncRuntime> {
inner: Arc<TimeoutInner<RT>>,
}

#[allow(dead_code)]
pub(crate) struct TimeoutInner<RT: AsyncRuntime> {
/// The time when this Timeout is created.
///
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/vote/leader_id/leader_id_adv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<NID: NodeId> LeaderId<NID> {
}
}

impl<NID: NodeId> std::fmt::Display for LeaderId<NID> {
impl<NID: NodeId> fmt::Display for LeaderId<NID> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}-{}", self.term, self.node_id)
}
Expand Down
5 changes: 3 additions & 2 deletions openraft/src/vote/leader_id/leader_id_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<NID: NodeId> LeaderId<NID> {
}
}

impl<NID: NodeId> std::fmt::Display for LeaderId<NID> {
impl<NID: NodeId> fmt::Display for LeaderId<NID> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}-{:?}", self.term, self.voted_for)
}
Expand All @@ -82,7 +82,7 @@ pub struct CommittedLeaderId<NID> {
p: PhantomData<NID>,
}

impl<NID: NodeId> std::fmt::Display for CommittedLeaderId<NID> {
impl<NID: NodeId> fmt::Display for CommittedLeaderId<NID> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.term)
}
Expand All @@ -96,6 +96,7 @@ impl<NID: NodeId> CommittedLeaderId<NID> {
}

#[cfg(test)]
#[allow(clippy::nonminimal_bool)]
mod tests {
use crate::CommittedLeaderId;

Check warning on line 101 in openraft/src/vote/leader_id/leader_id_std.rs

View workflow job for this annotation

GitHub Actions / openraft-feature-test (nightly, single-term-leader)

unused import: `crate::CommittedLeaderId`

Check warning on line 101 in openraft/src/vote/leader_id/leader_id_std.rs

View workflow job for this annotation

GitHub Actions / openraft-test (nightly, 0, single-term-leader)

unused import: `crate::CommittedLeaderId`

Check warning on line 101 in openraft/src/vote/leader_id/leader_id_std.rs

View workflow job for this annotation

GitHub Actions / openraft-feature-test (nightly, single-term-leader)

unused import: `crate::CommittedLeaderId`

Check warning on line 101 in openraft/src/vote/leader_id/leader_id_std.rs

View workflow job for this annotation

GitHub Actions / openraft-test (nightly, 0, single-term-leader)

unused import: `crate::CommittedLeaderId`
use crate::LeaderId;
Expand Down
1 change: 1 addition & 0 deletions openraft/src/vote/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl<NID: NodeId> Vote<NID> {
}

#[cfg(test)]
#[allow(clippy::nonminimal_bool)]
mod tests {
#[cfg(not(feature = "single-term-leader"))]
mod feature_no_single_term_leader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down

0 comments on commit 44cc427

Please sign in to comment.