diff --git a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs index 521209e64..444488ba6 100644 --- a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs +++ b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs @@ -4,13 +4,10 @@ use std::time::Duration; use maplit::btreemap; use maplit::btreeset; -use openraft::error::NodeNotFound; -use openraft::AnyError; use openraft::BasicNode; use raft_kv_memstore::client::ExampleClient; use raft_kv_memstore::start_example_raft_node; use raft_kv_memstore::store::ExampleRequest; -use raft_kv_memstore::ExampleNodeId; use tokio::runtime::Runtime; use tracing_subscriber::EnvFilter; @@ -36,10 +33,7 @@ async fn test_cluster() -> anyhow::Result<()> { 2 => "127.0.0.1:21002".to_string(), 3 => "127.0.0.1:21003".to_string(), _ => { - return Err(NodeNotFound:: { - node_id, - source: AnyError::error("node not found"), - }); + return Err(anyhow::anyhow!("node {} not found", node_id)); } }; Ok(addr) diff --git a/examples/raft-kv-rocksdb/src/network/raft_network_impl.rs b/examples/raft-kv-rocksdb/src/network/raft_network_impl.rs index ef691901e..f9665a65c 100644 --- a/examples/raft-kv-rocksdb/src/network/raft_network_impl.rs +++ b/examples/raft-kv-rocksdb/src/network/raft_network_impl.rs @@ -5,7 +5,6 @@ use async_trait::async_trait; use openraft::error::AppendEntriesError; use openraft::error::InstallSnapshotError; use openraft::error::NetworkError; -use openraft::error::NodeNotFound; use openraft::error::RPCError; use openraft::error::RemoteError; use openraft::error::VoteError; @@ -19,7 +18,6 @@ use openraft::AnyError; use openraft::RaftNetwork; use openraft::RaftNetworkFactory; use serde::de::DeserializeOwned; -use serde::Serialize; use toy_rpc::pubsub::AckModeNone; use toy_rpc::Client; @@ -30,37 +28,6 @@ use crate::ExampleTypeConfig; pub struct ExampleNetwork {} -impl ExampleNetwork { - pub async fn send_rpc( - &self, - target: ExampleNodeId, - target_node: Option<&ExampleNode>, - uri: &str, - req: Req, - ) -> Result> - where - Req: Serialize, - Err: std::error::Error + DeserializeOwned, - Resp: DeserializeOwned, - { - let addr = target_node.map(|x| &x.rpc_addr).ok_or_else(|| { - RPCError::NodeNotFound(NodeNotFound { - node_id: target, - source: AnyError::default(), - }) - })?; - - let url = format!("http://{}/{}", addr, uri); - let client = reqwest::Client::new(); - - let resp = client.post(url).json(&req).send().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?; - - let res: Result = resp.json().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?; - - res.map_err(|e| RPCError::RemoteError(RemoteError::new(target, e))) - } -} - // NOTE: This could be implemented also on `Arc`, but since it's empty, implemented directly. #[async_trait] impl RaftNetworkFactory for ExampleNetwork { diff --git a/openraft/src/error.rs b/openraft/src/error.rs index 32672b800..a2196f054 100644 --- a/openraft/src/error.rs +++ b/openraft/src/error.rs @@ -283,9 +283,6 @@ where #[error(transparent)] StorageError(#[from] StorageError), - #[error(transparent)] - NodeNotFound(#[from] NodeNotFound), - #[error(transparent)] Timeout(#[from] Timeout), @@ -303,9 +300,6 @@ where serde(bound = "T:serde::Serialize + for <'d> serde::Deserialize<'d>") )] pub enum RPCError { - #[error(transparent)] - NodeNotFound(#[from] NodeNotFound), - #[error(transparent)] Timeout(#[from] Timeout), @@ -477,14 +471,6 @@ pub struct NotAMembershipEntry {} #[error("new membership can not be empty")] pub struct EmptyMembership {} -#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))] -#[error("node not found: {node_id}, source: {source}")] -pub struct NodeNotFound { - pub node_id: NID, - pub source: AnyError, -} - #[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[error("infallible")] diff --git a/openraft/src/replication/mod.rs b/openraft/src/replication/mod.rs index ec7568929..cab9f6f71 100644 --- a/openraft/src/replication/mod.rs +++ b/openraft/src/replication/mod.rs @@ -183,9 +183,6 @@ impl, S: RaftStorage> Replication let _ = self.tx_raft_core.send(RaftMsg::ReplicationFatal); return; } - ReplicationError::NodeNotFound(err) => { - unreachable!("programming bug: {}", err) - } ReplicationError::Timeout { .. } => { // nothing to do } @@ -306,7 +303,6 @@ impl, S: RaftStorage> Replication tracing::warn!(error=%err, "error sending AppendEntries RPC to target"); let repl_err = match err { - RPCError::NodeNotFound(e) => ReplicationError::NodeNotFound(e), RPCError::Timeout(e) => { let _ = self.tx_raft_core.send(RaftMsg::UpdateReplicationProgress { target: self.target, diff --git a/openraft/tests/fixtures/mod.rs b/openraft/tests/fixtures/mod.rs index 1cfc60b4a..748c32c05 100644 --- a/openraft/tests/fixtures/mod.rs +++ b/openraft/tests/fixtures/mod.rs @@ -32,7 +32,6 @@ use openraft::error::CheckIsLeaderError; use openraft::error::ClientWriteError; use openraft::error::InstallSnapshotError; use openraft::error::NetworkError; -use openraft::error::NodeNotFound; use openraft::error::RPCError; use openraft::error::RemoteError; use openraft::error::VoteError; @@ -423,12 +422,11 @@ where } #[tracing::instrument(level = "debug", skip(self))] - pub fn get_raft_handle(&self, node_id: &C::NodeId) -> std::result::Result, NodeNotFound> { + pub fn get_raft_handle(&self, node_id: &C::NodeId) -> std::result::Result, NetworkError> { let rt = self.routing_table.lock().unwrap(); - let raft_and_sto = rt.get(node_id).ok_or_else(|| NodeNotFound { - node_id: *node_id, - source: AnyError::error(""), - })?; + let raft_and_sto = rt + .get(node_id) + .ok_or_else(|| NetworkError::new(&AnyError::error(format!("node {} not found", *node_id))))?; let r = raft_and_sto.clone().0; Ok(r) }