Skip to content

Commit 22cd3bb

Browse files
committed
Change: remove deprecated RaftNetwork methods without option argument
1 parent b73f906 commit 22cd3bb

File tree

10 files changed

+78
-108
lines changed

10 files changed

+78
-108
lines changed

examples/raft-kv-memstore-generic-snapshot-data/src/network.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ impl RaftNetworkFactory<TypeConfig> for Router {
3737
}
3838

3939
impl RaftNetwork<TypeConfig> for Connection {
40-
async fn send_append_entries(
40+
async fn append_entries(
4141
&mut self,
4242
req: AppendEntriesRequest<TypeConfig>,
43+
_option: RPCOption,
4344
) -> Result<AppendEntriesResponse<NodeId>, typ::RPCError> {
4445
let resp = self
4546
.router
@@ -65,7 +66,11 @@ impl RaftNetwork<TypeConfig> for Connection {
6566
Ok(resp)
6667
}
6768

68-
async fn send_vote(&mut self, req: VoteRequest<NodeId>) -> Result<VoteResponse<NodeId>, typ::RPCError> {
69+
async fn vote(
70+
&mut self,
71+
req: VoteRequest<NodeId>,
72+
_option: RPCOption,
73+
) -> Result<VoteResponse<NodeId>, typ::RPCError> {
6974
let resp = self
7075
.router
7176
.send(self.target, "/raft/vote", req)

examples/raft-kv-memstore-opendal-snapshot-data/src/network.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ impl RaftNetworkFactory<TypeConfig> for Router {
3737
}
3838

3939
impl RaftNetwork<TypeConfig> for Connection {
40-
async fn send_append_entries(
40+
async fn append_entries(
4141
&mut self,
4242
req: AppendEntriesRequest<TypeConfig>,
43+
_option: RPCOption,
4344
) -> Result<AppendEntriesResponse<NodeId>, typ::RPCError> {
4445
let resp = self
4546
.router
@@ -65,7 +66,11 @@ impl RaftNetwork<TypeConfig> for Connection {
6566
Ok(resp)
6667
}
6768

68-
async fn send_vote(&mut self, req: VoteRequest<NodeId>) -> Result<VoteResponse<NodeId>, typ::RPCError> {
69+
async fn vote(
70+
&mut self,
71+
req: VoteRequest<NodeId>,
72+
_option: RPCOption,
73+
) -> Result<VoteResponse<NodeId>, typ::RPCError> {
6974
let resp = self
7075
.router
7176
.send(self.target, "/raft/vote", req)

examples/raft-kv-memstore-singlethreaded/src/network.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use openraft::error::InstallSnapshotError;
22
use openraft::error::RemoteError;
3+
use openraft::network::RPCOption;
34
use openraft::raft::AppendEntriesRequest;
45
use openraft::raft::AppendEntriesResponse;
56
use openraft::raft::InstallSnapshotRequest;
@@ -32,9 +33,10 @@ impl RaftNetworkFactory<TypeConfig> for Router {
3233
}
3334

3435
impl RaftNetwork<TypeConfig> for Connection {
35-
async fn send_append_entries(
36+
async fn append_entries(
3637
&mut self,
3738
req: AppendEntriesRequest<TypeConfig>,
39+
_option: RPCOption,
3840
) -> Result<AppendEntriesResponse<NodeId>, typ::RPCError> {
3941
let resp = self
4042
.router
@@ -44,9 +46,10 @@ impl RaftNetwork<TypeConfig> for Connection {
4446
Ok(resp)
4547
}
4648

47-
async fn send_install_snapshot(
49+
async fn install_snapshot(
4850
&mut self,
4951
req: InstallSnapshotRequest<TypeConfig>,
52+
_option: RPCOption,
5053
) -> Result<InstallSnapshotResponse<NodeId>, typ::RPCError<InstallSnapshotError>> {
5154
let resp = self
5255
.router
@@ -56,7 +59,11 @@ impl RaftNetwork<TypeConfig> for Connection {
5659
Ok(resp)
5760
}
5861

59-
async fn send_vote(&mut self, req: VoteRequest<NodeId>) -> Result<VoteResponse<NodeId>, typ::RPCError> {
62+
async fn vote(
63+
&mut self,
64+
req: VoteRequest<NodeId>,
65+
_option: RPCOption,
66+
) -> Result<VoteResponse<NodeId>, typ::RPCError> {
6067
let resp = self
6168
.router
6269
.send(self.target, "/raft/vote", req)

examples/raft-kv-memstore/src/network/raft_network_impl.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use openraft::error::InstallSnapshotError;
22
use openraft::error::NetworkError;
33
use openraft::error::RemoteError;
4+
use openraft::network::RPCOption;
45
use openraft::network::RaftNetwork;
56
use openraft::network::RaftNetworkFactory;
67
use openraft::raft::AppendEntriesRequest;
@@ -77,21 +78,27 @@ pub struct NetworkConnection {
7778
}
7879

7980
impl RaftNetwork<TypeConfig> for NetworkConnection {
80-
async fn send_append_entries(
81+
async fn append_entries(
8182
&mut self,
8283
req: AppendEntriesRequest<TypeConfig>,
84+
_option: RPCOption,
8385
) -> Result<AppendEntriesResponse<NodeId>, typ::RPCError> {
8486
self.owner.send_rpc(self.target, &self.target_node, "raft-append", req).await
8587
}
8688

87-
async fn send_install_snapshot(
89+
async fn install_snapshot(
8890
&mut self,
8991
req: InstallSnapshotRequest<TypeConfig>,
92+
_option: RPCOption,
9093
) -> Result<InstallSnapshotResponse<NodeId>, typ::RPCError<InstallSnapshotError>> {
9194
self.owner.send_rpc(self.target, &self.target_node, "raft-snapshot", req).await
9295
}
9396

94-
async fn send_vote(&mut self, req: VoteRequest<NodeId>) -> Result<VoteResponse<NodeId>, typ::RPCError> {
97+
async fn vote(
98+
&mut self,
99+
req: VoteRequest<NodeId>,
100+
_option: RPCOption,
101+
) -> Result<VoteResponse<NodeId>, typ::RPCError> {
95102
self.owner.send_rpc(self.target, &self.target_node, "raft-vote", req).await
96103
}
97104
}

examples/raft-kv-rocksdb/src/network/raft_network_impl.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use openraft::error::NetworkError;
66
use openraft::error::RPCError;
77
use openraft::error::RaftError;
88
use openraft::error::RemoteError;
9+
use openraft::network::RPCOption;
910
use openraft::network::RaftNetwork;
1011
use openraft::network::RaftNetworkFactory;
1112
use openraft::raft::AppendEntriesRequest;
@@ -99,7 +100,7 @@ fn to_error<E: std::error::Error + 'static + Clone>(e: toy_rpc::Error, target: N
99100
// 99 | ) -> Result<AppendEntriesResponse<NodeId>, RPCError<NodeId, Node, RaftError<NodeId>>>
100101
// {
101102
// | ___________________________________________________________________________________________^
102-
// 100 | | tracing::debug!(req = debug(&req), "send_append_entries");
103+
// 100 | | tracing::debug!(req = debug(&req), "append_entries");
103104
// 101 | |
104105
// 102 | | let c = self.c().await?;
105106
// ... |
@@ -112,11 +113,12 @@ fn to_error<E: std::error::Error + 'static + Clone>(e: toy_rpc::Error, target: N
112113
#[allow(clippy::blocks_in_conditions)]
113114
impl RaftNetwork<TypeConfig> for NetworkConnection {
114115
#[tracing::instrument(level = "debug", skip_all, err(Debug))]
115-
async fn send_append_entries(
116+
async fn append_entries(
116117
&mut self,
117118
req: AppendEntriesRequest<TypeConfig>,
119+
_option: RPCOption,
118120
) -> Result<AppendEntriesResponse<NodeId>, RPCError<NodeId, Node, RaftError<NodeId>>> {
119-
tracing::debug!(req = debug(&req), "send_append_entries");
121+
tracing::debug!(req = debug(&req), "append_entries");
120122

121123
let c = self.c().await?;
122124
tracing::debug!("got connection");
@@ -128,20 +130,22 @@ impl RaftNetwork<TypeConfig> for NetworkConnection {
128130
}
129131

130132
#[tracing::instrument(level = "debug", skip_all, err(Debug))]
131-
async fn send_install_snapshot(
133+
async fn install_snapshot(
132134
&mut self,
133135
req: InstallSnapshotRequest<TypeConfig>,
136+
_option: RPCOption,
134137
) -> Result<InstallSnapshotResponse<NodeId>, RPCError<NodeId, Node, RaftError<NodeId, InstallSnapshotError>>> {
135-
tracing::debug!(req = debug(&req), "send_install_snapshot");
138+
tracing::debug!(req = debug(&req), "install_snapshot");
136139
self.c().await?.raft().snapshot(req).await.map_err(|e| to_error(e, self.target))
137140
}
138141

139142
#[tracing::instrument(level = "debug", skip_all, err(Debug))]
140-
async fn send_vote(
143+
async fn vote(
141144
&mut self,
142145
req: VoteRequest<NodeId>,
146+
_option: RPCOption,
143147
) -> Result<VoteResponse<NodeId>, RPCError<NodeId, Node, RaftError<NodeId>>> {
144-
tracing::debug!(req = debug(&req), "send_vote");
148+
tracing::debug!(req = debug(&req), "vote");
145149
self.c().await?.raft().vote(req).await.map_err(|e| to_error(e, self.target))
146150
}
147151
}

openraft/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ where
240240
Closed(#[from] ReplicationClosed),
241241

242242
// TODO(xp): two sub type: StorageError / TransportError
243-
// TODO(xp): a sub error for just send_append_entries()
243+
// TODO(xp): a sub error for just append_entries()
244244
#[error(transparent)]
245245
StorageError(#[from] StorageError<NID>),
246246

openraft/src/network/network.rs

+19-81
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ use crate::Vote;
3131
///
3232
/// A single network instance is used to connect to a single target node. The network instance is
3333
/// constructed by the [`RaftNetworkFactory`](`crate::network::RaftNetworkFactory`).
34-
///
35-
/// ### 2023-05-03: New API with options
36-
///
37-
/// - This trait introduced 3 new API `append_entries`, `install_snapshot` and `vote` which accept
38-
/// an additional argument [`RPCOption`], and deprecated the old API `send_append_entries`,
39-
/// `send_install_snapshot` and `send_vote`.
40-
///
41-
/// - The old API will be **removed** in `0.9`. An application can still implement the old API
42-
/// without any changes. Openraft calls only the new API and the default implementation will
43-
/// delegate to the old API.
44-
///
45-
/// - Implementing the new APIs will disable the old APIs.
4634
#[add_async_trait]
4735
pub trait RaftNetwork<C>: OptionalSend + OptionalSync + 'static
4836
where C: RaftTypeConfig
@@ -52,37 +40,26 @@ where C: RaftTypeConfig
5240
&mut self,
5341
rpc: AppendEntriesRequest<C>,
5442
option: RPCOption,
55-
) -> Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>> {
56-
let _ = option;
57-
#[allow(deprecated)]
58-
self.send_append_entries(rpc).await
59-
}
43+
) -> Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>;
6044

6145
/// Send an InstallSnapshot RPC to the target.
46+
#[cfg(not(feature = "generic-snapshot-data"))]
6247
#[deprecated(since = "0.9.0", note = "use `snapshot()` instead for sending a complete snapshot")]
6348
async fn install_snapshot(
6449
&mut self,
65-
rpc: InstallSnapshotRequest<C>,
66-
option: RPCOption,
50+
_rpc: InstallSnapshotRequest<C>,
51+
_option: RPCOption,
6752
) -> Result<
6853
InstallSnapshotResponse<C::NodeId>,
6954
RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>,
70-
> {
71-
let _ = option;
72-
#[allow(deprecated)]
73-
self.send_install_snapshot(rpc).await
74-
}
55+
>;
7556

7657
/// Send a RequestVote RPC to the target.
7758
async fn vote(
7859
&mut self,
7960
rpc: VoteRequest<C::NodeId>,
8061
option: RPCOption,
81-
) -> Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>> {
82-
let _ = option;
83-
#[allow(deprecated)]
84-
self.send_vote(rpc).await
85-
}
62+
) -> Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>>;
8663

8764
/// Send a complete Snapshot to the target.
8865
///
@@ -99,67 +76,28 @@ where C: RaftTypeConfig
9976
/// with this vote.
10077
///
10178
/// `cancel` get `Ready` when the caller decides to cancel this snapshot transmission.
79+
#[cfg(feature = "generic-snapshot-data")]
10280
async fn snapshot(
10381
&mut self,
10482
vote: Vote<C::NodeId>,
10583
snapshot: Snapshot<C>,
10684
cancel: impl Future<Output = ReplicationClosed> + OptionalSend,
10785
option: RPCOption,
108-
) -> Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>> {
109-
#[cfg(not(feature = "generic-snapshot-data"))]
110-
{
111-
use crate::network::stream_snapshot;
112-
use crate::network::stream_snapshot::SnapshotTransport;
113-
114-
let resp = stream_snapshot::Chunked::send_snapshot(self, vote, snapshot, cancel, option).await?;
115-
Ok(resp)
116-
}
117-
#[cfg(feature = "generic-snapshot-data")]
118-
{
119-
let _ = (vote, snapshot, cancel, option);
120-
unimplemented!(
121-
"no default implementation for RaftNetwork::snapshot() if `generic-snapshot-data` feature is enabled"
122-
)
123-
}
124-
}
86+
) -> Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>>;
12587

126-
/// Send an AppendEntries RPC to the target Raft node (§5).
127-
#[deprecated(
128-
since = "0.8.4",
129-
note = "use `append_entries` instead. This method will be removed in 0.9"
130-
)]
131-
async fn send_append_entries(
132-
&mut self,
133-
rpc: AppendEntriesRequest<C>,
134-
) -> Result<AppendEntriesResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>> {
135-
let _ = rpc;
136-
unimplemented!("send_append_entries is deprecated")
137-
}
138-
139-
/// Send an InstallSnapshot RPC to the target Raft node (§7).
140-
#[deprecated(
141-
since = "0.8.4",
142-
note = "use `install_snapshot` instead. This method will be removed in 0.9"
143-
)]
144-
async fn send_install_snapshot(
88+
#[cfg(not(feature = "generic-snapshot-data"))]
89+
async fn snapshot(
14590
&mut self,
146-
rpc: InstallSnapshotRequest<C>,
147-
) -> Result<
148-
InstallSnapshotResponse<C::NodeId>,
149-
RPCError<C::NodeId, C::Node, RaftError<C::NodeId, InstallSnapshotError>>,
150-
> {
151-
let _ = rpc;
152-
unimplemented!("send_install_snapshot is deprecated")
153-
}
91+
vote: Vote<C::NodeId>,
92+
snapshot: Snapshot<C>,
93+
cancel: impl Future<Output = ReplicationClosed> + OptionalSend,
94+
option: RPCOption,
95+
) -> Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>> {
96+
use crate::network::stream_snapshot;
97+
use crate::network::stream_snapshot::SnapshotTransport;
15498

155-
/// Send a RequestVote RPC to the target Raft node (§5).
156-
#[deprecated(since = "0.8.4", note = "use `vote` instead. This method will be removed in 0.9")]
157-
async fn send_vote(
158-
&mut self,
159-
rpc: VoteRequest<C::NodeId>,
160-
) -> Result<VoteResponse<C::NodeId>, RPCError<C::NodeId, C::Node, RaftError<C::NodeId>>> {
161-
let _ = rpc;
162-
unimplemented!("send_vote is deprecated")
99+
let resp = stream_snapshot::Chunked::send_snapshot(self, vote, snapshot, cancel, option).await?;
100+
Ok(resp)
163101
}
164102

165103
/// Build a backoff instance if the target node is temporarily(or permanently) unreachable.

openraft/src/raft/message/append_entries.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ impl<C: RaftTypeConfig> MessageSummary<AppendEntriesRequest<C>> for AppendEntrie
5353

5454
/// The response to an `AppendEntriesRequest`.
5555
///
56-
/// [`RaftNetwork::send_append_entries`] returns this type only when received an RPC reply.
56+
/// [`RaftNetwork::append_entries`] returns this type only when received an RPC reply.
5757
/// Otherwise it should return [`RPCError`].
5858
///
5959
/// [`RPCError`]: crate::error::RPCError
60-
/// [`RaftNetwork::send_append_entries`]: crate::network::RaftNetwork::send_append_entries
60+
/// [`RaftNetwork::append_entries`]: crate::network::RaftNetwork::append_entries
6161
#[derive(Debug)]
6262
#[derive(PartialEq, Eq)]
6363
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))]
@@ -67,20 +67,20 @@ pub enum AppendEntriesResponse<NID: NodeId> {
6767

6868
/// Successfully sent the first portion of log entries.
6969
///
70-
/// [`RaftNetwork::send_append_entries`] can return a partial success.
70+
/// [`RaftNetwork::append_entries`] can return a partial success.
7171
/// For example, it tries to send log entries `[1-2..3-10]`, the application is allowed to send
7272
/// just `[1-2..1-3]` and return `PartialSuccess(1-3)`,
7373
///
7474
/// ### Caution
7575
///
7676
/// The returned matching log id must be **greater than or equal to** the first log
7777
/// id([`AppendEntriesRequest::prev_log_id`]) of the entries to send. If no RPC reply is
78-
/// received, [`RaftNetwork::send_append_entries`] must return an [`RPCError`] to inform
78+
/// received, [`RaftNetwork::append_entries`] must return an [`RPCError`] to inform
7979
/// Openraft that the first log id([`AppendEntriesRequest::prev_log_id`]) may not match on
8080
/// the remote target node.
8181
///
8282
/// [`RPCError`]: crate::error::RPCError
83-
/// [`RaftNetwork::send_append_entries`]: crate::network::RaftNetwork::send_append_entries
83+
/// [`RaftNetwork::append_entries`]: crate::network::RaftNetwork::append_entries
8484
PartialSuccess(Option<LogId<NID>>),
8585

8686
/// The first log id([`AppendEntriesRequest::prev_log_id`]) of the entries to send does not

0 commit comments

Comments
 (0)