mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-05-29 10:43:26 +00:00
Add storage server proto definition (#1426)
This commit is contained in:
committed by
GitHub
parent
093882cf00
commit
4c60f36232
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -3449,6 +3449,16 @@ dependencies = [
|
||||
"uncased",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsql-storage"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"prost",
|
||||
"prost-build",
|
||||
"tonic 0.10.2",
|
||||
"tonic-build 0.10.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsql-sys"
|
||||
version = "0.5.0"
|
||||
@ -3535,7 +3545,7 @@ dependencies = [
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"tonic 0.11.0",
|
||||
"tonic-build",
|
||||
"tonic-build 0.11.0",
|
||||
"tracing",
|
||||
"uuid",
|
||||
"zerocopy",
|
||||
@ -5717,7 +5727,10 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project",
|
||||
"prost",
|
||||
"rustls 0.21.12",
|
||||
"rustls-pemfile 1.0.4",
|
||||
"tokio",
|
||||
"tokio-rustls 0.24.1",
|
||||
"tokio-stream",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
@ -5757,6 +5770,19 @@ dependencies = [
|
||||
"webpki-roots 0.26.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tonic-build"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d021fc044c18582b9a2408cd0dd05b1596e3ecdb5c4df822bb0183545683889"
|
||||
dependencies = [
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"prost-build",
|
||||
"quote",
|
||||
"syn 2.0.66",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tonic-build"
|
||||
version = "0.11.0"
|
||||
|
@ -17,6 +17,7 @@ members = [
|
||||
|
||||
"xtask", "libsql-hrana",
|
||||
"libsql-wal",
|
||||
"libsql-storage",
|
||||
]
|
||||
|
||||
exclude = [
|
||||
|
15
libsql-storage/Cargo.toml
Normal file
15
libsql-storage/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "libsql-storage"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
description = "libSQL WAL"
|
||||
repository = "https://github.com/tursodatabase/libsql"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
prost = "0.12"
|
||||
tonic = { version = "0.10", features = ["tls"] }
|
||||
|
||||
[dev-dependencies]
|
||||
prost-build = "0.12"
|
||||
tonic-build = "0.10"
|
78
libsql-storage/proto/storage.proto
Normal file
78
libsql-storage/proto/storage.proto
Normal file
@ -0,0 +1,78 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package storage;
|
||||
|
||||
message Frame {
|
||||
uint64 page_no = 1;
|
||||
bytes data = 2;
|
||||
}
|
||||
|
||||
message InsertFramesRequest {
|
||||
string namespace = 1;
|
||||
repeated Frame frames = 2;
|
||||
uint64 max_frame_no = 3;
|
||||
}
|
||||
|
||||
message InsertFramesResponse {
|
||||
uint32 num_frames = 1;
|
||||
}
|
||||
|
||||
message FindFrameRequest {
|
||||
string namespace = 1;
|
||||
uint64 page_no = 2;
|
||||
uint64 max_frame_no = 3;
|
||||
}
|
||||
|
||||
message FindFrameResponse {
|
||||
optional uint64 frame_no = 1;
|
||||
}
|
||||
|
||||
message ReadFrameRequest {
|
||||
string namespace = 1;
|
||||
uint64 frame_no = 2;
|
||||
}
|
||||
|
||||
message ReadFrameResponse {
|
||||
optional bytes frame = 1;
|
||||
}
|
||||
|
||||
message DbSizeRequest {
|
||||
string namespace = 1;
|
||||
}
|
||||
|
||||
message DbSizeResponse {
|
||||
uint64 size = 1;
|
||||
}
|
||||
|
||||
message FramesInWALRequest {
|
||||
string namespace = 1;
|
||||
}
|
||||
|
||||
message FramesInWALResponse {
|
||||
uint64 count = 1;
|
||||
}
|
||||
|
||||
message FramePageNumRequest {
|
||||
string namespace = 1;
|
||||
uint64 frame_no = 2;
|
||||
}
|
||||
|
||||
message FramePageNumResponse {
|
||||
uint64 page_no = 1;
|
||||
}
|
||||
|
||||
message DestroyRequest {
|
||||
string namespace = 1;
|
||||
}
|
||||
|
||||
message DestroyResponse {}
|
||||
|
||||
service Storage {
|
||||
rpc InsertFrames(InsertFramesRequest) returns (InsertFramesResponse) {}
|
||||
rpc FindFrame(FindFrameRequest) returns (FindFrameResponse) {}
|
||||
rpc ReadFrame(ReadFrameRequest) returns (ReadFrameResponse) {}
|
||||
rpc DbSize(DbSizeRequest) returns (DbSizeResponse) {}
|
||||
rpc FramesInWAL(FramesInWALRequest) returns (FramesInWALResponse) {}
|
||||
rpc FramePageNum(FramePageNumRequest) returns (FramePageNumResponse) {}
|
||||
rpc Destroy(DestroyRequest) returns (DestroyResponse) {}
|
||||
}
|
838
libsql-storage/src/generated/storage.rs
Normal file
838
libsql-storage/src/generated/storage.rs
Normal file
@ -0,0 +1,838 @@
|
||||
// This file is @generated by prost-build.
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct Frame {
|
||||
#[prost(uint64, tag = "1")]
|
||||
pub page_no: u64,
|
||||
#[prost(bytes = "vec", tag = "2")]
|
||||
pub data: ::prost::alloc::vec::Vec<u8>,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct InsertFramesRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
#[prost(message, repeated, tag = "2")]
|
||||
pub frames: ::prost::alloc::vec::Vec<Frame>,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub max_frame_no: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct InsertFramesResponse {
|
||||
#[prost(uint32, tag = "1")]
|
||||
pub num_frames: u32,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FindFrameRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
#[prost(uint64, tag = "2")]
|
||||
pub page_no: u64,
|
||||
#[prost(uint64, tag = "3")]
|
||||
pub max_frame_no: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FindFrameResponse {
|
||||
#[prost(uint64, optional, tag = "1")]
|
||||
pub frame_no: ::core::option::Option<u64>,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ReadFrameRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
#[prost(uint64, tag = "2")]
|
||||
pub frame_no: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ReadFrameResponse {
|
||||
#[prost(bytes = "vec", optional, tag = "1")]
|
||||
pub frame: ::core::option::Option<::prost::alloc::vec::Vec<u8>>,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DbSizeRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DbSizeResponse {
|
||||
#[prost(uint64, tag = "1")]
|
||||
pub size: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FramesInWalRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FramesInWalResponse {
|
||||
#[prost(uint64, tag = "1")]
|
||||
pub count: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FramePageNumRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
#[prost(uint64, tag = "2")]
|
||||
pub frame_no: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FramePageNumResponse {
|
||||
#[prost(uint64, tag = "1")]
|
||||
pub page_no: u64,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DestroyRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub namespace: ::prost::alloc::string::String,
|
||||
}
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DestroyResponse {}
|
||||
/// Generated client implementations.
|
||||
pub mod storage_client {
|
||||
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
|
||||
use tonic::codegen::*;
|
||||
use tonic::codegen::http::Uri;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StorageClient<T> {
|
||||
inner: tonic::client::Grpc<T>,
|
||||
}
|
||||
impl StorageClient<tonic::transport::Channel> {
|
||||
/// Attempt to create a new client by connecting to a given endpoint.
|
||||
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
||||
where
|
||||
D: TryInto<tonic::transport::Endpoint>,
|
||||
D::Error: Into<StdError>,
|
||||
{
|
||||
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
|
||||
Ok(Self::new(conn))
|
||||
}
|
||||
}
|
||||
impl<T> StorageClient<T>
|
||||
where
|
||||
T: tonic::client::GrpcService<tonic::body::BoxBody>,
|
||||
T::Error: Into<StdError>,
|
||||
T::ResponseBody: Body<Data = Bytes> + Send + 'static,
|
||||
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
|
||||
{
|
||||
pub fn new(inner: T) -> Self {
|
||||
let inner = tonic::client::Grpc::new(inner);
|
||||
Self { inner }
|
||||
}
|
||||
pub fn with_origin(inner: T, origin: Uri) -> Self {
|
||||
let inner = tonic::client::Grpc::with_origin(inner, origin);
|
||||
Self { inner }
|
||||
}
|
||||
pub fn with_interceptor<F>(
|
||||
inner: T,
|
||||
interceptor: F,
|
||||
) -> StorageClient<InterceptedService<T, F>>
|
||||
where
|
||||
F: tonic::service::Interceptor,
|
||||
T::ResponseBody: Default,
|
||||
T: tonic::codegen::Service<
|
||||
http::Request<tonic::body::BoxBody>,
|
||||
Response = http::Response<
|
||||
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
|
||||
>,
|
||||
>,
|
||||
<T as tonic::codegen::Service<
|
||||
http::Request<tonic::body::BoxBody>,
|
||||
>>::Error: Into<StdError> + Send + Sync,
|
||||
{
|
||||
StorageClient::new(InterceptedService::new(inner, interceptor))
|
||||
}
|
||||
/// Compress requests with the given encoding.
|
||||
///
|
||||
/// This requires the server to support it otherwise it might respond with an
|
||||
/// error.
|
||||
#[must_use]
|
||||
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.inner = self.inner.send_compressed(encoding);
|
||||
self
|
||||
}
|
||||
/// Enable decompressing responses.
|
||||
#[must_use]
|
||||
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.inner = self.inner.accept_compressed(encoding);
|
||||
self
|
||||
}
|
||||
/// Limits the maximum size of a decoded message.
|
||||
///
|
||||
/// Default: `4MB`
|
||||
#[must_use]
|
||||
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||
self.inner = self.inner.max_decoding_message_size(limit);
|
||||
self
|
||||
}
|
||||
/// Limits the maximum size of an encoded message.
|
||||
///
|
||||
/// Default: `usize::MAX`
|
||||
#[must_use]
|
||||
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||
self.inner = self.inner.max_encoding_message_size(limit);
|
||||
self
|
||||
}
|
||||
pub async fn insert_frames(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::InsertFramesRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::InsertFramesResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/storage.Storage/InsertFrames",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(GrpcMethod::new("storage.Storage", "InsertFrames"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn find_frame(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::FindFrameRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FindFrameResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/storage.Storage/FindFrame",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut().insert(GrpcMethod::new("storage.Storage", "FindFrame"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn read_frame(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::ReadFrameRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ReadFrameResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/storage.Storage/ReadFrame",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut().insert(GrpcMethod::new("storage.Storage", "ReadFrame"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn db_size(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::DbSizeRequest>,
|
||||
) -> std::result::Result<tonic::Response<super::DbSizeResponse>, tonic::Status> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static("/storage.Storage/DbSize");
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut().insert(GrpcMethod::new("storage.Storage", "DbSize"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn frames_in_wal(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::FramesInWalRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FramesInWalResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/storage.Storage/FramesInWAL",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(GrpcMethod::new("storage.Storage", "FramesInWAL"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn frame_page_num(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::FramePageNumRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FramePageNumResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/storage.Storage/FramePageNum",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(GrpcMethod::new("storage.Storage", "FramePageNum"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn destroy(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::DestroyRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::DestroyResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::new(
|
||||
tonic::Code::Unknown,
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static("/storage.Storage/Destroy");
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut().insert(GrpcMethod::new("storage.Storage", "Destroy"));
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Generated server implementations.
|
||||
pub mod storage_server {
|
||||
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
|
||||
use tonic::codegen::*;
|
||||
/// Generated trait containing gRPC methods that should be implemented for use with StorageServer.
|
||||
#[async_trait]
|
||||
pub trait Storage: Send + Sync + 'static {
|
||||
async fn insert_frames(
|
||||
&self,
|
||||
request: tonic::Request<super::InsertFramesRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::InsertFramesResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn find_frame(
|
||||
&self,
|
||||
request: tonic::Request<super::FindFrameRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FindFrameResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn read_frame(
|
||||
&self,
|
||||
request: tonic::Request<super::ReadFrameRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ReadFrameResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn db_size(
|
||||
&self,
|
||||
request: tonic::Request<super::DbSizeRequest>,
|
||||
) -> std::result::Result<tonic::Response<super::DbSizeResponse>, tonic::Status>;
|
||||
async fn frames_in_wal(
|
||||
&self,
|
||||
request: tonic::Request<super::FramesInWalRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FramesInWalResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn frame_page_num(
|
||||
&self,
|
||||
request: tonic::Request<super::FramePageNumRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::FramePageNumResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn destroy(
|
||||
&self,
|
||||
request: tonic::Request<super::DestroyRequest>,
|
||||
) -> std::result::Result<tonic::Response<super::DestroyResponse>, tonic::Status>;
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct StorageServer<T: Storage> {
|
||||
inner: _Inner<T>,
|
||||
accept_compression_encodings: EnabledCompressionEncodings,
|
||||
send_compression_encodings: EnabledCompressionEncodings,
|
||||
max_decoding_message_size: Option<usize>,
|
||||
max_encoding_message_size: Option<usize>,
|
||||
}
|
||||
struct _Inner<T>(Arc<T>);
|
||||
impl<T: Storage> StorageServer<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self::from_arc(Arc::new(inner))
|
||||
}
|
||||
pub fn from_arc(inner: Arc<T>) -> Self {
|
||||
let inner = _Inner(inner);
|
||||
Self {
|
||||
inner,
|
||||
accept_compression_encodings: Default::default(),
|
||||
send_compression_encodings: Default::default(),
|
||||
max_decoding_message_size: None,
|
||||
max_encoding_message_size: None,
|
||||
}
|
||||
}
|
||||
pub fn with_interceptor<F>(
|
||||
inner: T,
|
||||
interceptor: F,
|
||||
) -> InterceptedService<Self, F>
|
||||
where
|
||||
F: tonic::service::Interceptor,
|
||||
{
|
||||
InterceptedService::new(Self::new(inner), interceptor)
|
||||
}
|
||||
/// Enable decompressing requests with the given encoding.
|
||||
#[must_use]
|
||||
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.accept_compression_encodings.enable(encoding);
|
||||
self
|
||||
}
|
||||
/// Compress responses with the given encoding, if the client supports it.
|
||||
#[must_use]
|
||||
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||
self.send_compression_encodings.enable(encoding);
|
||||
self
|
||||
}
|
||||
/// Limits the maximum size of a decoded message.
|
||||
///
|
||||
/// Default: `4MB`
|
||||
#[must_use]
|
||||
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||
self.max_decoding_message_size = Some(limit);
|
||||
self
|
||||
}
|
||||
/// Limits the maximum size of an encoded message.
|
||||
///
|
||||
/// Default: `usize::MAX`
|
||||
#[must_use]
|
||||
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||
self.max_encoding_message_size = Some(limit);
|
||||
self
|
||||
}
|
||||
}
|
||||
impl<T, B> tonic::codegen::Service<http::Request<B>> for StorageServer<T>
|
||||
where
|
||||
T: Storage,
|
||||
B: Body + Send + 'static,
|
||||
B::Error: Into<StdError> + Send + 'static,
|
||||
{
|
||||
type Response = http::Response<tonic::body::BoxBody>;
|
||||
type Error = std::convert::Infallible;
|
||||
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||
fn poll_ready(
|
||||
&mut self,
|
||||
_cx: &mut Context<'_>,
|
||||
) -> Poll<std::result::Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||
let inner = self.inner.clone();
|
||||
match req.uri().path() {
|
||||
"/storage.Storage/InsertFrames" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct InsertFramesSvc<T: Storage>(pub Arc<T>);
|
||||
impl<
|
||||
T: Storage,
|
||||
> tonic::server::UnaryService<super::InsertFramesRequest>
|
||||
for InsertFramesSvc<T> {
|
||||
type Response = super::InsertFramesResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::InsertFramesRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::insert_frames(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = InsertFramesSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/FindFrame" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct FindFrameSvc<T: Storage>(pub Arc<T>);
|
||||
impl<T: Storage> tonic::server::UnaryService<super::FindFrameRequest>
|
||||
for FindFrameSvc<T> {
|
||||
type Response = super::FindFrameResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::FindFrameRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::find_frame(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = FindFrameSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/ReadFrame" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct ReadFrameSvc<T: Storage>(pub Arc<T>);
|
||||
impl<T: Storage> tonic::server::UnaryService<super::ReadFrameRequest>
|
||||
for ReadFrameSvc<T> {
|
||||
type Response = super::ReadFrameResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::ReadFrameRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::read_frame(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = ReadFrameSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/DbSize" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct DbSizeSvc<T: Storage>(pub Arc<T>);
|
||||
impl<T: Storage> tonic::server::UnaryService<super::DbSizeRequest>
|
||||
for DbSizeSvc<T> {
|
||||
type Response = super::DbSizeResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::DbSizeRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::db_size(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = DbSizeSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/FramesInWAL" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct FramesInWALSvc<T: Storage>(pub Arc<T>);
|
||||
impl<
|
||||
T: Storage,
|
||||
> tonic::server::UnaryService<super::FramesInWalRequest>
|
||||
for FramesInWALSvc<T> {
|
||||
type Response = super::FramesInWalResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::FramesInWalRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::frames_in_wal(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = FramesInWALSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/FramePageNum" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct FramePageNumSvc<T: Storage>(pub Arc<T>);
|
||||
impl<
|
||||
T: Storage,
|
||||
> tonic::server::UnaryService<super::FramePageNumRequest>
|
||||
for FramePageNumSvc<T> {
|
||||
type Response = super::FramePageNumResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::FramePageNumRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::frame_page_num(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = FramePageNumSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/storage.Storage/Destroy" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct DestroySvc<T: Storage>(pub Arc<T>);
|
||||
impl<T: Storage> tonic::server::UnaryService<super::DestroyRequest>
|
||||
for DestroySvc<T> {
|
||||
type Response = super::DestroyResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::DestroyRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as Storage>::destroy(&inner, request).await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let inner = inner.0;
|
||||
let method = DestroySvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
_ => {
|
||||
Box::pin(async move {
|
||||
Ok(
|
||||
http::Response::builder()
|
||||
.status(200)
|
||||
.header("grpc-status", "12")
|
||||
.header("content-type", "application/grpc")
|
||||
.body(empty_body())
|
||||
.unwrap(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Storage> Clone for StorageServer<T> {
|
||||
fn clone(&self) -> Self {
|
||||
let inner = self.inner.clone();
|
||||
Self {
|
||||
inner,
|
||||
accept_compression_encodings: self.accept_compression_encodings,
|
||||
send_compression_encodings: self.send_compression_encodings,
|
||||
max_decoding_message_size: self.max_decoding_message_size,
|
||||
max_encoding_message_size: self.max_encoding_message_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Storage> Clone for _Inner<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(Arc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self.0)
|
||||
}
|
||||
}
|
||||
impl<T: Storage> tonic::server::NamedService for StorageServer<T> {
|
||||
const NAME: &'static str = "storage.Storage";
|
||||
}
|
||||
}
|
4
libsql-storage/src/lib.rs
Normal file
4
libsql-storage/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub mod rpc {
|
||||
#![allow(clippy::all)]
|
||||
include!("generated/storage.rs");
|
||||
}
|
33
libsql-storage/tests/bootstrap.rs
Normal file
33
libsql-storage/tests/bootstrap.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use std::{path::PathBuf, process::Command};
|
||||
|
||||
#[test]
|
||||
fn bootstrap() {
|
||||
let iface_files = &["proto/storage.proto"];
|
||||
let dirs = &["storage"];
|
||||
|
||||
let out_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
|
||||
.join("src")
|
||||
.join("generated");
|
||||
|
||||
let mut config = prost_build::Config::new();
|
||||
config.bytes([".wal_log"]);
|
||||
|
||||
tonic_build::configure()
|
||||
.build_client(true)
|
||||
.build_server(true)
|
||||
.build_transport(true)
|
||||
.out_dir(&out_dir)
|
||||
.type_attribute(".proxy", "#[derive(serde::Serialize, serde::Deserialize)]")
|
||||
.compile_with_config(config, iface_files, dirs)
|
||||
.unwrap();
|
||||
|
||||
let status = Command::new("git")
|
||||
.arg("diff")
|
||||
.arg("--exit-code")
|
||||
.arg("--")
|
||||
.arg(&out_dir)
|
||||
.status()
|
||||
.unwrap();
|
||||
|
||||
assert!(status.success(), "You should commit the protobuf files");
|
||||
}
|
Reference in New Issue
Block a user