Skip to content

Commit

Permalink
change: rename Network methods to send_xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Aug 23, 2021
1 parent 8cd24ba commit a1a05bb
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion async-raft/src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
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"))),
Expand Down
2 changes: 1 addition & 1 deletion async-raft/src/core/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>
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;
}
Expand Down
10 changes: 7 additions & 3 deletions async-raft/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ pub trait RaftNetwork<D>: 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<D>) -> Result<AppendEntriesResponse>;
async fn send_append_entries(&self, target: NodeId, rpc: AppendEntriesRequest<D>) -> Result<AppendEntriesResponse>;

/// Send an InstallSnapshot RPC to the target Raft node (§7).
async fn install_snapshot(&self, target: NodeId, rpc: InstallSnapshotRequest) -> Result<InstallSnapshotResponse>;
async fn send_install_snapshot(
&self,
target: NodeId,
rpc: InstallSnapshotRequest,
) -> Result<InstallSnapshotResponse>;

/// Send a RequestVote RPC to the target Raft node (§5).
async fn vote(&self, target: NodeId, rpc: VoteRequest) -> Result<VoteResponse>;
async fn send_vote(&self, target: NodeId, rpc: VoteRequest) -> Result<VoteResponse>;
}
4 changes: 2 additions & 2 deletions async-raft/src/replication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>> 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
{
Expand Down Expand Up @@ -934,7 +934,7 @@ impl<'a, D: AppData, R: AppDataResponse, N: RaftNetwork<D>, S: RaftStorage<D, R>

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;

Expand Down
6 changes: 3 additions & 3 deletions async-raft/tests/conflict_with_empty_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());

Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions async-raft/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ impl RaftRouter {
#[async_trait]
impl RaftNetwork<MemClientRequest> 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<MemClientRequest>,
Expand All @@ -647,7 +647,7 @@ impl RaftNetwork<MemClientRequest> for RaftRouter {
}

/// Send an InstallSnapshot RPC to the target Raft node (§7).
async fn install_snapshot(&self, target: u64, rpc: InstallSnapshotRequest) -> Result<InstallSnapshotResponse> {
async fn send_install_snapshot(&self, target: u64, rpc: InstallSnapshotRequest) -> Result<InstallSnapshotResponse> {
self.rand_send_delay().await;

let rt = self.routing_table.read().await;
Expand All @@ -660,7 +660,7 @@ impl RaftNetwork<MemClientRequest> for RaftRouter {
}

/// Send a RequestVote RPC to the target Raft node (§5).
async fn vote(&self, target: u64, rpc: VoteRequest) -> Result<VoteResponse> {
async fn send_vote(&self, target: u64, rpc: VoteRequest) -> Result<VoteResponse> {
self.rand_send_delay().await;

let rt = self.routing_table.read().await;
Expand Down
2 changes: 1 addition & 1 deletion async-raft/tests/leader_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion async-raft/tests/snapshot_overrides_membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
{
Expand Down

0 comments on commit a1a05bb

Please sign in to comment.