Skip to main content

d_engine_proto/generated/
d_engine.server.storage.rs

1// This file is @generated by prost-build.
2#[derive(serde::Serialize, serde::Deserialize)]
3#[derive(Clone, PartialEq, ::prost::Message)]
4pub struct SnapshotChunk {
5    /// Leader's current term (for leadership validation)
6    #[prost(uint64, tag = "1")]
7    pub leader_term: u64,
8    /// Leader's node ID (for identification)
9    #[prost(uint32, tag = "2")]
10    pub leader_id: u32,
11    /// Chunk sequence number (0-based)
12    #[prost(uint32, tag = "3")]
13    pub seq: u32,
14    /// Total number of chunks in this snapshot
15    #[prost(uint32, tag = "4")]
16    pub total_chunks: u32,
17    /// Chunk-specific checksum (CRC32)
18    #[prost(bytes = "bytes", tag = "5")]
19    pub chunk_checksum: ::prost::bytes::Bytes,
20    /// Snapshot metadata (only present in first chunk)
21    #[prost(message, optional, tag = "6")]
22    pub metadata: ::core::option::Option<SnapshotMetadata>,
23    /// Payload data (recommended 4MB chunks)
24    #[prost(bytes = "bytes", tag = "7")]
25    pub data: ::prost::bytes::Bytes,
26}
27#[derive(serde::Serialize, serde::Deserialize)]
28#[derive(Clone, PartialEq, ::prost::Message)]
29pub struct SnapshotMetadata {
30    /// The last log index included in the snapshot
31    #[prost(message, optional, tag = "1")]
32    pub last_included: ::core::option::Option<super::super::common::LogId>,
33    /// SHA-256 checksum// Total number of chunks in this snapshot
34    #[prost(bytes = "bytes", tag = "2")]
35    pub checksum: ::prost::bytes::Bytes,
36}
37#[derive(serde::Serialize, serde::Deserialize)]
38#[derive(Clone, Copy, PartialEq, ::prost::Message)]
39pub struct SnapshotResponse {
40    /// Peer's current term (for Leader degradation detection)
41    #[prost(uint64, tag = "1")]
42    pub term: u64,
43    /// Whether the reception is successful
44    #[prost(bool, tag = "2")]
45    pub success: bool,
46    /// If failed, specify the chunk index to be retransmitted
47    #[prost(uint32, tag = "3")]
48    pub next_chunk: u32,
49}
50#[derive(serde::Serialize, serde::Deserialize)]
51#[derive(Clone, Copy, PartialEq, ::prost::Message)]
52pub struct SnapshotAck {
53    /// Received chunk sequence number
54    #[prost(uint32, tag = "1")]
55    pub seq: u32,
56    /// Status of this chunk
57    #[prost(enumeration = "snapshot_ack::ChunkStatus", tag = "2")]
58    pub status: i32,
59    /// Next requested chunk (for flow control)
60    #[prost(uint32, tag = "3")]
61    pub next_requested: u32,
62}
63/// Nested message and enum types in `SnapshotAck`.
64pub mod snapshot_ack {
65    #[derive(serde::Serialize, serde::Deserialize)]
66    #[derive(
67        Clone,
68        Copy,
69        Debug,
70        PartialEq,
71        Eq,
72        Hash,
73        PartialOrd,
74        Ord,
75        ::prost::Enumeration
76    )]
77    #[repr(i32)]
78    pub enum ChunkStatus {
79        Accepted = 0,
80        ChecksumMismatch = 1,
81        OutOfOrder = 2,
82        Requested = 3,
83        Failed = 4,
84    }
85    impl ChunkStatus {
86        /// String value of the enum field names used in the ProtoBuf definition.
87        ///
88        /// The values are not transformed in any way and thus are considered stable
89        /// (if the ProtoBuf definition does not change) and safe for programmatic use.
90        pub fn as_str_name(&self) -> &'static str {
91            match self {
92                Self::Accepted => "ACCEPTED",
93                Self::ChecksumMismatch => "CHECKSUM_MISMATCH",
94                Self::OutOfOrder => "OUT_OF_ORDER",
95                Self::Requested => "REQUESTED",
96                Self::Failed => "FAILED",
97            }
98        }
99        /// Creates an enum from field names used in the ProtoBuf definition.
100        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
101            match value {
102                "ACCEPTED" => Some(Self::Accepted),
103                "CHECKSUM_MISMATCH" => Some(Self::ChecksumMismatch),
104                "OUT_OF_ORDER" => Some(Self::OutOfOrder),
105                "REQUESTED" => Some(Self::Requested),
106                "FAILED" => Some(Self::Failed),
107                _ => None,
108            }
109        }
110    }
111}
112/// Generated client implementations.
113pub mod snapshot_service_client {
114    #![allow(
115        unused_variables,
116        dead_code,
117        missing_docs,
118        clippy::wildcard_imports,
119        clippy::let_unit_value,
120    )]
121    use tonic::codegen::*;
122    use tonic::codegen::http::Uri;
123    #[derive(Debug, Clone)]
124    pub struct SnapshotServiceClient<T> {
125        inner: tonic::client::Grpc<T>,
126    }
127    impl SnapshotServiceClient<tonic::transport::Channel> {
128        /// Attempt to create a new client by connecting to a given endpoint.
129        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
130        where
131            D: TryInto<tonic::transport::Endpoint>,
132            D::Error: Into<StdError>,
133        {
134            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
135            Ok(Self::new(conn))
136        }
137    }
138    impl<T> SnapshotServiceClient<T>
139    where
140        T: tonic::client::GrpcService<tonic::body::BoxBody>,
141        T::Error: Into<StdError>,
142        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
143        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
144    {
145        pub fn new(inner: T) -> Self {
146            let inner = tonic::client::Grpc::new(inner);
147            Self { inner }
148        }
149        pub fn with_origin(inner: T, origin: Uri) -> Self {
150            let inner = tonic::client::Grpc::with_origin(inner, origin);
151            Self { inner }
152        }
153        pub fn with_interceptor<F>(
154            inner: T,
155            interceptor: F,
156        ) -> SnapshotServiceClient<InterceptedService<T, F>>
157        where
158            F: tonic::service::Interceptor,
159            T::ResponseBody: Default,
160            T: tonic::codegen::Service<
161                http::Request<tonic::body::BoxBody>,
162                Response = http::Response<
163                    <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
164                >,
165            >,
166            <T as tonic::codegen::Service<
167                http::Request<tonic::body::BoxBody>,
168            >>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
169        {
170            SnapshotServiceClient::new(InterceptedService::new(inner, interceptor))
171        }
172        /// Compress requests with the given encoding.
173        ///
174        /// This requires the server to support it otherwise it might respond with an
175        /// error.
176        #[must_use]
177        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
178            self.inner = self.inner.send_compressed(encoding);
179            self
180        }
181        /// Enable decompressing responses.
182        #[must_use]
183        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
184            self.inner = self.inner.accept_compressed(encoding);
185            self
186        }
187        /// Limits the maximum size of a decoded message.
188        ///
189        /// Default: `4MB`
190        #[must_use]
191        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
192            self.inner = self.inner.max_decoding_message_size(limit);
193            self
194        }
195        /// Limits the maximum size of an encoded message.
196        ///
197        /// Default: `usize::MAX`
198        #[must_use]
199        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
200            self.inner = self.inner.max_encoding_message_size(limit);
201            self
202        }
203        /// Leader-driven snapshot streaming
204        pub async fn install_snapshot(
205            &mut self,
206            request: impl tonic::IntoStreamingRequest<Message = super::SnapshotChunk>,
207        ) -> std::result::Result<
208            tonic::Response<super::SnapshotResponse>,
209            tonic::Status,
210        > {
211            self.inner
212                .ready()
213                .await
214                .map_err(|e| {
215                    tonic::Status::unknown(
216                        format!("Service was not ready: {}", e.into()),
217                    )
218                })?;
219            let codec = tonic::codec::ProstCodec::default();
220            let path = http::uri::PathAndQuery::from_static(
221                "/d_engine.server.storage.SnapshotService/InstallSnapshot",
222            );
223            let mut req = request.into_streaming_request();
224            req.extensions_mut()
225                .insert(
226                    GrpcMethod::new(
227                        "d_engine.server.storage.SnapshotService",
228                        "InstallSnapshot",
229                    ),
230                );
231            self.inner.client_streaming(req, path, codec).await
232        }
233        /// Learner-driven snapshot streaming
234        pub async fn stream_snapshot(
235            &mut self,
236            request: impl tonic::IntoStreamingRequest<Message = super::SnapshotAck>,
237        ) -> std::result::Result<
238            tonic::Response<tonic::codec::Streaming<super::SnapshotChunk>>,
239            tonic::Status,
240        > {
241            self.inner
242                .ready()
243                .await
244                .map_err(|e| {
245                    tonic::Status::unknown(
246                        format!("Service was not ready: {}", e.into()),
247                    )
248                })?;
249            let codec = tonic::codec::ProstCodec::default();
250            let path = http::uri::PathAndQuery::from_static(
251                "/d_engine.server.storage.SnapshotService/StreamSnapshot",
252            );
253            let mut req = request.into_streaming_request();
254            req.extensions_mut()
255                .insert(
256                    GrpcMethod::new(
257                        "d_engine.server.storage.SnapshotService",
258                        "StreamSnapshot",
259                    ),
260                );
261            self.inner.streaming(req, path, codec).await
262        }
263    }
264}
265/// Generated server implementations.
266pub mod snapshot_service_server {
267    #![allow(
268        unused_variables,
269        dead_code,
270        missing_docs,
271        clippy::wildcard_imports,
272        clippy::let_unit_value,
273    )]
274    use tonic::codegen::*;
275    /// Generated trait containing gRPC methods that should be implemented for use with SnapshotServiceServer.
276    #[async_trait]
277    pub trait SnapshotService: std::marker::Send + std::marker::Sync + 'static {
278        /// Leader-driven snapshot streaming
279        async fn install_snapshot(
280            &self,
281            request: tonic::Request<tonic::Streaming<super::SnapshotChunk>>,
282        ) -> std::result::Result<
283            tonic::Response<super::SnapshotResponse>,
284            tonic::Status,
285        >;
286        /// Server streaming response type for the StreamSnapshot method.
287        type StreamSnapshotStream: tonic::codegen::tokio_stream::Stream<
288                Item = std::result::Result<super::SnapshotChunk, tonic::Status>,
289            >
290            + std::marker::Send
291            + 'static;
292        /// Learner-driven snapshot streaming
293        async fn stream_snapshot(
294            &self,
295            request: tonic::Request<tonic::Streaming<super::SnapshotAck>>,
296        ) -> std::result::Result<
297            tonic::Response<Self::StreamSnapshotStream>,
298            tonic::Status,
299        >;
300    }
301    #[derive(Debug)]
302    pub struct SnapshotServiceServer<T> {
303        inner: Arc<T>,
304        accept_compression_encodings: EnabledCompressionEncodings,
305        send_compression_encodings: EnabledCompressionEncodings,
306        max_decoding_message_size: Option<usize>,
307        max_encoding_message_size: Option<usize>,
308    }
309    impl<T> SnapshotServiceServer<T> {
310        pub fn new(inner: T) -> Self {
311            Self::from_arc(Arc::new(inner))
312        }
313        pub fn from_arc(inner: Arc<T>) -> Self {
314            Self {
315                inner,
316                accept_compression_encodings: Default::default(),
317                send_compression_encodings: Default::default(),
318                max_decoding_message_size: None,
319                max_encoding_message_size: None,
320            }
321        }
322        pub fn with_interceptor<F>(
323            inner: T,
324            interceptor: F,
325        ) -> InterceptedService<Self, F>
326        where
327            F: tonic::service::Interceptor,
328        {
329            InterceptedService::new(Self::new(inner), interceptor)
330        }
331        /// Enable decompressing requests with the given encoding.
332        #[must_use]
333        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
334            self.accept_compression_encodings.enable(encoding);
335            self
336        }
337        /// Compress responses with the given encoding, if the client supports it.
338        #[must_use]
339        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
340            self.send_compression_encodings.enable(encoding);
341            self
342        }
343        /// Limits the maximum size of a decoded message.
344        ///
345        /// Default: `4MB`
346        #[must_use]
347        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
348            self.max_decoding_message_size = Some(limit);
349            self
350        }
351        /// Limits the maximum size of an encoded message.
352        ///
353        /// Default: `usize::MAX`
354        #[must_use]
355        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
356            self.max_encoding_message_size = Some(limit);
357            self
358        }
359    }
360    impl<T, B> tonic::codegen::Service<http::Request<B>> for SnapshotServiceServer<T>
361    where
362        T: SnapshotService,
363        B: Body + std::marker::Send + 'static,
364        B::Error: Into<StdError> + std::marker::Send + 'static,
365    {
366        type Response = http::Response<tonic::body::BoxBody>;
367        type Error = std::convert::Infallible;
368        type Future = BoxFuture<Self::Response, Self::Error>;
369        fn poll_ready(
370            &mut self,
371            _cx: &mut Context<'_>,
372        ) -> Poll<std::result::Result<(), Self::Error>> {
373            Poll::Ready(Ok(()))
374        }
375        fn call(&mut self, req: http::Request<B>) -> Self::Future {
376            match req.uri().path() {
377                "/d_engine.server.storage.SnapshotService/InstallSnapshot" => {
378                    #[allow(non_camel_case_types)]
379                    struct InstallSnapshotSvc<T: SnapshotService>(pub Arc<T>);
380                    impl<
381                        T: SnapshotService,
382                    > tonic::server::ClientStreamingService<super::SnapshotChunk>
383                    for InstallSnapshotSvc<T> {
384                        type Response = super::SnapshotResponse;
385                        type Future = BoxFuture<
386                            tonic::Response<Self::Response>,
387                            tonic::Status,
388                        >;
389                        fn call(
390                            &mut self,
391                            request: tonic::Request<
392                                tonic::Streaming<super::SnapshotChunk>,
393                            >,
394                        ) -> Self::Future {
395                            let inner = Arc::clone(&self.0);
396                            let fut = async move {
397                                <T as SnapshotService>::install_snapshot(&inner, request)
398                                    .await
399                            };
400                            Box::pin(fut)
401                        }
402                    }
403                    let accept_compression_encodings = self.accept_compression_encodings;
404                    let send_compression_encodings = self.send_compression_encodings;
405                    let max_decoding_message_size = self.max_decoding_message_size;
406                    let max_encoding_message_size = self.max_encoding_message_size;
407                    let inner = self.inner.clone();
408                    let fut = async move {
409                        let method = InstallSnapshotSvc(inner);
410                        let codec = tonic::codec::ProstCodec::default();
411                        let mut grpc = tonic::server::Grpc::new(codec)
412                            .apply_compression_config(
413                                accept_compression_encodings,
414                                send_compression_encodings,
415                            )
416                            .apply_max_message_size_config(
417                                max_decoding_message_size,
418                                max_encoding_message_size,
419                            );
420                        let res = grpc.client_streaming(method, req).await;
421                        Ok(res)
422                    };
423                    Box::pin(fut)
424                }
425                "/d_engine.server.storage.SnapshotService/StreamSnapshot" => {
426                    #[allow(non_camel_case_types)]
427                    struct StreamSnapshotSvc<T: SnapshotService>(pub Arc<T>);
428                    impl<
429                        T: SnapshotService,
430                    > tonic::server::StreamingService<super::SnapshotAck>
431                    for StreamSnapshotSvc<T> {
432                        type Response = super::SnapshotChunk;
433                        type ResponseStream = T::StreamSnapshotStream;
434                        type Future = BoxFuture<
435                            tonic::Response<Self::ResponseStream>,
436                            tonic::Status,
437                        >;
438                        fn call(
439                            &mut self,
440                            request: tonic::Request<tonic::Streaming<super::SnapshotAck>>,
441                        ) -> Self::Future {
442                            let inner = Arc::clone(&self.0);
443                            let fut = async move {
444                                <T as SnapshotService>::stream_snapshot(&inner, request)
445                                    .await
446                            };
447                            Box::pin(fut)
448                        }
449                    }
450                    let accept_compression_encodings = self.accept_compression_encodings;
451                    let send_compression_encodings = self.send_compression_encodings;
452                    let max_decoding_message_size = self.max_decoding_message_size;
453                    let max_encoding_message_size = self.max_encoding_message_size;
454                    let inner = self.inner.clone();
455                    let fut = async move {
456                        let method = StreamSnapshotSvc(inner);
457                        let codec = tonic::codec::ProstCodec::default();
458                        let mut grpc = tonic::server::Grpc::new(codec)
459                            .apply_compression_config(
460                                accept_compression_encodings,
461                                send_compression_encodings,
462                            )
463                            .apply_max_message_size_config(
464                                max_decoding_message_size,
465                                max_encoding_message_size,
466                            );
467                        let res = grpc.streaming(method, req).await;
468                        Ok(res)
469                    };
470                    Box::pin(fut)
471                }
472                _ => {
473                    Box::pin(async move {
474                        let mut response = http::Response::new(empty_body());
475                        let headers = response.headers_mut();
476                        headers
477                            .insert(
478                                tonic::Status::GRPC_STATUS,
479                                (tonic::Code::Unimplemented as i32).into(),
480                            );
481                        headers
482                            .insert(
483                                http::header::CONTENT_TYPE,
484                                tonic::metadata::GRPC_CONTENT_TYPE,
485                            );
486                        Ok(response)
487                    })
488                }
489            }
490        }
491    }
492    impl<T> Clone for SnapshotServiceServer<T> {
493        fn clone(&self) -> Self {
494            let inner = self.inner.clone();
495            Self {
496                inner,
497                accept_compression_encodings: self.accept_compression_encodings,
498                send_compression_encodings: self.send_compression_encodings,
499                max_decoding_message_size: self.max_decoding_message_size,
500                max_encoding_message_size: self.max_encoding_message_size,
501            }
502        }
503    }
504    /// Generated gRPC service name
505    pub const SERVICE_NAME: &str = "d_engine.server.storage.SnapshotService";
506    impl<T> tonic::server::NamedService for SnapshotServiceServer<T> {
507        const NAME: &'static str = SERVICE_NAME;
508    }
509}