1#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Clone, PartialEq, ::prost::Message)]
5pub struct WriteCommand {
6 #[prost(oneof = "write_command::Operation", tags = "1, 2")]
7 pub operation: ::core::option::Option<write_command::Operation>,
8}
9pub mod write_command {
11 #[derive(serde::Serialize, serde::Deserialize)]
12 #[derive(Clone, PartialEq, ::prost::Message)]
13 pub struct Insert {
14 #[prost(bytes = "bytes", tag = "1")]
15 pub key: ::prost::bytes::Bytes,
16 #[prost(bytes = "bytes", tag = "2")]
17 pub value: ::prost::bytes::Bytes,
18 #[prost(uint64, tag = "3")]
21 pub ttl_secs: u64,
22 }
23 #[derive(serde::Serialize, serde::Deserialize)]
24 #[derive(Clone, PartialEq, ::prost::Message)]
25 pub struct Delete {
26 #[prost(bytes = "bytes", tag = "1")]
27 pub key: ::prost::bytes::Bytes,
28 }
29 #[derive(serde::Serialize, serde::Deserialize)]
30 #[derive(Clone, PartialEq, ::prost::Oneof)]
31 pub enum Operation {
32 #[prost(message, tag = "1")]
33 Insert(Insert),
34 #[prost(message, tag = "2")]
35 Delete(Delete),
36 }
37}
38#[derive(serde::Serialize, serde::Deserialize)]
39#[derive(Clone, PartialEq, ::prost::Message)]
40pub struct ClientWriteRequest {
41 #[prost(uint32, tag = "1")]
42 pub client_id: u32,
43 #[prost(message, repeated, tag = "2")]
44 pub commands: ::prost::alloc::vec::Vec<WriteCommand>,
45}
46#[derive(serde::Serialize, serde::Deserialize)]
47#[derive(Clone, PartialEq, ::prost::Message)]
48pub struct ClientReadRequest {
49 #[prost(uint32, tag = "1")]
50 pub client_id: u32,
51 #[prost(bytes = "bytes", repeated, tag = "2")]
53 pub keys: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>,
54 #[prost(enumeration = "ReadConsistencyPolicy", optional, tag = "3")]
59 pub consistency_policy: ::core::option::Option<i32>,
60}
61#[derive(serde::Serialize, serde::Deserialize)]
62#[derive(Clone, PartialEq, ::prost::Message)]
63pub struct ClientResponse {
64 #[prost(enumeration = "super::error::ErrorCode", tag = "1")]
65 pub error: i32,
66 #[prost(message, optional, tag = "4")]
67 pub metadata: ::core::option::Option<super::error::ErrorMetadata>,
68 #[prost(oneof = "client_response::SuccessResult", tags = "2, 3")]
69 pub success_result: ::core::option::Option<client_response::SuccessResult>,
70}
71pub mod client_response {
73 #[derive(serde::Serialize, serde::Deserialize)]
74 #[derive(Clone, PartialEq, ::prost::Oneof)]
75 pub enum SuccessResult {
76 #[prost(bool, tag = "2")]
77 WriteAck(bool),
78 #[prost(message, tag = "3")]
79 ReadData(super::ReadResults),
80 }
81}
82#[derive(serde::Serialize, serde::Deserialize)]
84#[derive(Clone, PartialEq, ::prost::Message)]
85pub struct ClientResult {
86 #[prost(bytes = "bytes", tag = "1")]
87 pub key: ::prost::bytes::Bytes,
88 #[prost(bytes = "bytes", tag = "2")]
89 pub value: ::prost::bytes::Bytes,
90}
91#[derive(serde::Serialize, serde::Deserialize)]
92#[derive(Clone, PartialEq, ::prost::Message)]
93pub struct ReadResults {
94 #[prost(message, repeated, tag = "1")]
95 pub results: ::prost::alloc::vec::Vec<ClientResult>,
96}
97#[derive(serde::Serialize, serde::Deserialize)]
102#[derive(Clone, PartialEq, ::prost::Message)]
103pub struct WatchRequest {
104 #[prost(uint32, tag = "1")]
105 pub client_id: u32,
106 #[prost(bytes = "bytes", tag = "2")]
108 pub key: ::prost::bytes::Bytes,
109}
110#[derive(serde::Serialize, serde::Deserialize)]
112#[derive(Clone, PartialEq, ::prost::Message)]
113pub struct WatchResponse {
114 #[prost(bytes = "bytes", tag = "1")]
116 pub key: ::prost::bytes::Bytes,
117 #[prost(bytes = "bytes", tag = "2")]
119 pub value: ::prost::bytes::Bytes,
120 #[prost(enumeration = "WatchEventType", tag = "3")]
122 pub event_type: i32,
123 #[prost(enumeration = "super::error::ErrorCode", tag = "4")]
125 pub error: i32,
126}
127#[derive(serde::Serialize, serde::Deserialize)]
132#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
133#[repr(i32)]
134pub enum ReadConsistencyPolicy {
135 LeaseRead = 0,
140 LinearizableRead = 1,
146 EventualConsistency = 2,
153}
154impl ReadConsistencyPolicy {
155 pub fn as_str_name(&self) -> &'static str {
160 match self {
161 Self::LeaseRead => "READ_CONSISTENCY_POLICY_LEASE_READ",
162 Self::LinearizableRead => "READ_CONSISTENCY_POLICY_LINEARIZABLE_READ",
163 Self::EventualConsistency => "READ_CONSISTENCY_POLICY_EVENTUAL_CONSISTENCY",
164 }
165 }
166 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
168 match value {
169 "READ_CONSISTENCY_POLICY_LEASE_READ" => Some(Self::LeaseRead),
170 "READ_CONSISTENCY_POLICY_LINEARIZABLE_READ" => Some(Self::LinearizableRead),
171 "READ_CONSISTENCY_POLICY_EVENTUAL_CONSISTENCY" => {
172 Some(Self::EventualConsistency)
173 }
174 _ => None,
175 }
176 }
177}
178#[derive(serde::Serialize, serde::Deserialize)]
180#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
181#[repr(i32)]
182pub enum WatchEventType {
183 Put = 0,
185 Delete = 1,
187}
188impl WatchEventType {
189 pub fn as_str_name(&self) -> &'static str {
194 match self {
195 Self::Put => "WATCH_EVENT_TYPE_PUT",
196 Self::Delete => "WATCH_EVENT_TYPE_DELETE",
197 }
198 }
199 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
201 match value {
202 "WATCH_EVENT_TYPE_PUT" => Some(Self::Put),
203 "WATCH_EVENT_TYPE_DELETE" => Some(Self::Delete),
204 _ => None,
205 }
206 }
207}
208pub mod raft_client_service_client {
210 #![allow(
211 unused_variables,
212 dead_code,
213 missing_docs,
214 clippy::wildcard_imports,
215 clippy::let_unit_value,
216 )]
217 use tonic::codegen::*;
218 use tonic::codegen::http::Uri;
219 #[derive(Debug, Clone)]
220 pub struct RaftClientServiceClient<T> {
221 inner: tonic::client::Grpc<T>,
222 }
223 impl RaftClientServiceClient<tonic::transport::Channel> {
224 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
226 where
227 D: TryInto<tonic::transport::Endpoint>,
228 D::Error: Into<StdError>,
229 {
230 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
231 Ok(Self::new(conn))
232 }
233 }
234 impl<T> RaftClientServiceClient<T>
235 where
236 T: tonic::client::GrpcService<tonic::body::BoxBody>,
237 T::Error: Into<StdError>,
238 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
239 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
240 {
241 pub fn new(inner: T) -> Self {
242 let inner = tonic::client::Grpc::new(inner);
243 Self { inner }
244 }
245 pub fn with_origin(inner: T, origin: Uri) -> Self {
246 let inner = tonic::client::Grpc::with_origin(inner, origin);
247 Self { inner }
248 }
249 pub fn with_interceptor<F>(
250 inner: T,
251 interceptor: F,
252 ) -> RaftClientServiceClient<InterceptedService<T, F>>
253 where
254 F: tonic::service::Interceptor,
255 T::ResponseBody: Default,
256 T: tonic::codegen::Service<
257 http::Request<tonic::body::BoxBody>,
258 Response = http::Response<
259 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
260 >,
261 >,
262 <T as tonic::codegen::Service<
263 http::Request<tonic::body::BoxBody>,
264 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
265 {
266 RaftClientServiceClient::new(InterceptedService::new(inner, interceptor))
267 }
268 #[must_use]
273 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
274 self.inner = self.inner.send_compressed(encoding);
275 self
276 }
277 #[must_use]
279 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
280 self.inner = self.inner.accept_compressed(encoding);
281 self
282 }
283 #[must_use]
287 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
288 self.inner = self.inner.max_decoding_message_size(limit);
289 self
290 }
291 #[must_use]
295 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
296 self.inner = self.inner.max_encoding_message_size(limit);
297 self
298 }
299 pub async fn handle_client_write(
300 &mut self,
301 request: impl tonic::IntoRequest<super::ClientWriteRequest>,
302 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status> {
303 self.inner
304 .ready()
305 .await
306 .map_err(|e| {
307 tonic::Status::unknown(
308 format!("Service was not ready: {}", e.into()),
309 )
310 })?;
311 let codec = tonic::codec::ProstCodec::default();
312 let path = http::uri::PathAndQuery::from_static(
313 "/d_engine.client.RaftClientService/HandleClientWrite",
314 );
315 let mut req = request.into_request();
316 req.extensions_mut()
317 .insert(
318 GrpcMethod::new(
319 "d_engine.client.RaftClientService",
320 "HandleClientWrite",
321 ),
322 );
323 self.inner.unary(req, path, codec).await
324 }
325 pub async fn handle_client_read(
326 &mut self,
327 request: impl tonic::IntoRequest<super::ClientReadRequest>,
328 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status> {
329 self.inner
330 .ready()
331 .await
332 .map_err(|e| {
333 tonic::Status::unknown(
334 format!("Service was not ready: {}", e.into()),
335 )
336 })?;
337 let codec = tonic::codec::ProstCodec::default();
338 let path = http::uri::PathAndQuery::from_static(
339 "/d_engine.client.RaftClientService/HandleClientRead",
340 );
341 let mut req = request.into_request();
342 req.extensions_mut()
343 .insert(
344 GrpcMethod::new(
345 "d_engine.client.RaftClientService",
346 "HandleClientRead",
347 ),
348 );
349 self.inner.unary(req, path, codec).await
350 }
351 pub async fn watch(
364 &mut self,
365 request: impl tonic::IntoRequest<super::WatchRequest>,
366 ) -> std::result::Result<
367 tonic::Response<tonic::codec::Streaming<super::WatchResponse>>,
368 tonic::Status,
369 > {
370 self.inner
371 .ready()
372 .await
373 .map_err(|e| {
374 tonic::Status::unknown(
375 format!("Service was not ready: {}", e.into()),
376 )
377 })?;
378 let codec = tonic::codec::ProstCodec::default();
379 let path = http::uri::PathAndQuery::from_static(
380 "/d_engine.client.RaftClientService/Watch",
381 );
382 let mut req = request.into_request();
383 req.extensions_mut()
384 .insert(GrpcMethod::new("d_engine.client.RaftClientService", "Watch"));
385 self.inner.server_streaming(req, path, codec).await
386 }
387 }
388}
389pub mod raft_client_service_server {
391 #![allow(
392 unused_variables,
393 dead_code,
394 missing_docs,
395 clippy::wildcard_imports,
396 clippy::let_unit_value,
397 )]
398 use tonic::codegen::*;
399 #[async_trait]
401 pub trait RaftClientService: std::marker::Send + std::marker::Sync + 'static {
402 async fn handle_client_write(
403 &self,
404 request: tonic::Request<super::ClientWriteRequest>,
405 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status>;
406 async fn handle_client_read(
407 &self,
408 request: tonic::Request<super::ClientReadRequest>,
409 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status>;
410 type WatchStream: tonic::codegen::tokio_stream::Stream<
412 Item = std::result::Result<super::WatchResponse, tonic::Status>,
413 >
414 + std::marker::Send
415 + 'static;
416 async fn watch(
429 &self,
430 request: tonic::Request<super::WatchRequest>,
431 ) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
432 }
433 #[derive(Debug)]
434 pub struct RaftClientServiceServer<T> {
435 inner: Arc<T>,
436 accept_compression_encodings: EnabledCompressionEncodings,
437 send_compression_encodings: EnabledCompressionEncodings,
438 max_decoding_message_size: Option<usize>,
439 max_encoding_message_size: Option<usize>,
440 }
441 impl<T> RaftClientServiceServer<T> {
442 pub fn new(inner: T) -> Self {
443 Self::from_arc(Arc::new(inner))
444 }
445 pub fn from_arc(inner: Arc<T>) -> Self {
446 Self {
447 inner,
448 accept_compression_encodings: Default::default(),
449 send_compression_encodings: Default::default(),
450 max_decoding_message_size: None,
451 max_encoding_message_size: None,
452 }
453 }
454 pub fn with_interceptor<F>(
455 inner: T,
456 interceptor: F,
457 ) -> InterceptedService<Self, F>
458 where
459 F: tonic::service::Interceptor,
460 {
461 InterceptedService::new(Self::new(inner), interceptor)
462 }
463 #[must_use]
465 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
466 self.accept_compression_encodings.enable(encoding);
467 self
468 }
469 #[must_use]
471 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
472 self.send_compression_encodings.enable(encoding);
473 self
474 }
475 #[must_use]
479 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
480 self.max_decoding_message_size = Some(limit);
481 self
482 }
483 #[must_use]
487 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
488 self.max_encoding_message_size = Some(limit);
489 self
490 }
491 }
492 impl<T, B> tonic::codegen::Service<http::Request<B>> for RaftClientServiceServer<T>
493 where
494 T: RaftClientService,
495 B: Body + std::marker::Send + 'static,
496 B::Error: Into<StdError> + std::marker::Send + 'static,
497 {
498 type Response = http::Response<tonic::body::BoxBody>;
499 type Error = std::convert::Infallible;
500 type Future = BoxFuture<Self::Response, Self::Error>;
501 fn poll_ready(
502 &mut self,
503 _cx: &mut Context<'_>,
504 ) -> Poll<std::result::Result<(), Self::Error>> {
505 Poll::Ready(Ok(()))
506 }
507 fn call(&mut self, req: http::Request<B>) -> Self::Future {
508 match req.uri().path() {
509 "/d_engine.client.RaftClientService/HandleClientWrite" => {
510 #[allow(non_camel_case_types)]
511 struct HandleClientWriteSvc<T: RaftClientService>(pub Arc<T>);
512 impl<
513 T: RaftClientService,
514 > tonic::server::UnaryService<super::ClientWriteRequest>
515 for HandleClientWriteSvc<T> {
516 type Response = super::ClientResponse;
517 type Future = BoxFuture<
518 tonic::Response<Self::Response>,
519 tonic::Status,
520 >;
521 fn call(
522 &mut self,
523 request: tonic::Request<super::ClientWriteRequest>,
524 ) -> Self::Future {
525 let inner = Arc::clone(&self.0);
526 let fut = async move {
527 <T as RaftClientService>::handle_client_write(
528 &inner,
529 request,
530 )
531 .await
532 };
533 Box::pin(fut)
534 }
535 }
536 let accept_compression_encodings = self.accept_compression_encodings;
537 let send_compression_encodings = self.send_compression_encodings;
538 let max_decoding_message_size = self.max_decoding_message_size;
539 let max_encoding_message_size = self.max_encoding_message_size;
540 let inner = self.inner.clone();
541 let fut = async move {
542 let method = HandleClientWriteSvc(inner);
543 let codec = tonic::codec::ProstCodec::default();
544 let mut grpc = tonic::server::Grpc::new(codec)
545 .apply_compression_config(
546 accept_compression_encodings,
547 send_compression_encodings,
548 )
549 .apply_max_message_size_config(
550 max_decoding_message_size,
551 max_encoding_message_size,
552 );
553 let res = grpc.unary(method, req).await;
554 Ok(res)
555 };
556 Box::pin(fut)
557 }
558 "/d_engine.client.RaftClientService/HandleClientRead" => {
559 #[allow(non_camel_case_types)]
560 struct HandleClientReadSvc<T: RaftClientService>(pub Arc<T>);
561 impl<
562 T: RaftClientService,
563 > tonic::server::UnaryService<super::ClientReadRequest>
564 for HandleClientReadSvc<T> {
565 type Response = super::ClientResponse;
566 type Future = BoxFuture<
567 tonic::Response<Self::Response>,
568 tonic::Status,
569 >;
570 fn call(
571 &mut self,
572 request: tonic::Request<super::ClientReadRequest>,
573 ) -> Self::Future {
574 let inner = Arc::clone(&self.0);
575 let fut = async move {
576 <T as RaftClientService>::handle_client_read(
577 &inner,
578 request,
579 )
580 .await
581 };
582 Box::pin(fut)
583 }
584 }
585 let accept_compression_encodings = self.accept_compression_encodings;
586 let send_compression_encodings = self.send_compression_encodings;
587 let max_decoding_message_size = self.max_decoding_message_size;
588 let max_encoding_message_size = self.max_encoding_message_size;
589 let inner = self.inner.clone();
590 let fut = async move {
591 let method = HandleClientReadSvc(inner);
592 let codec = tonic::codec::ProstCodec::default();
593 let mut grpc = tonic::server::Grpc::new(codec)
594 .apply_compression_config(
595 accept_compression_encodings,
596 send_compression_encodings,
597 )
598 .apply_max_message_size_config(
599 max_decoding_message_size,
600 max_encoding_message_size,
601 );
602 let res = grpc.unary(method, req).await;
603 Ok(res)
604 };
605 Box::pin(fut)
606 }
607 "/d_engine.client.RaftClientService/Watch" => {
608 #[allow(non_camel_case_types)]
609 struct WatchSvc<T: RaftClientService>(pub Arc<T>);
610 impl<
611 T: RaftClientService,
612 > tonic::server::ServerStreamingService<super::WatchRequest>
613 for WatchSvc<T> {
614 type Response = super::WatchResponse;
615 type ResponseStream = T::WatchStream;
616 type Future = BoxFuture<
617 tonic::Response<Self::ResponseStream>,
618 tonic::Status,
619 >;
620 fn call(
621 &mut self,
622 request: tonic::Request<super::WatchRequest>,
623 ) -> Self::Future {
624 let inner = Arc::clone(&self.0);
625 let fut = async move {
626 <T as RaftClientService>::watch(&inner, request).await
627 };
628 Box::pin(fut)
629 }
630 }
631 let accept_compression_encodings = self.accept_compression_encodings;
632 let send_compression_encodings = self.send_compression_encodings;
633 let max_decoding_message_size = self.max_decoding_message_size;
634 let max_encoding_message_size = self.max_encoding_message_size;
635 let inner = self.inner.clone();
636 let fut = async move {
637 let method = WatchSvc(inner);
638 let codec = tonic::codec::ProstCodec::default();
639 let mut grpc = tonic::server::Grpc::new(codec)
640 .apply_compression_config(
641 accept_compression_encodings,
642 send_compression_encodings,
643 )
644 .apply_max_message_size_config(
645 max_decoding_message_size,
646 max_encoding_message_size,
647 );
648 let res = grpc.server_streaming(method, req).await;
649 Ok(res)
650 };
651 Box::pin(fut)
652 }
653 _ => {
654 Box::pin(async move {
655 let mut response = http::Response::new(empty_body());
656 let headers = response.headers_mut();
657 headers
658 .insert(
659 tonic::Status::GRPC_STATUS,
660 (tonic::Code::Unimplemented as i32).into(),
661 );
662 headers
663 .insert(
664 http::header::CONTENT_TYPE,
665 tonic::metadata::GRPC_CONTENT_TYPE,
666 );
667 Ok(response)
668 })
669 }
670 }
671 }
672 }
673 impl<T> Clone for RaftClientServiceServer<T> {
674 fn clone(&self) -> Self {
675 let inner = self.inner.clone();
676 Self {
677 inner,
678 accept_compression_encodings: self.accept_compression_encodings,
679 send_compression_encodings: self.send_compression_encodings,
680 max_decoding_message_size: self.max_decoding_message_size,
681 max_encoding_message_size: self.max_encoding_message_size,
682 }
683 }
684 }
685 pub const SERVICE_NAME: &str = "d_engine.client.RaftClientService";
687 impl<T> tonic::server::NamedService for RaftClientServiceServer<T> {
688 const NAME: &'static str = SERVICE_NAME;
689 }
690}