1#[derive(serde::Serialize, serde::Deserialize)]
3#[derive(Clone, PartialEq, ::prost::Message)]
4pub struct AppendEntriesRequest {
5 #[prost(uint64, tag = "1")]
6 pub term: u64,
7 #[prost(uint32, tag = "2")]
8 pub leader_id: u32,
9 #[prost(uint64, tag = "3")]
10 pub prev_log_index: u64,
11 #[prost(uint64, tag = "4")]
12 pub prev_log_term: u64,
13 #[prost(message, repeated, tag = "5")]
14 pub entries: ::prost::alloc::vec::Vec<super::common::Entry>,
15 #[prost(uint64, tag = "6")]
16 pub leader_commit_index: u64,
17}
18#[derive(serde::Serialize, serde::Deserialize)]
19#[derive(Clone, Copy, PartialEq, ::prost::Message)]
20pub struct AppendEntriesResponse {
21 #[prost(uint32, tag = "1")]
22 pub node_id: u32,
23 #[prost(uint64, tag = "2")]
24 pub term: u64,
25 #[prost(oneof = "append_entries_response::Result", tags = "3, 4, 5")]
26 pub result: ::core::option::Option<append_entries_response::Result>,
27}
28pub mod append_entries_response {
30 #[derive(serde::Serialize, serde::Deserialize)]
31 #[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
32 pub enum Result {
33 #[prost(message, tag = "3")]
34 Success(super::SuccessResult),
35 #[prost(message, tag = "4")]
36 Conflict(super::ConflictResult),
37 #[prost(uint64, tag = "5")]
38 HigherTerm(u64),
39 }
40}
41#[derive(serde::Serialize, serde::Deserialize)]
42#[derive(Clone, Copy, PartialEq, ::prost::Message)]
43pub struct SuccessResult {
44 #[prost(message, optional, tag = "1")]
45 pub last_match: ::core::option::Option<super::common::LogId>,
46}
47#[derive(serde::Serialize, serde::Deserialize)]
48#[derive(Clone, Copy, PartialEq, ::prost::Message)]
49pub struct ConflictResult {
50 #[prost(uint64, optional, tag = "1")]
51 pub conflict_term: ::core::option::Option<u64>,
52 #[prost(uint64, optional, tag = "2")]
53 pub conflict_index: ::core::option::Option<u64>,
54}
55pub mod raft_replication_service_client {
57 #![allow(
58 unused_variables,
59 dead_code,
60 missing_docs,
61 clippy::wildcard_imports,
62 clippy::let_unit_value,
63 )]
64 use tonic::codegen::*;
65 use tonic::codegen::http::Uri;
66 #[derive(Debug, Clone)]
67 pub struct RaftReplicationServiceClient<T> {
68 inner: tonic::client::Grpc<T>,
69 }
70 impl RaftReplicationServiceClient<tonic::transport::Channel> {
71 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
73 where
74 D: TryInto<tonic::transport::Endpoint>,
75 D::Error: Into<StdError>,
76 {
77 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
78 Ok(Self::new(conn))
79 }
80 }
81 impl<T> RaftReplicationServiceClient<T>
82 where
83 T: tonic::client::GrpcService<tonic::body::BoxBody>,
84 T::Error: Into<StdError>,
85 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
86 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
87 {
88 pub fn new(inner: T) -> Self {
89 let inner = tonic::client::Grpc::new(inner);
90 Self { inner }
91 }
92 pub fn with_origin(inner: T, origin: Uri) -> Self {
93 let inner = tonic::client::Grpc::with_origin(inner, origin);
94 Self { inner }
95 }
96 pub fn with_interceptor<F>(
97 inner: T,
98 interceptor: F,
99 ) -> RaftReplicationServiceClient<InterceptedService<T, F>>
100 where
101 F: tonic::service::Interceptor,
102 T::ResponseBody: Default,
103 T: tonic::codegen::Service<
104 http::Request<tonic::body::BoxBody>,
105 Response = http::Response<
106 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
107 >,
108 >,
109 <T as tonic::codegen::Service<
110 http::Request<tonic::body::BoxBody>,
111 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
112 {
113 RaftReplicationServiceClient::new(
114 InterceptedService::new(inner, interceptor),
115 )
116 }
117 #[must_use]
122 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
123 self.inner = self.inner.send_compressed(encoding);
124 self
125 }
126 #[must_use]
128 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
129 self.inner = self.inner.accept_compressed(encoding);
130 self
131 }
132 #[must_use]
136 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
137 self.inner = self.inner.max_decoding_message_size(limit);
138 self
139 }
140 #[must_use]
144 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
145 self.inner = self.inner.max_encoding_message_size(limit);
146 self
147 }
148 pub async fn append_entries(
149 &mut self,
150 request: impl tonic::IntoRequest<super::AppendEntriesRequest>,
151 ) -> std::result::Result<
152 tonic::Response<super::AppendEntriesResponse>,
153 tonic::Status,
154 > {
155 self.inner
156 .ready()
157 .await
158 .map_err(|e| {
159 tonic::Status::unknown(
160 format!("Service was not ready: {}", e.into()),
161 )
162 })?;
163 let codec = tonic::codec::ProstCodec::default();
164 let path = http::uri::PathAndQuery::from_static(
165 "/raft.replication.RaftReplicationService/AppendEntries",
166 );
167 let mut req = request.into_request();
168 req.extensions_mut()
169 .insert(
170 GrpcMethod::new(
171 "raft.replication.RaftReplicationService",
172 "AppendEntries",
173 ),
174 );
175 self.inner.unary(req, path, codec).await
176 }
177 }
178}
179pub mod raft_replication_service_server {
181 #![allow(
182 unused_variables,
183 dead_code,
184 missing_docs,
185 clippy::wildcard_imports,
186 clippy::let_unit_value,
187 )]
188 use tonic::codegen::*;
189 #[async_trait]
191 pub trait RaftReplicationService: std::marker::Send + std::marker::Sync + 'static {
192 async fn append_entries(
193 &self,
194 request: tonic::Request<super::AppendEntriesRequest>,
195 ) -> std::result::Result<
196 tonic::Response<super::AppendEntriesResponse>,
197 tonic::Status,
198 >;
199 }
200 #[derive(Debug)]
201 pub struct RaftReplicationServiceServer<T> {
202 inner: Arc<T>,
203 accept_compression_encodings: EnabledCompressionEncodings,
204 send_compression_encodings: EnabledCompressionEncodings,
205 max_decoding_message_size: Option<usize>,
206 max_encoding_message_size: Option<usize>,
207 }
208 impl<T> RaftReplicationServiceServer<T> {
209 pub fn new(inner: T) -> Self {
210 Self::from_arc(Arc::new(inner))
211 }
212 pub fn from_arc(inner: Arc<T>) -> Self {
213 Self {
214 inner,
215 accept_compression_encodings: Default::default(),
216 send_compression_encodings: Default::default(),
217 max_decoding_message_size: None,
218 max_encoding_message_size: None,
219 }
220 }
221 pub fn with_interceptor<F>(
222 inner: T,
223 interceptor: F,
224 ) -> InterceptedService<Self, F>
225 where
226 F: tonic::service::Interceptor,
227 {
228 InterceptedService::new(Self::new(inner), interceptor)
229 }
230 #[must_use]
232 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
233 self.accept_compression_encodings.enable(encoding);
234 self
235 }
236 #[must_use]
238 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
239 self.send_compression_encodings.enable(encoding);
240 self
241 }
242 #[must_use]
246 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
247 self.max_decoding_message_size = Some(limit);
248 self
249 }
250 #[must_use]
254 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
255 self.max_encoding_message_size = Some(limit);
256 self
257 }
258 }
259 impl<T, B> tonic::codegen::Service<http::Request<B>>
260 for RaftReplicationServiceServer<T>
261 where
262 T: RaftReplicationService,
263 B: Body + std::marker::Send + 'static,
264 B::Error: Into<StdError> + std::marker::Send + 'static,
265 {
266 type Response = http::Response<tonic::body::BoxBody>;
267 type Error = std::convert::Infallible;
268 type Future = BoxFuture<Self::Response, Self::Error>;
269 fn poll_ready(
270 &mut self,
271 _cx: &mut Context<'_>,
272 ) -> Poll<std::result::Result<(), Self::Error>> {
273 Poll::Ready(Ok(()))
274 }
275 fn call(&mut self, req: http::Request<B>) -> Self::Future {
276 match req.uri().path() {
277 "/raft.replication.RaftReplicationService/AppendEntries" => {
278 #[allow(non_camel_case_types)]
279 struct AppendEntriesSvc<T: RaftReplicationService>(pub Arc<T>);
280 impl<
281 T: RaftReplicationService,
282 > tonic::server::UnaryService<super::AppendEntriesRequest>
283 for AppendEntriesSvc<T> {
284 type Response = super::AppendEntriesResponse;
285 type Future = BoxFuture<
286 tonic::Response<Self::Response>,
287 tonic::Status,
288 >;
289 fn call(
290 &mut self,
291 request: tonic::Request<super::AppendEntriesRequest>,
292 ) -> Self::Future {
293 let inner = Arc::clone(&self.0);
294 let fut = async move {
295 <T as RaftReplicationService>::append_entries(
296 &inner,
297 request,
298 )
299 .await
300 };
301 Box::pin(fut)
302 }
303 }
304 let accept_compression_encodings = self.accept_compression_encodings;
305 let send_compression_encodings = self.send_compression_encodings;
306 let max_decoding_message_size = self.max_decoding_message_size;
307 let max_encoding_message_size = self.max_encoding_message_size;
308 let inner = self.inner.clone();
309 let fut = async move {
310 let method = AppendEntriesSvc(inner);
311 let codec = tonic::codec::ProstCodec::default();
312 let mut grpc = tonic::server::Grpc::new(codec)
313 .apply_compression_config(
314 accept_compression_encodings,
315 send_compression_encodings,
316 )
317 .apply_max_message_size_config(
318 max_decoding_message_size,
319 max_encoding_message_size,
320 );
321 let res = grpc.unary(method, req).await;
322 Ok(res)
323 };
324 Box::pin(fut)
325 }
326 _ => {
327 Box::pin(async move {
328 let mut response = http::Response::new(empty_body());
329 let headers = response.headers_mut();
330 headers
331 .insert(
332 tonic::Status::GRPC_STATUS,
333 (tonic::Code::Unimplemented as i32).into(),
334 );
335 headers
336 .insert(
337 http::header::CONTENT_TYPE,
338 tonic::metadata::GRPC_CONTENT_TYPE,
339 );
340 Ok(response)
341 })
342 }
343 }
344 }
345 }
346 impl<T> Clone for RaftReplicationServiceServer<T> {
347 fn clone(&self) -> Self {
348 let inner = self.inner.clone();
349 Self {
350 inner,
351 accept_compression_encodings: self.accept_compression_encodings,
352 send_compression_encodings: self.send_compression_encodings,
353 max_decoding_message_size: self.max_decoding_message_size,
354 max_encoding_message_size: self.max_encoding_message_size,
355 }
356 }
357 }
358 pub const SERVICE_NAME: &str = "raft.replication.RaftReplicationService";
360 impl<T> tonic::server::NamedService for RaftReplicationServiceServer<T> {
361 const NAME: &'static str = SERVICE_NAME;
362 }
363}