@@ -13,6 +13,7 @@ use openraft::error::RPCError;
13
13
use openraft:: error:: RemoteError ;
14
14
use openraft:: raft:: AddLearnerResponse ;
15
15
use openraft:: raft:: ClientWriteResponse ;
16
+ use openraft:: BasicNode ;
16
17
use openraft:: RaftMetrics ;
17
18
use reqwest:: Client ;
18
19
use serde:: de:: DeserializeOwned ;
@@ -55,14 +56,17 @@ impl ExampleClient {
55
56
pub async fn write (
56
57
& self ,
57
58
req : & ExampleRequest ,
58
- ) -> Result < ClientWriteResponse < ExampleTypeConfig > , RPCError < ExampleNodeId , ClientWriteError < ExampleNodeId > > > {
59
+ ) -> Result <
60
+ ClientWriteResponse < ExampleTypeConfig > ,
61
+ RPCError < ExampleNodeId , BasicNode , ClientWriteError < ExampleNodeId , BasicNode > > ,
62
+ > {
59
63
self . send_rpc_to_leader ( "write" , Some ( req) ) . await
60
64
}
61
65
62
66
/// Read value by key, in an inconsistent mode.
63
67
///
64
68
/// This method may return stale value because it does not force to read on a legal leader.
65
- pub async fn read ( & self , req : & String ) -> Result < String , RPCError < ExampleNodeId , Infallible > > {
69
+ pub async fn read ( & self , req : & String ) -> Result < String , RPCError < ExampleNodeId , BasicNode , Infallible > > {
66
70
self . do_send_rpc_to_leader ( "read" , Some ( req) ) . await
67
71
}
68
72
@@ -72,7 +76,7 @@ impl ExampleClient {
72
76
pub async fn consistent_read (
73
77
& self ,
74
78
req : & String ,
75
- ) -> Result < String , RPCError < ExampleNodeId , CheckIsLeaderError < ExampleNodeId > > > {
79
+ ) -> Result < String , RPCError < ExampleNodeId , BasicNode , CheckIsLeaderError < ExampleNodeId , BasicNode > > > {
76
80
self . do_send_rpc_to_leader ( "consistent_read" , Some ( req) ) . await
77
81
}
78
82
@@ -84,7 +88,9 @@ impl ExampleClient {
84
88
/// With a initialized cluster, new node can be added with [`write`].
85
89
/// Then setup replication with [`add_learner`].
86
90
/// Then make the new node a member with [`change_membership`].
87
- pub async fn init ( & self ) -> Result < ( ) , RPCError < ExampleNodeId , InitializeError < ExampleNodeId > > > {
91
+ pub async fn init (
92
+ & self ,
93
+ ) -> Result < ( ) , RPCError < ExampleNodeId , BasicNode , InitializeError < ExampleNodeId , BasicNode > > > {
88
94
self . do_send_rpc_to_leader ( "init" , Some ( & Empty { } ) ) . await
89
95
}
90
96
@@ -94,7 +100,10 @@ impl ExampleClient {
94
100
pub async fn add_learner (
95
101
& self ,
96
102
req : ( ExampleNodeId , String ) ,
97
- ) -> Result < AddLearnerResponse < ExampleNodeId > , RPCError < ExampleNodeId , AddLearnerError < ExampleNodeId > > > {
103
+ ) -> Result <
104
+ AddLearnerResponse < ExampleNodeId > ,
105
+ RPCError < ExampleNodeId , BasicNode , AddLearnerError < ExampleNodeId , BasicNode > > ,
106
+ > {
98
107
self . send_rpc_to_leader ( "add-learner" , Some ( & req) ) . await
99
108
}
100
109
@@ -105,7 +114,10 @@ impl ExampleClient {
105
114
pub async fn change_membership (
106
115
& self ,
107
116
req : & BTreeSet < ExampleNodeId > ,
108
- ) -> Result < ClientWriteResponse < ExampleTypeConfig > , RPCError < ExampleNodeId , ClientWriteError < ExampleNodeId > > > {
117
+ ) -> Result <
118
+ ClientWriteResponse < ExampleTypeConfig > ,
119
+ RPCError < ExampleNodeId , BasicNode , ClientWriteError < ExampleNodeId , BasicNode > > ,
120
+ > {
109
121
self . send_rpc_to_leader ( "change-membership" , Some ( req) ) . await
110
122
}
111
123
@@ -114,7 +126,9 @@ impl ExampleClient {
114
126
/// Metrics contains various information about the cluster, such as current leader,
115
127
/// membership config, replication status etc.
116
128
/// See [`RaftMetrics`].
117
- pub async fn metrics ( & self ) -> Result < RaftMetrics < ExampleNodeId > , RPCError < ExampleNodeId , Infallible > > {
129
+ pub async fn metrics (
130
+ & self ,
131
+ ) -> Result < RaftMetrics < ExampleNodeId , BasicNode > , RPCError < ExampleNodeId , BasicNode , Infallible > > {
118
132
self . do_send_rpc_to_leader ( "metrics" , None :: < & ( ) > ) . await
119
133
}
120
134
@@ -129,7 +143,7 @@ impl ExampleClient {
129
143
& self ,
130
144
uri : & str ,
131
145
req : Option < & Req > ,
132
- ) -> Result < Resp , RPCError < ExampleNodeId , Err > >
146
+ ) -> Result < Resp , RPCError < ExampleNodeId , BasicNode , Err > >
133
147
where
134
148
Req : Serialize + ' static ,
135
149
Resp : Serialize + DeserializeOwned ,
@@ -174,17 +188,21 @@ impl ExampleClient {
174
188
& self ,
175
189
uri : & str ,
176
190
req : Option < & Req > ,
177
- ) -> Result < Resp , RPCError < ExampleNodeId , Err > >
191
+ ) -> Result < Resp , RPCError < ExampleNodeId , BasicNode , Err > >
178
192
where
179
193
Req : Serialize + ' static ,
180
194
Resp : Serialize + DeserializeOwned ,
181
- Err : std:: error:: Error + Serialize + DeserializeOwned + TryInto < ForwardToLeader < ExampleNodeId > > + Clone ,
195
+ Err : std:: error:: Error
196
+ + Serialize
197
+ + DeserializeOwned
198
+ + TryInto < ForwardToLeader < ExampleNodeId , BasicNode > >
199
+ + Clone ,
182
200
{
183
201
// Retry at most 3 times to find a valid leader.
184
202
let mut n_retry = 3 ;
185
203
186
204
loop {
187
- let res: Result < Resp , RPCError < ExampleNodeId , Err > > = self . do_send_rpc_to_leader ( uri, req) . await ;
205
+ let res: Result < Resp , RPCError < ExampleNodeId , BasicNode , Err > > = self . do_send_rpc_to_leader ( uri, req) . await ;
188
206
189
207
let rpc_err = match res {
190
208
Ok ( x) => return Ok ( x) ,
@@ -193,7 +211,7 @@ impl ExampleClient {
193
211
194
212
if let RPCError :: RemoteError ( remote_err) = & rpc_err {
195
213
let forward_err_res =
196
- <Err as TryInto < ForwardToLeader < ExampleNodeId > > >:: try_into ( remote_err. source . clone ( ) ) ;
214
+ <Err as TryInto < ForwardToLeader < ExampleNodeId , BasicNode > > >:: try_into ( remote_err. source . clone ( ) ) ;
197
215
198
216
if let Ok ( ForwardToLeader {
199
217
leader_id : Some ( leader_id) ,
0 commit comments