From a1a05bb46eed4282af2c32d9db31f008b9519c15 Mon Sep 17 00:00:00 2001 From: drdr xp Date: Mon, 23 Aug 2021 18:41:36 +0800 Subject: [PATCH] change: rename Network methods to send_xxx --- async-raft/src/core/client.rs | 2 +- async-raft/src/core/vote.rs | 2 +- async-raft/src/network.rs | 10 +++++++--- async-raft/src/replication/mod.rs | 4 ++-- async-raft/tests/conflict_with_empty_entries.rs | 6 +++--- async-raft/tests/fixtures/mod.rs | 6 +++--- async-raft/tests/leader_metrics.rs | 2 +- async-raft/tests/snapshot_overrides_membership.rs | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/async-raft/src/core/client.rs b/async-raft/src/core/client.rs index 43a4833ec..b8c381821 100644 --- a/async-raft/src/core/client.rs +++ b/async-raft/src/core/client.rs @@ -175,7 +175,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage let ttl = Duration::from_millis(self.core.config.heartbeat_interval); let task = tokio::spawn( async move { - match timeout(ttl, network.append_entries(target, rpc)).await { + match timeout(ttl, network.send_append_entries(target, rpc)).await { Ok(Ok(data)) => Ok((target, data)), Ok(Err(err)) => Err((target, err)), Err(_timeout) => Err((target, anyhow!("timeout waiting for leadership confirmation"))), diff --git a/async-raft/src/core/vote.rs b/async-raft/src/core/vote.rs index a8059c8a5..38bc2ea68 100644 --- a/async-raft/src/core/vote.rs +++ b/async-raft/src/core/vote.rs @@ -160,7 +160,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage let (network, tx_inner) = (self.core.network.clone(), tx.clone()); let _ = tokio::spawn( async move { - match network.vote(member, rpc).await { + match network.send_vote(member, rpc).await { Ok(res) => { let _ = tx_inner.send((res, member)).await; } diff --git a/async-raft/src/network.rs b/async-raft/src/network.rs index a18ef76d8..afc7e6fa9 100644 --- a/async-raft/src/network.rs +++ b/async-raft/src/network.rs @@ -21,11 +21,15 @@ pub trait RaftNetwork: Send + Sync + 'static where D: AppData { /// Send an AppendEntries RPC to the target Raft node (§5). - async fn append_entries(&self, target: NodeId, rpc: AppendEntriesRequest) -> Result; + async fn send_append_entries(&self, target: NodeId, rpc: AppendEntriesRequest) -> Result; /// Send an InstallSnapshot RPC to the target Raft node (§7). - async fn install_snapshot(&self, target: NodeId, rpc: InstallSnapshotRequest) -> Result; + async fn send_install_snapshot( + &self, + target: NodeId, + rpc: InstallSnapshotRequest, + ) -> Result; /// Send a RequestVote RPC to the target Raft node (§5). - async fn vote(&self, target: NodeId, rpc: VoteRequest) -> Result; + async fn send_vote(&self, target: NodeId, rpc: VoteRequest) -> Result; } diff --git a/async-raft/src/replication/mod.rs b/async-raft/src/replication/mod.rs index 69e9d1c87..898a0cfcd 100644 --- a/async-raft/src/replication/mod.rs +++ b/async-raft/src/replication/mod.rs @@ -266,7 +266,7 @@ impl, S: RaftStorage> Re tracing::debug!("start sending append_entries, timeout: {:?}", self.heartbeat_timeout); let res = match timeout( self.heartbeat_timeout, - self.network.append_entries(self.target, payload), + self.network.send_append_entries(self.target, payload), ) .await { @@ -934,7 +934,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork, S: RaftStorage let res = timeout( self.replication_core.install_snapshot_timeout, - self.replication_core.network.install_snapshot(self.replication_core.target, req), + self.replication_core.network.send_install_snapshot(self.replication_core.target, req), ) .await; diff --git a/async-raft/tests/conflict_with_empty_entries.rs b/async-raft/tests/conflict_with_empty_entries.rs index cb2da52c8..8471af01b 100644 --- a/async-raft/tests/conflict_with_empty_entries.rs +++ b/async-raft/tests/conflict_with_empty_entries.rs @@ -57,7 +57,7 @@ async fn conflict_with_empty_entries() -> Result<()> { leader_commit: 5, }; - let resp = router.append_entries(0, rpc).await?; + let resp = router.send_append_entries(0, rpc).await?; assert!(!resp.success); assert!(resp.conflict_opt.is_some()); let c = resp.conflict_opt.unwrap(); @@ -93,7 +93,7 @@ async fn conflict_with_empty_entries() -> Result<()> { leader_commit: 5, }; - let resp = router.append_entries(0, rpc).await?; + let resp = router.send_append_entries(0, rpc).await?; assert!(resp.success); assert!(resp.conflict_opt.is_none()); @@ -107,7 +107,7 @@ async fn conflict_with_empty_entries() -> Result<()> { leader_commit: 5, }; - let resp = router.append_entries(0, rpc).await?; + let resp = router.send_append_entries(0, rpc).await?; assert!(!resp.success); assert!(resp.conflict_opt.is_some()); let c = resp.conflict_opt.unwrap(); diff --git a/async-raft/tests/fixtures/mod.rs b/async-raft/tests/fixtures/mod.rs index 357b3047f..7e41e942b 100644 --- a/async-raft/tests/fixtures/mod.rs +++ b/async-raft/tests/fixtures/mod.rs @@ -626,7 +626,7 @@ impl RaftRouter { #[async_trait] impl RaftNetwork for RaftRouter { /// Send an AppendEntries RPC to the target Raft node (§5). - async fn append_entries( + async fn send_append_entries( &self, target: u64, rpc: AppendEntriesRequest, @@ -647,7 +647,7 @@ impl RaftNetwork for RaftRouter { } /// Send an InstallSnapshot RPC to the target Raft node (§7). - async fn install_snapshot(&self, target: u64, rpc: InstallSnapshotRequest) -> Result { + async fn send_install_snapshot(&self, target: u64, rpc: InstallSnapshotRequest) -> Result { self.rand_send_delay().await; let rt = self.routing_table.read().await; @@ -660,7 +660,7 @@ impl RaftNetwork for RaftRouter { } /// Send a RequestVote RPC to the target Raft node (§5). - async fn vote(&self, target: u64, rpc: VoteRequest) -> Result { + async fn send_vote(&self, target: u64, rpc: VoteRequest) -> Result { self.rand_send_delay().await; let rt = self.routing_table.read().await; diff --git a/async-raft/tests/leader_metrics.rs b/async-raft/tests/leader_metrics.rs index cfd531ae4..8f97c106b 100644 --- a/async-raft/tests/leader_metrics.rs +++ b/async-raft/tests/leader_metrics.rs @@ -168,7 +168,7 @@ async fn leader_metrics() -> Result<()> { tracing::info!("--- take leadership of node 0"); router - .vote(0, VoteRequest { + .send_vote(0, VoteRequest { term: 100, candidate_id: 100, last_log_index: 100, diff --git a/async-raft/tests/snapshot_overrides_membership.rs b/async-raft/tests/snapshot_overrides_membership.rs index afbcb4490..b6995030d 100644 --- a/async-raft/tests/snapshot_overrides_membership.rs +++ b/async-raft/tests/snapshot_overrides_membership.rs @@ -104,7 +104,7 @@ async fn snapshot_overrides_membership() -> Result<()> { }], leader_commit: 0, }; - router.append_entries(1, req).await?; + router.send_append_entries(1, req).await?; tracing::info!("--- check that non-voter membership is affected"); {