1#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Clone, PartialEq, ::prost::Message)]
5pub struct WriteCommand {
6 #[prost(oneof = "write_command::Operation", tags = "1, 2, 3")]
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::Message)]
31 pub struct CompareAndSwap {
32 #[prost(bytes = "bytes", tag = "1")]
33 pub key: ::prost::bytes::Bytes,
34 #[prost(bytes = "bytes", optional, tag = "2")]
36 pub expected_value: ::core::option::Option<::prost::bytes::Bytes>,
37 #[prost(bytes = "bytes", tag = "3")]
39 pub new_value: ::prost::bytes::Bytes,
40 }
41 #[derive(serde::Serialize, serde::Deserialize)]
42 #[derive(Clone, PartialEq, ::prost::Oneof)]
43 pub enum Operation {
44 #[prost(message, tag = "1")]
45 Insert(Insert),
46 #[prost(message, tag = "2")]
47 Delete(Delete),
48 #[prost(message, tag = "3")]
49 CompareAndSwap(CompareAndSwap),
50 }
51}
52#[derive(serde::Serialize, serde::Deserialize)]
53#[derive(Clone, PartialEq, ::prost::Message)]
54pub struct ClientWriteRequest {
55 #[prost(uint32, tag = "1")]
56 pub client_id: u32,
57 #[prost(message, optional, tag = "2")]
59 pub command: ::core::option::Option<WriteCommand>,
60}
61#[derive(serde::Serialize, serde::Deserialize)]
62#[derive(Clone, PartialEq, ::prost::Message)]
63pub struct ClientReadRequest {
64 #[prost(uint32, tag = "1")]
65 pub client_id: u32,
66 #[prost(bytes = "bytes", repeated, tag = "2")]
68 pub keys: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>,
69 #[prost(enumeration = "ReadConsistencyPolicy", optional, tag = "3")]
74 pub consistency_policy: ::core::option::Option<i32>,
75}
76#[derive(serde::Serialize, serde::Deserialize)]
78#[derive(Clone, Copy, PartialEq, ::prost::Message)]
79pub struct WriteResult {
80 #[prost(bool, tag = "1")]
83 pub succeeded: bool,
84}
85#[derive(serde::Serialize, serde::Deserialize)]
86#[derive(Clone, PartialEq, ::prost::Message)]
87pub struct ClientResponse {
88 #[prost(enumeration = "super::error::ErrorCode", tag = "1")]
89 pub error: i32,
90 #[prost(message, optional, tag = "4")]
91 pub metadata: ::core::option::Option<super::error::ErrorMetadata>,
92 #[prost(oneof = "client_response::SuccessResult", tags = "2, 3")]
93 pub success_result: ::core::option::Option<client_response::SuccessResult>,
94}
95pub mod client_response {
97 #[derive(serde::Serialize, serde::Deserialize)]
98 #[derive(Clone, PartialEq, ::prost::Oneof)]
99 pub enum SuccessResult {
100 #[prost(message, tag = "2")]
101 WriteResult(super::WriteResult),
102 #[prost(message, tag = "3")]
103 ReadData(super::ReadResults),
104 }
105}
106#[derive(serde::Serialize, serde::Deserialize)]
108#[derive(Clone, PartialEq, ::prost::Message)]
109pub struct ClientResult {
110 #[prost(bytes = "bytes", tag = "1")]
111 pub key: ::prost::bytes::Bytes,
112 #[prost(bytes = "bytes", tag = "2")]
113 pub value: ::prost::bytes::Bytes,
114}
115#[derive(serde::Serialize, serde::Deserialize)]
116#[derive(Clone, PartialEq, ::prost::Message)]
117pub struct ReadResults {
118 #[prost(message, repeated, tag = "1")]
119 pub results: ::prost::alloc::vec::Vec<ClientResult>,
120}
121#[derive(serde::Serialize, serde::Deserialize)]
126#[derive(Clone, PartialEq, ::prost::Message)]
127pub struct WatchRequest {
128 #[prost(uint32, tag = "1")]
129 pub client_id: u32,
130 #[prost(bytes = "bytes", tag = "2")]
132 pub key: ::prost::bytes::Bytes,
133}
134#[derive(serde::Serialize, serde::Deserialize)]
136#[derive(Clone, PartialEq, ::prost::Message)]
137pub struct WatchResponse {
138 #[prost(bytes = "bytes", tag = "1")]
140 pub key: ::prost::bytes::Bytes,
141 #[prost(bytes = "bytes", tag = "2")]
143 pub value: ::prost::bytes::Bytes,
144 #[prost(enumeration = "WatchEventType", tag = "3")]
146 pub event_type: i32,
147 #[prost(enumeration = "super::error::ErrorCode", tag = "4")]
149 pub error: i32,
150}
151#[derive(serde::Serialize, serde::Deserialize)]
156#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
157#[repr(i32)]
158pub enum ReadConsistencyPolicy {
159 LeaseRead = 0,
164 LinearizableRead = 1,
170 EventualConsistency = 2,
177}
178impl ReadConsistencyPolicy {
179 pub fn as_str_name(&self) -> &'static str {
184 match self {
185 Self::LeaseRead => "READ_CONSISTENCY_POLICY_LEASE_READ",
186 Self::LinearizableRead => "READ_CONSISTENCY_POLICY_LINEARIZABLE_READ",
187 Self::EventualConsistency => "READ_CONSISTENCY_POLICY_EVENTUAL_CONSISTENCY",
188 }
189 }
190 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
192 match value {
193 "READ_CONSISTENCY_POLICY_LEASE_READ" => Some(Self::LeaseRead),
194 "READ_CONSISTENCY_POLICY_LINEARIZABLE_READ" => Some(Self::LinearizableRead),
195 "READ_CONSISTENCY_POLICY_EVENTUAL_CONSISTENCY" => {
196 Some(Self::EventualConsistency)
197 }
198 _ => None,
199 }
200 }
201}
202#[derive(serde::Serialize, serde::Deserialize)]
204#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
205#[repr(i32)]
206pub enum WatchEventType {
207 Put = 0,
209 Delete = 1,
211}
212impl WatchEventType {
213 pub fn as_str_name(&self) -> &'static str {
218 match self {
219 Self::Put => "WATCH_EVENT_TYPE_PUT",
220 Self::Delete => "WATCH_EVENT_TYPE_DELETE",
221 }
222 }
223 pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
225 match value {
226 "WATCH_EVENT_TYPE_PUT" => Some(Self::Put),
227 "WATCH_EVENT_TYPE_DELETE" => Some(Self::Delete),
228 _ => None,
229 }
230 }
231}
232pub mod raft_client_service_client {
234 #![allow(
235 unused_variables,
236 dead_code,
237 missing_docs,
238 clippy::wildcard_imports,
239 clippy::let_unit_value,
240 )]
241 use tonic::codegen::*;
242 use tonic::codegen::http::Uri;
243 #[derive(Debug, Clone)]
244 pub struct RaftClientServiceClient<T> {
245 inner: tonic::client::Grpc<T>,
246 }
247 impl RaftClientServiceClient<tonic::transport::Channel> {
248 pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
250 where
251 D: TryInto<tonic::transport::Endpoint>,
252 D::Error: Into<StdError>,
253 {
254 let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
255 Ok(Self::new(conn))
256 }
257 }
258 impl<T> RaftClientServiceClient<T>
259 where
260 T: tonic::client::GrpcService<tonic::body::BoxBody>,
261 T::Error: Into<StdError>,
262 T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
263 <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
264 {
265 pub fn new(inner: T) -> Self {
266 let inner = tonic::client::Grpc::new(inner);
267 Self { inner }
268 }
269 pub fn with_origin(inner: T, origin: Uri) -> Self {
270 let inner = tonic::client::Grpc::with_origin(inner, origin);
271 Self { inner }
272 }
273 pub fn with_interceptor<F>(
274 inner: T,
275 interceptor: F,
276 ) -> RaftClientServiceClient<InterceptedService<T, F>>
277 where
278 F: tonic::service::Interceptor,
279 T::ResponseBody: Default,
280 T: tonic::codegen::Service<
281 http::Request<tonic::body::BoxBody>,
282 Response = http::Response<
283 <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
284 >,
285 >,
286 <T as tonic::codegen::Service<
287 http::Request<tonic::body::BoxBody>,
288 >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
289 {
290 RaftClientServiceClient::new(InterceptedService::new(inner, interceptor))
291 }
292 #[must_use]
297 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
298 self.inner = self.inner.send_compressed(encoding);
299 self
300 }
301 #[must_use]
303 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
304 self.inner = self.inner.accept_compressed(encoding);
305 self
306 }
307 #[must_use]
311 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
312 self.inner = self.inner.max_decoding_message_size(limit);
313 self
314 }
315 #[must_use]
319 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
320 self.inner = self.inner.max_encoding_message_size(limit);
321 self
322 }
323 pub async fn handle_client_write(
324 &mut self,
325 request: impl tonic::IntoRequest<super::ClientWriteRequest>,
326 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status> {
327 self.inner
328 .ready()
329 .await
330 .map_err(|e| {
331 tonic::Status::unknown(
332 format!("Service was not ready: {}", e.into()),
333 )
334 })?;
335 let codec = tonic::codec::ProstCodec::default();
336 let path = http::uri::PathAndQuery::from_static(
337 "/d_engine.client.RaftClientService/HandleClientWrite",
338 );
339 let mut req = request.into_request();
340 req.extensions_mut()
341 .insert(
342 GrpcMethod::new(
343 "d_engine.client.RaftClientService",
344 "HandleClientWrite",
345 ),
346 );
347 self.inner.unary(req, path, codec).await
348 }
349 pub async fn handle_client_read(
350 &mut self,
351 request: impl tonic::IntoRequest<super::ClientReadRequest>,
352 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status> {
353 self.inner
354 .ready()
355 .await
356 .map_err(|e| {
357 tonic::Status::unknown(
358 format!("Service was not ready: {}", e.into()),
359 )
360 })?;
361 let codec = tonic::codec::ProstCodec::default();
362 let path = http::uri::PathAndQuery::from_static(
363 "/d_engine.client.RaftClientService/HandleClientRead",
364 );
365 let mut req = request.into_request();
366 req.extensions_mut()
367 .insert(
368 GrpcMethod::new(
369 "d_engine.client.RaftClientService",
370 "HandleClientRead",
371 ),
372 );
373 self.inner.unary(req, path, codec).await
374 }
375 pub async fn watch(
388 &mut self,
389 request: impl tonic::IntoRequest<super::WatchRequest>,
390 ) -> std::result::Result<
391 tonic::Response<tonic::codec::Streaming<super::WatchResponse>>,
392 tonic::Status,
393 > {
394 self.inner
395 .ready()
396 .await
397 .map_err(|e| {
398 tonic::Status::unknown(
399 format!("Service was not ready: {}", e.into()),
400 )
401 })?;
402 let codec = tonic::codec::ProstCodec::default();
403 let path = http::uri::PathAndQuery::from_static(
404 "/d_engine.client.RaftClientService/Watch",
405 );
406 let mut req = request.into_request();
407 req.extensions_mut()
408 .insert(GrpcMethod::new("d_engine.client.RaftClientService", "Watch"));
409 self.inner.server_streaming(req, path, codec).await
410 }
411 }
412}
413pub mod raft_client_service_server {
415 #![allow(
416 unused_variables,
417 dead_code,
418 missing_docs,
419 clippy::wildcard_imports,
420 clippy::let_unit_value,
421 )]
422 use tonic::codegen::*;
423 #[async_trait]
425 pub trait RaftClientService: std::marker::Send + std::marker::Sync + 'static {
426 async fn handle_client_write(
427 &self,
428 request: tonic::Request<super::ClientWriteRequest>,
429 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status>;
430 async fn handle_client_read(
431 &self,
432 request: tonic::Request<super::ClientReadRequest>,
433 ) -> std::result::Result<tonic::Response<super::ClientResponse>, tonic::Status>;
434 type WatchStream: tonic::codegen::tokio_stream::Stream<
436 Item = std::result::Result<super::WatchResponse, tonic::Status>,
437 >
438 + std::marker::Send
439 + 'static;
440 async fn watch(
453 &self,
454 request: tonic::Request<super::WatchRequest>,
455 ) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
456 }
457 #[derive(Debug)]
458 pub struct RaftClientServiceServer<T> {
459 inner: Arc<T>,
460 accept_compression_encodings: EnabledCompressionEncodings,
461 send_compression_encodings: EnabledCompressionEncodings,
462 max_decoding_message_size: Option<usize>,
463 max_encoding_message_size: Option<usize>,
464 }
465 impl<T> RaftClientServiceServer<T> {
466 pub fn new(inner: T) -> Self {
467 Self::from_arc(Arc::new(inner))
468 }
469 pub fn from_arc(inner: Arc<T>) -> Self {
470 Self {
471 inner,
472 accept_compression_encodings: Default::default(),
473 send_compression_encodings: Default::default(),
474 max_decoding_message_size: None,
475 max_encoding_message_size: None,
476 }
477 }
478 pub fn with_interceptor<F>(
479 inner: T,
480 interceptor: F,
481 ) -> InterceptedService<Self, F>
482 where
483 F: tonic::service::Interceptor,
484 {
485 InterceptedService::new(Self::new(inner), interceptor)
486 }
487 #[must_use]
489 pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
490 self.accept_compression_encodings.enable(encoding);
491 self
492 }
493 #[must_use]
495 pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
496 self.send_compression_encodings.enable(encoding);
497 self
498 }
499 #[must_use]
503 pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
504 self.max_decoding_message_size = Some(limit);
505 self
506 }
507 #[must_use]
511 pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
512 self.max_encoding_message_size = Some(limit);
513 self
514 }
515 }
516 impl<T, B> tonic::codegen::Service<http::Request<B>> for RaftClientServiceServer<T>
517 where
518 T: RaftClientService,
519 B: Body + std::marker::Send + 'static,
520 B::Error: Into<StdError> + std::marker::Send + 'static,
521 {
522 type Response = http::Response<tonic::body::BoxBody>;
523 type Error = std::convert::Infallible;
524 type Future = BoxFuture<Self::Response, Self::Error>;
525 fn poll_ready(
526 &mut self,
527 _cx: &mut Context<'_>,
528 ) -> Poll<std::result::Result<(), Self::Error>> {
529 Poll::Ready(Ok(()))
530 }
531 fn call(&mut self, req: http::Request<B>) -> Self::Future {
532 match req.uri().path() {
533 "/d_engine.client.RaftClientService/HandleClientWrite" => {
534 #[allow(non_camel_case_types)]
535 struct HandleClientWriteSvc<T: RaftClientService>(pub Arc<T>);
536 impl<
537 T: RaftClientService,
538 > tonic::server::UnaryService<super::ClientWriteRequest>
539 for HandleClientWriteSvc<T> {
540 type Response = super::ClientResponse;
541 type Future = BoxFuture<
542 tonic::Response<Self::Response>,
543 tonic::Status,
544 >;
545 fn call(
546 &mut self,
547 request: tonic::Request<super::ClientWriteRequest>,
548 ) -> Self::Future {
549 let inner = Arc::clone(&self.0);
550 let fut = async move {
551 <T as RaftClientService>::handle_client_write(
552 &inner,
553 request,
554 )
555 .await
556 };
557 Box::pin(fut)
558 }
559 }
560 let accept_compression_encodings = self.accept_compression_encodings;
561 let send_compression_encodings = self.send_compression_encodings;
562 let max_decoding_message_size = self.max_decoding_message_size;
563 let max_encoding_message_size = self.max_encoding_message_size;
564 let inner = self.inner.clone();
565 let fut = async move {
566 let method = HandleClientWriteSvc(inner);
567 let codec = tonic::codec::ProstCodec::default();
568 let mut grpc = tonic::server::Grpc::new(codec)
569 .apply_compression_config(
570 accept_compression_encodings,
571 send_compression_encodings,
572 )
573 .apply_max_message_size_config(
574 max_decoding_message_size,
575 max_encoding_message_size,
576 );
577 let res = grpc.unary(method, req).await;
578 Ok(res)
579 };
580 Box::pin(fut)
581 }
582 "/d_engine.client.RaftClientService/HandleClientRead" => {
583 #[allow(non_camel_case_types)]
584 struct HandleClientReadSvc<T: RaftClientService>(pub Arc<T>);
585 impl<
586 T: RaftClientService,
587 > tonic::server::UnaryService<super::ClientReadRequest>
588 for HandleClientReadSvc<T> {
589 type Response = super::ClientResponse;
590 type Future = BoxFuture<
591 tonic::Response<Self::Response>,
592 tonic::Status,
593 >;
594 fn call(
595 &mut self,
596 request: tonic::Request<super::ClientReadRequest>,
597 ) -> Self::Future {
598 let inner = Arc::clone(&self.0);
599 let fut = async move {
600 <T as RaftClientService>::handle_client_read(
601 &inner,
602 request,
603 )
604 .await
605 };
606 Box::pin(fut)
607 }
608 }
609 let accept_compression_encodings = self.accept_compression_encodings;
610 let send_compression_encodings = self.send_compression_encodings;
611 let max_decoding_message_size = self.max_decoding_message_size;
612 let max_encoding_message_size = self.max_encoding_message_size;
613 let inner = self.inner.clone();
614 let fut = async move {
615 let method = HandleClientReadSvc(inner);
616 let codec = tonic::codec::ProstCodec::default();
617 let mut grpc = tonic::server::Grpc::new(codec)
618 .apply_compression_config(
619 accept_compression_encodings,
620 send_compression_encodings,
621 )
622 .apply_max_message_size_config(
623 max_decoding_message_size,
624 max_encoding_message_size,
625 );
626 let res = grpc.unary(method, req).await;
627 Ok(res)
628 };
629 Box::pin(fut)
630 }
631 "/d_engine.client.RaftClientService/Watch" => {
632 #[allow(non_camel_case_types)]
633 struct WatchSvc<T: RaftClientService>(pub Arc<T>);
634 impl<
635 T: RaftClientService,
636 > tonic::server::ServerStreamingService<super::WatchRequest>
637 for WatchSvc<T> {
638 type Response = super::WatchResponse;
639 type ResponseStream = T::WatchStream;
640 type Future = BoxFuture<
641 tonic::Response<Self::ResponseStream>,
642 tonic::Status,
643 >;
644 fn call(
645 &mut self,
646 request: tonic::Request<super::WatchRequest>,
647 ) -> Self::Future {
648 let inner = Arc::clone(&self.0);
649 let fut = async move {
650 <T as RaftClientService>::watch(&inner, request).await
651 };
652 Box::pin(fut)
653 }
654 }
655 let accept_compression_encodings = self.accept_compression_encodings;
656 let send_compression_encodings = self.send_compression_encodings;
657 let max_decoding_message_size = self.max_decoding_message_size;
658 let max_encoding_message_size = self.max_encoding_message_size;
659 let inner = self.inner.clone();
660 let fut = async move {
661 let method = WatchSvc(inner);
662 let codec = tonic::codec::ProstCodec::default();
663 let mut grpc = tonic::server::Grpc::new(codec)
664 .apply_compression_config(
665 accept_compression_encodings,
666 send_compression_encodings,
667 )
668 .apply_max_message_size_config(
669 max_decoding_message_size,
670 max_encoding_message_size,
671 );
672 let res = grpc.server_streaming(method, req).await;
673 Ok(res)
674 };
675 Box::pin(fut)
676 }
677 _ => {
678 Box::pin(async move {
679 let mut response = http::Response::new(empty_body());
680 let headers = response.headers_mut();
681 headers
682 .insert(
683 tonic::Status::GRPC_STATUS,
684 (tonic::Code::Unimplemented as i32).into(),
685 );
686 headers
687 .insert(
688 http::header::CONTENT_TYPE,
689 tonic::metadata::GRPC_CONTENT_TYPE,
690 );
691 Ok(response)
692 })
693 }
694 }
695 }
696 }
697 impl<T> Clone for RaftClientServiceServer<T> {
698 fn clone(&self) -> Self {
699 let inner = self.inner.clone();
700 Self {
701 inner,
702 accept_compression_encodings: self.accept_compression_encodings,
703 send_compression_encodings: self.send_compression_encodings,
704 max_decoding_message_size: self.max_decoding_message_size,
705 max_encoding_message_size: self.max_encoding_message_size,
706 }
707 }
708 }
709 pub const SERVICE_NAME: &str = "d_engine.client.RaftClientService";
711 impl<T> tonic::server::NamedService for RaftClientServiceServer<T> {
712 const NAME: &'static str = SERVICE_NAME;
713 }
714}