feat: prepare for crates.io publishing (#312)

* feat: prepare  for crates.io publishing

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix: exclude typos check

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix: add header for each file

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
This commit is contained in:
jeremyhi
2026-04-07 20:12:39 -07:00
committed by GitHub
parent 092ba1d01e
commit 32d60146e5
24 changed files with 9971 additions and 114 deletions
+4 -11
View File
@@ -30,9 +30,6 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: "1.24.3"
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
@@ -40,7 +37,10 @@ jobs:
uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check --workspace --all-targets
- name: Generate protbuf
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate protobuf
run: |
make all
- name: Check protobuf generation
@@ -68,9 +68,6 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
@@ -87,9 +84,6 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
@@ -98,4 +92,3 @@ jobs:
uses: Swatinem/rust-cache@v2
- name: Run cargo clippy
run: cargo clippy --workspace --all-targets -- -D warnings -D clippy::print_stdout -D clippy::print_stderr
+1
View File
@@ -1,6 +1,7 @@
[files]
extend-exclude = [
# Exclude all generated files
"src/generated/**",
"**/greptime/v1/**",
"java/**",
"go/**",
+16 -3
View File
@@ -2,7 +2,23 @@
name = "greptime-proto"
version = "0.1.0"
edition = "2021"
description = "Rust protobuf bindings for GreptimeDB APIs."
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/GreptimeTeam/greptime-proto"
documentation = "https://docs.rs/greptime-proto"
keywords = ["greptime", "greptimedb", "grpc", "protobuf", "proto"]
categories = ["api-bindings"]
include = [
"/Cargo.toml",
"/LICENSE",
"/README.md",
"/proto/**",
"/src/**",
]
[workspace]
members = ["xtask"]
[dependencies]
prost = "0.14"
@@ -13,6 +29,3 @@ strum = "0.25"
strum_macros = "0.25"
tonic = "0.14"
tonic-prost = "0.14"
[build-dependencies]
tonic-prost-build = "0.14"
+1 -1
View File
@@ -5,7 +5,7 @@ BUILDER_CONTAINER=namely/protoc-all:1.51_2
all: rust go java cpp
rust:
cargo build
cargo run --manifest-path xtask/Cargo.toml -- generate-rust
go: go-deps
docker run --rm -t -w /greptime-proto \
+13 -7
View File
@@ -1,16 +1,17 @@
# greptime-proto
GreptimeDB protobuf files.
GreptimeDB protobuf definitions and pre-generated Rust bindings.
## Build
### Requirement
- [google/protobuf][protobuf] v3
- Rust consumers do not need `protoc`.
- Maintainers need [google/protobuf][protobuf] v3 to regenerate Rust bindings after `.proto` changes.
### Command
- **Compile for Rust**
- **Generate Rust bindings**
```console
make rust
@@ -34,12 +35,11 @@ GreptimeDB protobuf files.
### Rust
```Toml
# Add this repository as dependency to your Cargo.toml file:
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git" }
```toml
greptime-proto = "0.1"
```
```Rust
```rust
// To use the GreptimeDB's gRPC service:
use greptime_proto::v1::*;
@@ -50,6 +50,12 @@ use greptime_proto::v1::meta::*;
use greptime_proto::prometheus::remote::*;
```
When working in this repository, regenerate the checked-in Rust bindings after `.proto` changes with:
```console
cargo run --manifest-path xtask/Cargo.toml -- generate-rust
```
### Go
Download the go module:
-82
View File
@@ -1,82 +0,0 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(
std::env::var("OUT_DIR")
.expect("cargo built-in env value 'OUT_DIR' must be set during compilation"),
);
tonic_prost_build::configure()
.file_descriptor_set_path(out_dir.join("greptime_grpc_desc.bin"))
.type_attribute(
".greptime.v1.SemanticType",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.Peer",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.HeartbeatRequest.node_workloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.DatanodeWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.FrontendWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.FlownodeWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.enum_attribute(
"region.RegionRequest.body",
"#[derive(strum_macros::AsRefStr)]",
)
.bytes(".greptime.v1.ArrowIpc")
.compile_protos(
&[
"proto/greptime/v1/database.proto",
"proto/greptime/v1/health.proto",
"proto/greptime/v1/wal.proto",
"proto/greptime/v1/meta/common.proto",
"proto/greptime/v1/meta/heartbeat.proto",
"proto/greptime/v1/meta/config.proto",
"proto/greptime/v1/meta/route.proto",
"proto/greptime/v1/meta/ddl.proto",
"proto/greptime/v1/meta/region.proto",
"proto/greptime/v1/meta/store.proto",
"proto/greptime/v1/meta/lock.proto",
"proto/greptime/v1/meta/cluster.proto",
"proto/greptime/v1/meta/procedure.proto",
"proto/greptime/v1/region/server.proto",
"proto/greptime/v1/flow/server.proto",
"proto/greptime/v1/frontend/server.proto",
"proto/greptime/v1/index/bloom_filter.proto",
"proto/greptime/v1/index/inverted_index.proto",
"proto/greptime/v1/index/vector_index.proto",
"proto/prometheus/remote/remote.proto",
"proto/substrait_extension/promql_plan.proto",
"proto/substrait_extension/dist_plan.proto",
],
&["proto"],
)
.expect("compile proto");
}
+572
View File
@@ -0,0 +1,572 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DirtyWindowRequests {
/// The dirty time window requests.
/// Each request contains a table_id and a list of dirty timestamps.
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<DirtyWindowRequest>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DirtyWindowRequest {
#[prost(uint32, tag = "1")]
pub table_id: u32,
/// Dirty timestamps. Used to mark this point in time as dirty,
/// so that the flow can be triggered to process the data.
#[prost(int64, repeated, tag = "2")]
pub timestamps: ::prost::alloc::vec::Vec<i64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FlowRequestHeader {
/// Encoded trace_id & span_id, follow the w3c Trace Context
/// <https://www.w3.org/TR/trace-context/#header-name>
#[prost(map = "string, string", tag = "1")]
pub tracing_context: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
/// The contextual information of the query
#[prost(message, optional, tag = "2")]
pub query_context: ::core::option::Option<super::QueryContext>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InsertRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<InsertRequest>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InsertRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(message, optional, tag = "2")]
pub rows: ::core::option::Option<super::Rows>,
#[prost(message, optional, tag = "3")]
pub partition_expr_version: ::core::option::Option<super::PartitionExprVersion>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FlowRequest {
#[prost(message, optional, tag = "64")]
pub header: ::core::option::Option<FlowRequestHeader>,
#[prost(oneof = "flow_request::Body", tags = "1, 2, 3")]
pub body: ::core::option::Option<flow_request::Body>,
}
/// Nested message and enum types in `FlowRequest`.
pub mod flow_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Body {
#[prost(message, tag = "1")]
Create(super::CreateRequest),
#[prost(message, tag = "2")]
Drop(super::DropRequest),
#[prost(message, tag = "3")]
Flush(super::FlushFlow),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FlowResponse {
#[prost(message, optional, tag = "1")]
pub header: ::core::option::Option<super::ResponseHeader>,
#[prost(uint64, tag = "2")]
pub affected_rows: u64,
/// affected flow ids
#[prost(message, repeated, tag = "3")]
pub affected_flows: ::prost::alloc::vec::Vec<super::FlowId>,
#[prost(map = "string, bytes", tag = "4")]
pub extensions: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::vec::Vec<u8>,
>,
}
/// Create a flow
///
/// Very similar to `ddl.CreateTaskExpr`,
/// replace `source_table_names` with `source_table_ids`
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CreateRequest {
#[prost(message, optional, tag = "1")]
pub flow_id: ::core::option::Option<super::FlowId>,
#[prost(message, repeated, tag = "2")]
pub source_table_ids: ::prost::alloc::vec::Vec<super::TableId>,
#[prost(message, optional, tag = "3")]
pub sink_table_name: ::core::option::Option<super::TableName>,
#[prost(bool, tag = "4")]
pub create_if_not_exists: bool,
/// Expire data older than the given duration seconds.
#[prost(message, optional, tag = "5")]
pub expire_after: ::core::option::Option<super::ExpireAfter>,
#[prost(message, optional, tag = "10")]
pub eval_interval: ::core::option::Option<super::EvalInterval>,
#[prost(string, tag = "6")]
pub comment: ::prost::alloc::string::String,
#[prost(string, tag = "7")]
pub sql: ::prost::alloc::string::String,
#[prost(map = "string, string", tag = "8")]
pub flow_options: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
/// Set to true if the flow should be created or replaced.
#[prost(bool, tag = "9")]
pub or_replace: bool,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DropRequest {
#[prost(message, optional, tag = "1")]
pub flow_id: ::core::option::Option<super::FlowId>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct FlushFlow {
#[prost(message, optional, tag = "1")]
pub flow_id: ::core::option::Option<super::FlowId>,
}
/// Generated client implementations.
pub mod flow_client {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
pub struct FlowClient<T> {
inner: tonic::client::Grpc<T>,
}
impl FlowClient<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> FlowClient<T>
where
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::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,
) -> FlowClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
FlowClient::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
}
/// Handle the control plane request for creating or removing a flow.
pub async fn handle_create_remove(
&mut self,
request: impl tonic::IntoRequest<super::FlowRequest>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.flow.Flow/HandleCreateRemove",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("greptime.v1.flow.Flow", "HandleCreateRemove"));
self.inner.unary(req, path, codec).await
}
/// Handle the data plane request for inserting or deleting rows
/// only expect `RegionRequest` to be one of `InsertRequests` or
/// `DeleteRequests` other types of `RegionRequest` will be ignored
pub async fn handle_mirror_request(
&mut self,
request: impl tonic::IntoRequest<super::InsertRequests>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.flow.Flow/HandleMirrorRequest",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("greptime.v1.flow.Flow", "HandleMirrorRequest"));
self.inner.unary(req, path, codec).await
}
pub async fn handle_mark_dirty_time_window(
&mut self,
request: impl tonic::IntoRequest<super::DirtyWindowRequests>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.flow.Flow/HandleMarkDirtyTimeWindow",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new("greptime.v1.flow.Flow", "HandleMarkDirtyTimeWindow"),
);
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
pub mod flow_server {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with FlowServer.
#[async_trait]
pub trait Flow: std::marker::Send + std::marker::Sync + 'static {
/// Handle the control plane request for creating or removing a flow.
async fn handle_create_remove(
&self,
request: tonic::Request<super::FlowRequest>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status>;
/// Handle the data plane request for inserting or deleting rows
/// only expect `RegionRequest` to be one of `InsertRequests` or
/// `DeleteRequests` other types of `RegionRequest` will be ignored
async fn handle_mirror_request(
&self,
request: tonic::Request<super::InsertRequests>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status>;
async fn handle_mark_dirty_time_window(
&self,
request: tonic::Request<super::DirtyWindowRequests>,
) -> std::result::Result<tonic::Response<super::FlowResponse>, tonic::Status>;
}
#[derive(Debug)]
pub struct FlowServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T> FlowServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
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 FlowServer<T>
where
T: Flow,
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::Body>;
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 {
match req.uri().path() {
"/greptime.v1.flow.Flow/HandleCreateRemove" => {
#[allow(non_camel_case_types)]
struct HandleCreateRemoveSvc<T: Flow>(pub Arc<T>);
impl<T: Flow> tonic::server::UnaryService<super::FlowRequest>
for HandleCreateRemoveSvc<T> {
type Response = super::FlowResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::FlowRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Flow>::handle_create_remove(&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 method = HandleCreateRemoveSvc(inner);
let codec = tonic_prost::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)
}
"/greptime.v1.flow.Flow/HandleMirrorRequest" => {
#[allow(non_camel_case_types)]
struct HandleMirrorRequestSvc<T: Flow>(pub Arc<T>);
impl<T: Flow> tonic::server::UnaryService<super::InsertRequests>
for HandleMirrorRequestSvc<T> {
type Response = super::FlowResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::InsertRequests>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Flow>::handle_mirror_request(&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 method = HandleMirrorRequestSvc(inner);
let codec = tonic_prost::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)
}
"/greptime.v1.flow.Flow/HandleMarkDirtyTimeWindow" => {
#[allow(non_camel_case_types)]
struct HandleMarkDirtyTimeWindowSvc<T: Flow>(pub Arc<T>);
impl<T: Flow> tonic::server::UnaryService<super::DirtyWindowRequests>
for HandleMarkDirtyTimeWindowSvc<T> {
type Response = super::FlowResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::DirtyWindowRequests>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Flow>::handle_mark_dirty_time_window(&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 method = HandleMarkDirtyTimeWindowSvc(inner);
let codec = tonic_prost::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 {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
impl<T> Clone for FlowServer<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,
}
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &str = "greptime.v1.flow.Flow";
impl<T> tonic::server::NamedService for FlowServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
+446
View File
@@ -0,0 +1,446 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ListProcessRequest {
#[prost(string, tag = "1")]
pub catalog: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListProcessResponse {
#[prost(message, repeated, tag = "1")]
pub processes: ::prost::alloc::vec::Vec<ProcessInfo>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct KillProcessRequest {
/// Frontend server address of process.
#[prost(string, tag = "1")]
pub server_addr: ::prost::alloc::string::String,
/// Catalog of process to kill.
#[prost(string, tag = "2")]
pub catalog: ::prost::alloc::string::String,
/// ID of process to kill.
#[prost(uint32, tag = "3")]
pub process_id: u32,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct KillProcessResponse {
/// Whether targeting process is successfully killed
#[prost(bool, tag = "1")]
pub success: bool,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ProcessInfo {
/// ID.
#[prost(uint32, tag = "1")]
pub id: u32,
/// Catalog of process.
#[prost(string, tag = "2")]
pub catalog: ::prost::alloc::string::String,
/// Involved schemas.
#[prost(string, repeated, tag = "3")]
pub schemas: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Query string.
#[prost(string, tag = "4")]
pub query: ::prost::alloc::string::String,
/// Start time.
#[prost(int64, tag = "5")]
pub start_timestamp: i64,
/// Client info.
#[prost(string, tag = "6")]
pub client: ::prost::alloc::string::String,
/// Frontend info of process.
#[prost(string, tag = "7")]
pub frontend: ::prost::alloc::string::String,
}
/// Generated client implementations.
pub mod frontend_client {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
pub struct FrontendClient<T> {
inner: tonic::client::Grpc<T>,
}
impl FrontendClient<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> FrontendClient<T>
where
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::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,
) -> FrontendClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
FrontendClient::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
}
/// List all running processes on frontend.
pub async fn list_process(
&mut self,
request: impl tonic::IntoRequest<super::ListProcessRequest>,
) -> std::result::Result<
tonic::Response<super::ListProcessResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.frontend.Frontend/ListProcess",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("greptime.v1.frontend.Frontend", "ListProcess"));
self.inner.unary(req, path, codec).await
}
/// Kill a running process on frontend.
pub async fn kill_process(
&mut self,
request: impl tonic::IntoRequest<super::KillProcessRequest>,
) -> std::result::Result<
tonic::Response<super::KillProcessResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.frontend.Frontend/KillProcess",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("greptime.v1.frontend.Frontend", "KillProcess"));
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
pub mod frontend_server {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with FrontendServer.
#[async_trait]
pub trait Frontend: std::marker::Send + std::marker::Sync + 'static {
/// List all running processes on frontend.
async fn list_process(
&self,
request: tonic::Request<super::ListProcessRequest>,
) -> std::result::Result<
tonic::Response<super::ListProcessResponse>,
tonic::Status,
>;
/// Kill a running process on frontend.
async fn kill_process(
&self,
request: tonic::Request<super::KillProcessRequest>,
) -> std::result::Result<
tonic::Response<super::KillProcessResponse>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct FrontendServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T> FrontendServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
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 FrontendServer<T>
where
T: Frontend,
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::Body>;
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 {
match req.uri().path() {
"/greptime.v1.frontend.Frontend/ListProcess" => {
#[allow(non_camel_case_types)]
struct ListProcessSvc<T: Frontend>(pub Arc<T>);
impl<
T: Frontend,
> tonic::server::UnaryService<super::ListProcessRequest>
for ListProcessSvc<T> {
type Response = super::ListProcessResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::ListProcessRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Frontend>::list_process(&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 method = ListProcessSvc(inner);
let codec = tonic_prost::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)
}
"/greptime.v1.frontend.Frontend/KillProcess" => {
#[allow(non_camel_case_types)]
struct KillProcessSvc<T: Frontend>(pub Arc<T>);
impl<
T: Frontend,
> tonic::server::UnaryService<super::KillProcessRequest>
for KillProcessSvc<T> {
type Response = super::KillProcessResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::KillProcessRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Frontend>::kill_process(&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 method = KillProcessSvc(inner);
let codec = tonic_prost::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 {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
impl<T> Clone for FrontendServer<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,
}
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &str = "greptime.v1.frontend.Frontend";
impl<T> tonic::server::NamedService for FrontendServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
+246
View File
@@ -0,0 +1,246 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
/// BloomFilterMeta defines the metadata for a bloom filter.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BloomFilterMeta {
/// The number of rows per segment.
#[prost(uint64, tag = "1")]
pub rows_per_segment: u64,
/// The number of segments.
#[prost(uint64, tag = "2")]
pub segment_count: u64,
/// The number of total rows.
#[prost(uint64, tag = "3")]
pub row_count: u64,
/// The size of the bloom filter in bytes excluding the metadata.
#[prost(uint64, tag = "4")]
pub bloom_filter_size: u64,
/// The indices to the bloom filter location of each segment.
#[prost(uint64, repeated, tag = "5")]
pub segment_loc_indices: ::prost::alloc::vec::Vec<u64>,
/// The bloom filter locations.
#[prost(message, repeated, tag = "6")]
pub bloom_filter_locs: ::prost::alloc::vec::Vec<BloomFilterLoc>,
}
/// BloomFilterLoc defines the location of a bloom filter.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct BloomFilterLoc {
/// The byte offset of the bloom filter data.
#[prost(uint64, tag = "1")]
pub offset: u64,
/// The size of the bloom filter data.
#[prost(uint64, tag = "2")]
pub size: u64,
/// The number of elements in the bloom filter.
#[prost(uint64, tag = "3")]
pub element_count: u64,
}
/// InvertedIndexMetas defines the metadata for an inverted index
/// within an inverted index blob.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvertedIndexMetas {
/// A map of tag names to their respective metadata corresponding to an individual
/// inverted index within the inverted index blob.
#[prost(map = "string, message", tag = "1")]
pub metas: ::std::collections::HashMap<
::prost::alloc::string::String,
InvertedIndexMeta,
>,
/// The total count of rows within the inverted index blob.
/// This is used to determine the number of segments within the bitmap.
#[prost(uint64, tag = "2")]
pub total_row_count: u64,
/// The number of rows per group for bitmap indexing which determines how rows are
/// batched for indexing. Each batch corresponds to a segment in the bitmap and allows
/// for efficient retrieval during queries by reducing the search space.
#[prost(uint64, tag = "3")]
pub segment_row_count: u64,
}
/// InvertedIndexMeta contains the metadata for a specific tag's inverted index.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InvertedIndexMeta {
/// Name of the tag associated with the inverted index.
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
/// The base byte offset for this tag's inverted index data within the blob.
/// Other offsets in this message are relative to this base offset.
#[prost(uint64, tag = "2")]
pub base_offset: u64,
/// The total size in bytes of this tag's inverted index data, including bitmaps,
/// FST data.
#[prost(uint64, tag = "3")]
pub inverted_index_size: u64,
/// The byte offset of the Finite State Transducer (FST) data relative to the `base_offset`.
#[prost(uint32, tag = "4")]
pub relative_fst_offset: u32,
/// The size in bytes of the FST data.
#[prost(uint32, tag = "5")]
pub fst_size: u32,
/// The byte offset relative to the `base_offset` where the null bitmap for this tag
/// starts.
#[prost(uint32, tag = "6")]
pub relative_null_bitmap_offset: u32,
/// The size in bytes of the null bitmap.
#[prost(uint32, tag = "7")]
pub null_bitmap_size: u32,
/// Statistical information about the tag's inverted index.
#[prost(message, optional, tag = "8")]
pub stats: ::core::option::Option<InvertedIndexStats>,
/// The type of bitmap used for indexing.
#[prost(enumeration = "BitmapType", tag = "9")]
pub bitmap_type: i32,
}
/// InvertedIndexStats provides statistical data on a tag's inverted index.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InvertedIndexStats {
/// The count of null entries within the tag's column.
#[prost(uint64, tag = "1")]
pub null_count: u64,
/// The number of distinct values within the tag's column.
#[prost(uint64, tag = "2")]
pub distinct_count: u64,
/// The minimum value found within the tag's column, encoded as bytes.
#[prost(bytes = "vec", tag = "3")]
pub min_value: ::prost::alloc::vec::Vec<u8>,
/// The maximum value found within the tag's column, encoded as bytes.
#[prost(bytes = "vec", tag = "4")]
pub max_value: ::prost::alloc::vec::Vec<u8>,
}
/// BitmapType defines the type of bitmap used for indexing.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum BitmapType {
BitVec = 0,
Roaring = 1,
}
impl BitmapType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::BitVec => "BitVec",
Self::Roaring => "Roaring",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"BitVec" => Some(Self::BitVec),
"Roaring" => Some(Self::Roaring),
_ => None,
}
}
}
/// Metadata for a vector index blob (stored as footer).
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct VectorIndexMeta {
/// Index engine type.
#[prost(enumeration = "VectorIndexEngine", tag = "1")]
pub engine: i32,
/// Vector dimension.
#[prost(uint32, tag = "2")]
pub dim: u32,
/// Distance metric.
#[prost(enumeration = "VectorDistanceMetric", tag = "3")]
pub metric: i32,
/// HNSW connectivity parameter.
#[prost(uint32, tag = "4")]
pub connectivity: u32,
/// HNSW expansion factor during index construction.
#[prost(uint32, tag = "5")]
pub expansion_add: u32,
/// HNSW expansion factor during search.
#[prost(uint32, tag = "6")]
pub expansion_search: u32,
/// Byte length of the null bitmap (RoaringBitmap serialized).
#[prost(uint32, tag = "7")]
pub null_bitmap_size: u32,
/// Byte length of the vector index data (engine-specific serialized format).
#[prost(uint64, tag = "8")]
pub index_size: u64,
/// Statistics about the vector index.
#[prost(message, optional, tag = "9")]
pub stats: ::core::option::Option<VectorIndexStats>,
}
/// Statistics for a vector index.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct VectorIndexStats {
/// Total number of rows in the SST.
#[prost(uint64, tag = "1")]
pub total_row_count: u64,
/// Number of rows with valid vectors (indexed).
#[prost(uint64, tag = "2")]
pub indexed_row_count: u64,
/// Number of null vectors.
#[prost(uint64, tag = "3")]
pub null_count: u64,
}
/// Vector index engine types.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum VectorIndexEngine {
Usearch = 0,
}
impl VectorIndexEngine {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Usearch => "VECTOR_INDEX_ENGINE_USEARCH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"VECTOR_INDEX_ENGINE_USEARCH" => Some(Self::Usearch),
_ => None,
}
}
}
/// Vector distance metrics.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum VectorDistanceMetric {
L2sq = 0,
Cosine = 1,
InnerProduct = 2,
}
impl VectorDistanceMetric {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::L2sq => "VECTOR_DISTANCE_METRIC_L2SQ",
Self::Cosine => "VECTOR_DISTANCE_METRIC_COSINE",
Self::InnerProduct => "VECTOR_DISTANCE_METRIC_INNER_PRODUCT",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"VECTOR_DISTANCE_METRIC_L2SQ" => Some(Self::L2sq),
"VECTOR_DISTANCE_METRIC_COSINE" => Some(Self::Cosine),
"VECTOR_DISTANCE_METRIC_INNER_PRODUCT" => Some(Self::InnerProduct),
_ => None,
}
}
}
File diff suppressed because it is too large Load Diff
+737
View File
@@ -0,0 +1,737 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RegionRequestHeader {
/// Encoded trace_id & span_id, follow the w3c Trace Context
/// <https://www.w3.org/TR/trace-context/#header-name>
#[prost(map = "string, string", tag = "5")]
pub tracing_context: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
/// DB Name of request, tracking only
#[prost(string, tag = "3")]
pub dbname: ::prost::alloc::string::String,
/// The contextual information of the query
#[prost(message, optional, tag = "6")]
pub query_context: ::core::option::Option<super::QueryContext>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RegionRequest {
#[prost(message, optional, tag = "1")]
pub header: ::core::option::Option<RegionRequestHeader>,
/// query request is handled in flight services.
#[prost(
oneof = "region_request::Body",
tags = "3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20"
)]
pub body: ::core::option::Option<region_request::Body>,
}
/// Nested message and enum types in `RegionRequest`.
pub mod region_request {
/// query request is handled in flight services.
#[derive(strum_macros::AsRefStr)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Body {
#[prost(message, tag = "3")]
Inserts(super::InsertRequests),
#[prost(message, tag = "4")]
Deletes(super::DeleteRequests),
#[prost(message, tag = "5")]
Create(super::CreateRequest),
#[prost(message, tag = "6")]
Drop(super::DropRequest),
#[prost(message, tag = "7")]
Open(super::OpenRequest),
#[prost(message, tag = "8")]
Close(super::CloseRequest),
#[prost(message, tag = "9")]
Alter(super::AlterRequest),
#[prost(message, tag = "10")]
Flush(super::FlushRequest),
#[prost(message, tag = "11")]
Compact(super::CompactRequest),
#[prost(message, tag = "12")]
Truncate(super::TruncateRequest),
#[prost(message, tag = "13")]
Creates(super::CreateRequests),
#[prost(message, tag = "14")]
Drops(super::DropRequests),
#[prost(message, tag = "15")]
Alters(super::AlterRequests),
#[prost(message, tag = "16")]
BulkInsert(super::BulkInsertRequest),
#[prost(message, tag = "17")]
Sync(super::SyncRequest),
#[prost(message, tag = "18")]
ListMetadata(super::ListMetadataRequest),
#[prost(message, tag = "19")]
BuildIndex(super::BuildIndexRequest),
#[prost(message, tag = "20")]
ApplyStagingManifest(super::ApplyStagingManifestRequest),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RegionResponse {
#[prost(message, optional, tag = "1")]
pub header: ::core::option::Option<super::ResponseHeader>,
#[prost(uint64, tag = "2")]
pub affected_rows: u64,
#[prost(map = "string, bytes", tag = "3")]
pub extensions: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::vec::Vec<u8>,
>,
/// Response for ListMetadataRequest.
/// It is a json array of region metadatas.
/// The length of the array is equal to the number of regions in the list request.
/// The element is null if the region is not found.
#[prost(bytes = "vec", tag = "4")]
pub metadata: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InsertRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<InsertRequest>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<DeleteRequest>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InsertRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(message, optional, tag = "2")]
pub rows: ::core::option::Option<super::Rows>,
#[prost(message, optional, tag = "3")]
pub partition_expr_version: ::core::option::Option<super::PartitionExprVersion>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(message, optional, tag = "2")]
pub rows: ::core::option::Option<super::Rows>,
#[prost(message, optional, tag = "3")]
pub partition_expr_version: ::core::option::Option<super::PartitionExprVersion>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryRequest {
#[prost(message, optional, tag = "1")]
pub header: ::core::option::Option<RegionRequestHeader>,
#[prost(uint64, tag = "2")]
pub region_id: u64,
/// substrait plan to query
#[prost(bytes = "vec", tag = "3")]
pub plan: ::prost::alloc::vec::Vec<u8>,
}
/// Create a batch of regions at once, usually used to create multiple logical
/// regions at once. Different engines can choose whether to support this
/// request. Metric Engine needs it.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CreateRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<CreateRequest>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CreateRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
/// Region engine name
#[prost(string, tag = "2")]
pub engine: ::prost::alloc::string::String,
/// Columns in this region.
#[prost(message, repeated, tag = "3")]
pub column_defs: ::prost::alloc::vec::Vec<RegionColumnDef>,
/// Column Id of primary keys.
#[prost(uint32, repeated, tag = "4")]
pub primary_key: ::prost::alloc::vec::Vec<u32>,
/// Region storage path
#[prost(string, tag = "5")]
pub path: ::prost::alloc::string::String,
/// Options of the created region.
#[prost(map = "string, string", tag = "6")]
pub options: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
/// Partition of the created region.
#[prost(message, optional, tag = "7")]
pub partition: ::core::option::Option<super::meta::Partition>,
}
/// Same as CreateRequests, but for dropping regions.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DropRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<DropRequest>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DropRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
/// Only used by Metric Engine, for fast path drop.
/// It only works for Metric Engine, and will be ignored by other engines.
/// If true, the Metric Engine will delete logical tables in memory, and drop the physical region eventually.
#[prost(bool, tag = "2")]
pub fast_path: bool,
/// Used only by the Metric Engine, to forcibly drop a physical region and all its associated logical regions.
#[prost(bool, tag = "3")]
pub force: bool,
/// If true, indicates that only a portion of the region is being dropped, and files may still be referenced by other regions.
/// This is used to prevent deletion of files that are still in use by other regions.
#[prost(bool, tag = "4")]
pub partial_drop: bool,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OpenRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
/// Region engine name
#[prost(string, tag = "2")]
pub engine: ::prost::alloc::string::String,
/// Region storage path
#[prost(string, tag = "3")]
pub path: ::prost::alloc::string::String,
/// Options of the opened region.
#[prost(map = "string, string", tag = "4")]
pub options: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost::alloc::string::String,
>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CloseRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AlterRequests {
#[prost(message, repeated, tag = "1")]
pub requests: ::prost::alloc::vec::Vec<AlterRequest>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AlterRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
/// The version of the schema before applying the alteration.
#[prost(uint64, tag = "4")]
pub schema_version: u64,
#[prost(
oneof = "alter_request::Kind",
tags = "2, 3, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16"
)]
pub kind: ::core::option::Option<alter_request::Kind>,
}
/// Nested message and enum types in `AlterRequest`.
pub mod alter_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Kind {
#[prost(message, tag = "2")]
AddColumns(super::AddColumns),
#[prost(message, tag = "3")]
DropColumns(super::DropColumns),
#[prost(message, tag = "5")]
ModifyColumnTypes(super::super::ModifyColumnTypes),
#[prost(message, tag = "6")]
SetTableOptions(super::super::SetTableOptions),
#[prost(message, tag = "9")]
UnsetTableOptions(super::super::UnsetTableOptions),
/// Deprecated: use set_indexes instead.
#[prost(message, tag = "10")]
SetIndex(super::super::SetIndex),
/// Deprecated: use unset_indexes instead.
#[prost(message, tag = "11")]
UnsetIndex(super::super::UnsetIndex),
#[prost(message, tag = "12")]
DropDefaults(super::super::DropDefaults),
#[prost(message, tag = "13")]
SetIndexes(super::super::SetIndexes),
#[prost(message, tag = "14")]
UnsetIndexes(super::super::UnsetIndexes),
#[prost(message, tag = "15")]
SetDefaults(super::super::SetDefaults),
#[prost(message, tag = "16")]
SyncColumns(super::SyncColumns),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SyncColumns {
#[prost(message, repeated, tag = "1")]
pub column_defs: ::prost::alloc::vec::Vec<RegionColumnDef>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AddColumns {
#[prost(message, repeated, tag = "1")]
pub add_columns: ::prost::alloc::vec::Vec<AddColumn>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DropColumns {
#[prost(message, repeated, tag = "1")]
pub drop_columns: ::prost::alloc::vec::Vec<DropColumn>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AddColumn {
#[prost(message, optional, tag = "1")]
pub column_def: ::core::option::Option<RegionColumnDef>,
#[prost(message, optional, tag = "3")]
pub location: ::core::option::Option<super::AddColumnLocation>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DropColumn {
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct FlushRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
}
/// / Regular compaction
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Regular {}
/// / Strictly-windowed compaction.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StrictWindow {
#[prost(int64, tag = "1")]
pub window_seconds: i64,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CompactRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(uint32, tag = "4")]
pub parallelism: u32,
#[prost(oneof = "compact_request::Options", tags = "2, 3")]
pub options: ::core::option::Option<compact_request::Options>,
}
/// Nested message and enum types in `CompactRequest`.
pub mod compact_request {
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Options {
#[prost(message, tag = "2")]
Regular(super::Regular),
#[prost(message, tag = "3")]
StrictWindow(super::StrictWindow),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TruncateRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(oneof = "truncate_request::Kind", tags = "2, 3")]
pub kind: ::core::option::Option<truncate_request::Kind>,
}
/// Nested message and enum types in `TruncateRequest`.
pub mod truncate_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Kind {
#[prost(message, tag = "2")]
All(super::All),
#[prost(message, tag = "3")]
TimeRanges(super::super::TimeRanges),
}
}
/// Truncate all data in region
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct All {}
/// The column definition of a region. Unlike the message `ColumnDef` in
/// `ddl.proto` which is for clients outside GreptimeDB, this `RegionColumnDef`
/// is for region requests use only. So it carries an extra field `column_id`
/// that is known internally.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RegionColumnDef {
#[prost(message, optional, tag = "1")]
pub column_def: ::core::option::Option<super::ColumnDef>,
#[prost(uint32, tag = "2")]
pub column_id: u32,
}
/// Request of bulk ingestion API.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct BulkInsertRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(message, optional, tag = "3")]
pub partition_expr_version: ::core::option::Option<super::PartitionExprVersion>,
#[prost(oneof = "bulk_insert_request::Body", tags = "2")]
pub body: ::core::option::Option<bulk_insert_request::Body>,
}
/// Nested message and enum types in `BulkInsertRequest`.
pub mod bulk_insert_request {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Body {
#[prost(message, tag = "2")]
ArrowIpc(super::super::ArrowIpc),
}
}
/// Manifest info for mito engine.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct MitoManifestInfo {
#[prost(uint64, tag = "1")]
pub data_manifest_version: u64,
}
/// Manifest info for metric engine.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct MetricManifestInfo {
#[prost(uint64, tag = "1")]
pub data_manifest_version: u64,
#[prost(uint64, tag = "2")]
pub metadata_manifest_version: u64,
}
/// Sync request for region.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SyncRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
#[prost(oneof = "sync_request::ManifestInfo", tags = "2, 3")]
pub manifest_info: ::core::option::Option<sync_request::ManifestInfo>,
}
/// Nested message and enum types in `SyncRequest`.
pub mod sync_request {
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum ManifestInfo {
#[prost(message, tag = "2")]
MitoManifestInfo(super::MitoManifestInfo),
#[prost(message, tag = "3")]
MetricManifestInfo(super::MetricManifestInfo),
}
}
/// Get region metadatas of a list of regions.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ListMetadataRequest {
#[prost(uint64, repeated, tag = "1")]
pub region_ids: ::prost::alloc::vec::Vec<u64>,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct BuildIndexRequest {
#[prost(uint64, tag = "1")]
pub region_id: u64,
}
/// The file metas of a staging manifest.
/// It is a json array of file metadatas.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct FileMetas {
#[prost(bytes = "vec", tag = "1")]
pub data: ::prost::alloc::vec::Vec<u8>,
}
/// / Apply staging manifest request.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ApplyStagingManifestRequest {
/// The target region id.
#[prost(uint64, tag = "1")]
pub region_id: u64,
/// The partition expression of the staging manifest.
#[prost(string, tag = "2")]
pub partition_expr: ::prost::alloc::string::String,
/// The region stores the staging manifest.
#[prost(uint64, tag = "3")]
pub central_region_id: u64,
/// Path to the staging manifest file.
#[prost(string, tag = "4")]
pub manifest_path: ::prost::alloc::string::String,
}
/// Generated client implementations.
pub mod region_client {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
pub struct RegionClient<T> {
inner: tonic::client::Grpc<T>,
}
impl RegionClient<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> RegionClient<T>
where
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::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,
) -> RegionClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
RegionClient::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 handle(
&mut self,
request: impl tonic::IntoRequest<super::RegionRequest>,
) -> std::result::Result<tonic::Response<super::RegionResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/greptime.v1.region.Region/Handle",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("greptime.v1.region.Region", "Handle"));
self.inner.unary(req, path, codec).await
}
}
}
/// Generated server implementations.
pub mod region_server {
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
/// Generated trait containing gRPC methods that should be implemented for use with RegionServer.
#[async_trait]
pub trait Region: std::marker::Send + std::marker::Sync + 'static {
async fn handle(
&self,
request: tonic::Request<super::RegionRequest>,
) -> std::result::Result<tonic::Response<super::RegionResponse>, tonic::Status>;
}
#[derive(Debug)]
pub struct RegionServer<T> {
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
impl<T> RegionServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
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 RegionServer<T>
where
T: Region,
B: Body + std::marker::Send + 'static,
B::Error: Into<StdError> + std::marker::Send + 'static,
{
type Response = http::Response<tonic::body::Body>;
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 {
match req.uri().path() {
"/greptime.v1.region.Region/Handle" => {
#[allow(non_camel_case_types)]
struct HandleSvc<T: Region>(pub Arc<T>);
impl<T: Region> tonic::server::UnaryService<super::RegionRequest>
for HandleSvc<T> {
type Response = super::RegionResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::RegionRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Region>::handle(&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 method = HandleSvc(inner);
let codec = tonic_prost::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 {
let mut response = http::Response::new(
tonic::body::Body::default(),
);
let headers = response.headers_mut();
headers
.insert(
tonic::Status::GRPC_STATUS,
(tonic::Code::Unimplemented as i32).into(),
);
headers
.insert(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
);
Ok(response)
})
}
}
}
}
impl<T> Clone for RegionServer<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,
}
}
}
/// Generated gRPC service name
pub const SERVICE_NAME: &str = "greptime.v1.region.Region";
impl<T> tonic::server::NamedService for RegionServer<T> {
const NAME: &'static str = SERVICE_NAME;
}
}
File diff suppressed because it is too large Load Diff
Binary file not shown.
+532
View File
@@ -0,0 +1,532 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct MetricMetadata {
/// Represents the metric type, these match the set from Prometheus.
/// Refer to github.com/prometheus/common/model/metadata.go for details.
#[prost(enumeration = "metric_metadata::MetricType", tag = "1")]
pub r#type: i32,
#[prost(string, tag = "2")]
pub metric_family_name: ::prost::alloc::string::String,
#[prost(string, tag = "4")]
pub help: ::prost::alloc::string::String,
#[prost(string, tag = "5")]
pub unit: ::prost::alloc::string::String,
}
/// Nested message and enum types in `MetricMetadata`.
pub mod metric_metadata {
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum MetricType {
Unknown = 0,
Counter = 1,
Gauge = 2,
Histogram = 3,
Gaugehistogram = 4,
Summary = 5,
Info = 6,
Stateset = 7,
}
impl MetricType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unknown => "UNKNOWN",
Self::Counter => "COUNTER",
Self::Gauge => "GAUGE",
Self::Histogram => "HISTOGRAM",
Self::Gaugehistogram => "GAUGEHISTOGRAM",
Self::Summary => "SUMMARY",
Self::Info => "INFO",
Self::Stateset => "STATESET",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"COUNTER" => Some(Self::Counter),
"GAUGE" => Some(Self::Gauge),
"HISTOGRAM" => Some(Self::Histogram),
"GAUGEHISTOGRAM" => Some(Self::Gaugehistogram),
"SUMMARY" => Some(Self::Summary),
"INFO" => Some(Self::Info),
"STATESET" => Some(Self::Stateset),
_ => None,
}
}
}
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct Sample {
#[prost(double, tag = "1")]
pub value: f64,
/// timestamp is in ms format, see model/timestamp/timestamp.go for
/// conversion from time.Time to Prometheus timestamp.
#[prost(int64, tag = "2")]
pub timestamp: i64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Exemplar {
/// Optional, can be empty.
#[prost(message, repeated, tag = "1")]
pub labels: ::prost::alloc::vec::Vec<Label>,
#[prost(double, tag = "2")]
pub value: f64,
/// timestamp is in ms format, see model/timestamp/timestamp.go for
/// conversion from time.Time to Prometheus timestamp.
#[prost(int64, tag = "3")]
pub timestamp: i64,
}
/// A native histogram, also known as a sparse histogram.
/// Original design doc:
/// <https://docs.google.com/document/d/1cLNv3aufPZb3fNfaJgdaRBZsInZKKIHo9E6HinJVbpM/edit>
/// The appendix of this design doc also explains the concept of float
/// histograms. This Histogram message can represent both, the usual
/// integer histogram as well as a float histogram.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Histogram {
/// Sum of observations in the histogram.
#[prost(double, tag = "3")]
pub sum: f64,
/// The schema defines the bucket schema. Currently, valid numbers
/// are -4 \<= n \<= 8. They are all for base-2 bucket schemas, where 1
/// is a bucket boundary in each case, and then each power of two is
/// divided into 2^n logarithmic buckets. Or in other words, each
/// bucket boundary is the previous boundary times 2^(2^-n). In the
/// future, more bucket schemas may be added using numbers \< -4 or >
/// 8.
#[prost(sint32, tag = "4")]
pub schema: i32,
/// Breadth of the zero bucket.
#[prost(double, tag = "5")]
pub zero_threshold: f64,
/// Negative Buckets.
#[prost(message, repeated, tag = "8")]
pub negative_spans: ::prost::alloc::vec::Vec<BucketSpan>,
/// Use either "negative_deltas" or "negative_counts", the former for
/// regular histograms with integer counts, the latter for float
/// histograms.
///
/// Count delta of each bucket compared to previous one (or to zero for 1st bucket).
#[prost(sint64, repeated, tag = "9")]
pub negative_deltas: ::prost::alloc::vec::Vec<i64>,
/// Absolute count of each bucket.
#[prost(double, repeated, tag = "10")]
pub negative_counts: ::prost::alloc::vec::Vec<f64>,
/// Positive Buckets.
#[prost(message, repeated, tag = "11")]
pub positive_spans: ::prost::alloc::vec::Vec<BucketSpan>,
/// Use either "positive_deltas" or "positive_counts", the former for
/// regular histograms with integer counts, the latter for float
/// histograms.
///
/// Count delta of each bucket compared to previous one (or to zero for 1st bucket).
#[prost(sint64, repeated, tag = "12")]
pub positive_deltas: ::prost::alloc::vec::Vec<i64>,
/// Absolute count of each bucket.
#[prost(double, repeated, tag = "13")]
pub positive_counts: ::prost::alloc::vec::Vec<f64>,
#[prost(enumeration = "histogram::ResetHint", tag = "14")]
pub reset_hint: i32,
/// timestamp is in ms format, see model/timestamp/timestamp.go for
/// conversion from time.Time to Prometheus timestamp.
#[prost(int64, tag = "15")]
pub timestamp: i64,
/// custom_values are not part of the specification, DO NOT use in remote write clients.
/// Used only for converting from OpenTelemetry to Prometheus internally.
#[prost(double, repeated, tag = "16")]
pub custom_values: ::prost::alloc::vec::Vec<f64>,
/// Count of observations in the histogram.
#[prost(oneof = "histogram::Count", tags = "1, 2")]
pub count: ::core::option::Option<histogram::Count>,
/// Count in zero bucket.
#[prost(oneof = "histogram::ZeroCount", tags = "6, 7")]
pub zero_count: ::core::option::Option<histogram::ZeroCount>,
}
/// Nested message and enum types in `Histogram`.
pub mod histogram {
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum ResetHint {
/// Need to test for a counter reset explicitly.
Unknown = 0,
/// This is the 1st histogram after a counter reset.
Yes = 1,
/// There was no counter reset between this and the previous Histogram.
No = 2,
/// This is a gauge histogram where counter resets don't happen.
Gauge = 3,
}
impl ResetHint {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unknown => "UNKNOWN",
Self::Yes => "YES",
Self::No => "NO",
Self::Gauge => "GAUGE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"YES" => Some(Self::Yes),
"NO" => Some(Self::No),
"GAUGE" => Some(Self::Gauge),
_ => None,
}
}
}
/// Count of observations in the histogram.
#[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
pub enum Count {
#[prost(uint64, tag = "1")]
CountInt(u64),
#[prost(double, tag = "2")]
CountFloat(f64),
}
/// Count in zero bucket.
#[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
pub enum ZeroCount {
#[prost(uint64, tag = "6")]
ZeroCountInt(u64),
#[prost(double, tag = "7")]
ZeroCountFloat(f64),
}
}
/// A BucketSpan defines a number of consecutive buckets with their
/// offset. Logically, it would be more straightforward to include the
/// bucket counts in the Span. However, the protobuf representation is
/// more compact in the way the data is structured here (with all the
/// buckets in a single array separate from the Spans).
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct BucketSpan {
/// Gap to previous span, or starting point for 1st span (which can be negative).
#[prost(sint32, tag = "1")]
pub offset: i32,
/// Length of consecutive buckets.
#[prost(uint32, tag = "2")]
pub length: u32,
}
/// TimeSeries represents samples and labels for a single time series.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct TimeSeries {
/// For a timeseries to be valid, and for the samples and exemplars
/// to be ingested by the remote system properly, the labels field is required.
#[prost(message, repeated, tag = "1")]
pub labels: ::prost::alloc::vec::Vec<Label>,
#[prost(message, repeated, tag = "2")]
pub samples: ::prost::alloc::vec::Vec<Sample>,
#[prost(message, repeated, tag = "3")]
pub exemplars: ::prost::alloc::vec::Vec<Exemplar>,
#[prost(message, repeated, tag = "4")]
pub histograms: ::prost::alloc::vec::Vec<Histogram>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Label {
#[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub value: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Labels {
#[prost(message, repeated, tag = "1")]
pub labels: ::prost::alloc::vec::Vec<Label>,
}
/// Matcher specifies a rule, which can match or set of labels or not.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LabelMatcher {
#[prost(enumeration = "label_matcher::Type", tag = "1")]
pub r#type: i32,
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub value: ::prost::alloc::string::String,
}
/// Nested message and enum types in `LabelMatcher`.
pub mod label_matcher {
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum Type {
Eq = 0,
Neq = 1,
Re = 2,
Nre = 3,
}
impl Type {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Eq => "EQ",
Self::Neq => "NEQ",
Self::Re => "RE",
Self::Nre => "NRE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"EQ" => Some(Self::Eq),
"NEQ" => Some(Self::Neq),
"RE" => Some(Self::Re),
"NRE" => Some(Self::Nre),
_ => None,
}
}
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ReadHints {
/// Query step size in milliseconds.
#[prost(int64, tag = "1")]
pub step_ms: i64,
/// String representation of surrounding function or aggregation.
#[prost(string, tag = "2")]
pub func: ::prost::alloc::string::String,
/// Start time in milliseconds.
#[prost(int64, tag = "3")]
pub start_ms: i64,
/// End time in milliseconds.
#[prost(int64, tag = "4")]
pub end_ms: i64,
/// List of label names used in aggregation.
#[prost(string, repeated, tag = "5")]
pub grouping: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Indicate whether it is without or by.
#[prost(bool, tag = "6")]
pub by: bool,
/// Range vector selector range in milliseconds.
#[prost(int64, tag = "7")]
pub range_ms: i64,
}
/// Chunk represents a TSDB chunk.
/// Time range \[min, max\] is inclusive.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Chunk {
#[prost(int64, tag = "1")]
pub min_time_ms: i64,
#[prost(int64, tag = "2")]
pub max_time_ms: i64,
#[prost(enumeration = "chunk::Encoding", tag = "3")]
pub r#type: i32,
#[prost(bytes = "vec", tag = "4")]
pub data: ::prost::alloc::vec::Vec<u8>,
}
/// Nested message and enum types in `Chunk`.
pub mod chunk {
/// We require this to match chunkenc.Encoding.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum Encoding {
Unknown = 0,
Xor = 1,
Histogram = 2,
FloatHistogram = 3,
}
impl Encoding {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unknown => "UNKNOWN",
Self::Xor => "XOR",
Self::Histogram => "HISTOGRAM",
Self::FloatHistogram => "FLOAT_HISTOGRAM",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN" => Some(Self::Unknown),
"XOR" => Some(Self::Xor),
"HISTOGRAM" => Some(Self::Histogram),
"FLOAT_HISTOGRAM" => Some(Self::FloatHistogram),
_ => None,
}
}
}
}
/// ChunkedSeries represents single, encoded time series.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ChunkedSeries {
/// Labels should be sorted.
#[prost(message, repeated, tag = "1")]
pub labels: ::prost::alloc::vec::Vec<Label>,
/// Chunks will be in start time order and may overlap.
#[prost(message, repeated, tag = "2")]
pub chunks: ::prost::alloc::vec::Vec<Chunk>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct WriteRequest {
#[prost(message, repeated, tag = "1")]
pub timeseries: ::prost::alloc::vec::Vec<TimeSeries>,
#[prost(message, repeated, tag = "3")]
pub metadata: ::prost::alloc::vec::Vec<MetricMetadata>,
}
/// ReadRequest represents a remote read request.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadRequest {
#[prost(message, repeated, tag = "1")]
pub queries: ::prost::alloc::vec::Vec<Query>,
/// accepted_response_types allows negotiating the content type of the response.
///
/// Response types are taken from the list in the FIFO order. If no response type in `accepted_response_types` is
/// implemented by server, error is returned.
/// For request that do not contain `accepted_response_types` field the SAMPLES response type will be used.
#[prost(enumeration = "read_request::ResponseType", repeated, tag = "2")]
pub accepted_response_types: ::prost::alloc::vec::Vec<i32>,
}
/// Nested message and enum types in `ReadRequest`.
pub mod read_request {
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
::prost::Enumeration
)]
#[repr(i32)]
pub enum ResponseType {
/// Server will return a single ReadResponse message with matched series that includes list of raw samples.
/// It's recommended to use streamed response types instead.
///
/// Response headers:
/// Content-Type: "application/x-protobuf"
/// Content-Encoding: "snappy"
Samples = 0,
/// Server will stream a delimited ChunkedReadResponse message that contains XOR encoded chunks for a single series.
/// Each message is following varint size and fixed size bigendian uint32 for CRC32 Castagnoli checksum.
///
/// Response headers:
/// Content-Type: "application/x-streamed-protobuf; proto=prometheus.ChunkedReadResponse"
/// Content-Encoding: ""
StreamedXorChunks = 1,
}
impl ResponseType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Samples => "SAMPLES",
Self::StreamedXorChunks => "STREAMED_XOR_CHUNKS",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"SAMPLES" => Some(Self::Samples),
"STREAMED_XOR_CHUNKS" => Some(Self::StreamedXorChunks),
_ => None,
}
}
}
}
/// ReadResponse is a response when response_type equals SAMPLES.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadResponse {
/// In same order as the request's queries.
#[prost(message, repeated, tag = "1")]
pub results: ::prost::alloc::vec::Vec<QueryResult>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Query {
#[prost(int64, tag = "1")]
pub start_timestamp_ms: i64,
#[prost(int64, tag = "2")]
pub end_timestamp_ms: i64,
#[prost(message, repeated, tag = "3")]
pub matchers: ::prost::alloc::vec::Vec<LabelMatcher>,
#[prost(message, optional, tag = "4")]
pub hints: ::core::option::Option<ReadHints>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QueryResult {
/// Samples within a time series must be ordered by time.
#[prost(message, repeated, tag = "1")]
pub timeseries: ::prost::alloc::vec::Vec<TimeSeries>,
}
/// ChunkedReadResponse is a response when response_type equals STREAMED_XOR_CHUNKS.
/// We strictly stream full series after series, optionally split by time. This means that a single frame can contain
/// partition of the single series, but once a new series is started to be streamed it means that no more chunks will
/// be sent for previous one. Series are returned sorted in the same way TSDB block are internally.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ChunkedReadResponse {
#[prost(message, repeated, tag = "1")]
pub chunked_series: ::prost::alloc::vec::Vec<ChunkedSeries>,
/// query_index represents an index of the query from ReadRequest.queries these chunks relates to.
#[prost(int64, tag = "2")]
pub query_index: i64,
}
+240
View File
@@ -0,0 +1,240 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct EmptyMetric {
/// Start timestamp in millisecond
#[prost(int64, tag = "1")]
pub start: i64,
/// End timestamp in millisecond
#[prost(int64, tag = "2")]
pub end: i64,
/// Interval in millisecond
#[prost(int64, tag = "3")]
pub interval: i64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InstantManipulate {
/// Start timestamp in millisecond
#[prost(int64, tag = "1")]
pub start: i64,
/// End timestamp in millisecond
#[prost(int64, tag = "2")]
pub end: i64,
/// Interval in millisecond
#[prost(int64, tag = "3")]
pub interval: i64,
/// Look-back delta in millisecond
#[prost(int64, tag = "4")]
pub lookback_delta: i64,
/// \[DEPRECATED\] Column name of time index column.
/// Use `time_index_idx` instead.
#[deprecated]
#[prost(string, tag = "5")]
pub time_index: ::prost::alloc::string::String,
/// \[DEPRECATED\] Optional field column name for validating staleness.
/// Use `field_index_idx` instead.
#[deprecated]
#[prost(string, tag = "6")]
pub field_index: ::prost::alloc::string::String,
/// Column index of time index column
#[prost(uint64, tag = "7")]
pub time_index_idx: u64,
/// Optional field column index for validating staleness
#[prost(uint64, tag = "8")]
pub field_index_idx: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SeriesNormalize {
/// Offset in millisecond
#[prost(int64, tag = "1")]
pub offset: i64,
/// \[DEPRECATED\] Column name of time index column.
/// Use `time_index_idx` instead.
#[deprecated]
#[prost(string, tag = "2")]
pub time_index: ::prost::alloc::string::String,
/// Whether to filter out NaN value
#[prost(bool, tag = "3")]
pub filter_nan: bool,
/// \[DEPRECATED\] Names of tag columns.
/// Use `tag_column_indices` instead.
#[deprecated]
#[prost(string, repeated, tag = "4")]
pub tag_columns: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Column index of time index column
#[prost(uint64, tag = "5")]
pub time_index_idx: u64,
/// Indices of tag columns
#[prost(uint64, repeated, tag = "6")]
pub tag_column_indices: ::prost::alloc::vec::Vec<u64>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct SeriesDivide {
/// \[DEPRECATED\] Names of tag columns.
/// Use `tag_column_indices` instead.
#[deprecated]
#[prost(string, repeated, tag = "1")]
pub tag_columns: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// \[DEPRECATED\] Name of time index column.
/// Use `time_index_column_idx` instead.
#[deprecated]
#[prost(string, tag = "2")]
pub time_index_column: ::prost::alloc::string::String,
/// Indices of tag columns
#[prost(uint64, repeated, tag = "3")]
pub tag_column_indices: ::prost::alloc::vec::Vec<u64>,
/// Index of time index column
#[prost(uint64, tag = "4")]
pub time_index_column_idx: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RangeManipulate {
/// Start timestamp in millisecond
#[prost(int64, tag = "1")]
pub start: i64,
/// End timestamp in millisecond
#[prost(int64, tag = "2")]
pub end: i64,
/// Interval in millisecond
#[prost(int64, tag = "3")]
pub interval: i64,
/// Range in millisecond
#[prost(int64, tag = "4")]
pub range: i64,
/// \[DEPRECATED\] Column name of time index column.
/// Use `time_index_idx` instead.
#[deprecated]
#[prost(string, tag = "5")]
pub time_index: ::prost::alloc::string::String,
/// \[DEPRECATED\] Names of tag columns.
/// Use `tag_column_indices` instead.
#[deprecated]
#[prost(string, repeated, tag = "6")]
pub tag_columns: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Column index of time index column
#[prost(uint64, tag = "7")]
pub time_index_idx: u64,
/// Indices of tag columns
#[prost(uint64, repeated, tag = "8")]
pub tag_column_indices: ::prost::alloc::vec::Vec<u64>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ScalarCalculate {
/// Start timestamp in millisecond
#[prost(int64, tag = "1")]
pub start: i64,
/// End timestamp in millisecond
#[prost(int64, tag = "2")]
pub end: i64,
/// Interval in millisecond
#[prost(int64, tag = "3")]
pub interval: i64,
/// \[DEPRECATED\] Column name of time index column.
/// Use `time_index_idx` instead.
#[deprecated]
#[prost(string, tag = "5")]
pub time_index: ::prost::alloc::string::String,
/// \[DEPRECATED\] Names of tag columns.
/// Use `tag_column_indices` instead.
#[deprecated]
#[prost(string, repeated, tag = "6")]
pub tag_columns: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// \[DEPRECATED\] Column name of field column.
/// Use `field_column_idx` instead.
#[deprecated]
#[prost(string, tag = "7")]
pub field_column: ::prost::alloc::string::String,
/// Column index of time index column
#[prost(uint64, tag = "8")]
pub time_index_idx: u64,
/// Indices of tag columns
#[prost(uint64, repeated, tag = "9")]
pub tag_column_indices: ::prost::alloc::vec::Vec<u64>,
/// Column index of field column
#[prost(uint64, tag = "10")]
pub field_column_idx: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Absent {
/// Start timestamp in millisecond
#[prost(int64, tag = "1")]
pub start: i64,
/// End timestamp in millisecond
#[prost(int64, tag = "2")]
pub end: i64,
/// Step in millisecond
#[prost(int64, tag = "3")]
pub step: i64,
/// \[DEPRECATED\] Column name of time index column.
/// Use `time_index_column_idx` instead.
#[deprecated]
#[prost(string, tag = "4")]
pub time_index_column: ::prost::alloc::string::String,
/// \[DEPRECATED\] Column name of value column.
/// Use `value_column_idx` instead.
#[deprecated]
#[prost(string, tag = "5")]
pub value_column: ::prost::alloc::string::String,
/// Fake labels as key-value pairs
#[prost(message, repeated, tag = "6")]
pub fake_labels: ::prost::alloc::vec::Vec<LabelPair>,
/// Column index of time index column
#[prost(uint64, tag = "7")]
pub time_index_column_idx: u64,
/// Column index of value column
#[prost(uint64, tag = "8")]
pub value_column_idx: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LabelPair {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub value: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
pub struct HistogramFold {
/// Column index of the `le` column (histogram bucket bounds)
#[prost(uint64, tag = "1")]
pub le_column_idx: u64,
/// Column index of the timestamp column
#[prost(uint64, tag = "2")]
pub ts_column_idx: u64,
/// Column index of the field column (histogram values)
#[prost(uint64, tag = "3")]
pub field_column_idx: u64,
/// Quantile value
#[prost(double, tag = "4")]
pub quantile: f64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UnionDistinctOn {
/// Indices of columns to compare for equality
#[prost(uint64, repeated, tag = "1")]
pub compare_key_indices: ::prost::alloc::vec::Vec<u64>,
/// Column index of the timestamp column
#[prost(uint64, tag = "2")]
pub ts_col_idx: u64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct MergeScan {
/// the input logical plan
#[prost(bytes = "vec", tag = "1")]
pub input: ::prost::alloc::vec::Vec<u8>,
/// whether this plan is a placeholder
#[prost(bool, tag = "2")]
pub is_placeholder: bool,
}
+2 -2
View File
@@ -17,10 +17,10 @@ pub mod v1;
pub mod prometheus {
pub mod remote {
tonic::include_proto!("prometheus");
include!("generated/prometheus.rs");
}
}
pub mod substrait_extension {
tonic::include_proto!("substrait_extension");
include!("generated/substrait_extension.rs");
}
+2 -2
View File
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1");
include!("generated/greptime.v1.rs");
use crate::v1::value::ValueData;
pub const GREPTIME_GRPC_DESC: &[u8] = tonic::include_file_descriptor_set!("greptime_grpc_desc");
pub const GREPTIME_GRPC_DESC: &[u8] = include_bytes!("generated/greptime_grpc_desc.bin");
pub mod flow;
pub mod frontend;
+1 -1
View File
@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1.flow");
include!("../generated/greptime.v1.flow.rs");
+1 -1
View File
@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1.frontend");
include!("../generated/greptime.v1.frontend.rs");
+1 -1
View File
@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1.index");
include!("../generated/greptime.v1.index.rs");
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1.meta");
include!("../generated/greptime.v1.meta.rs");
mod mailbox;
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
tonic::include_proto!("greptime.v1.region");
include!("../generated/greptime.v1.region.rs");
#[cfg(test)]
mod test {
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "greptime-proto-xtask"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
tonic-prost-build = "0.14"
+158
View File
@@ -0,0 +1,158 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::env;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
const LICENSE_HEADER: &str = r#"// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
"#;
const PROTO_FILES: &[&str] = &[
"proto/greptime/v1/database.proto",
"proto/greptime/v1/health.proto",
"proto/greptime/v1/wal.proto",
"proto/greptime/v1/meta/common.proto",
"proto/greptime/v1/meta/heartbeat.proto",
"proto/greptime/v1/meta/config.proto",
"proto/greptime/v1/meta/route.proto",
"proto/greptime/v1/meta/ddl.proto",
"proto/greptime/v1/meta/region.proto",
"proto/greptime/v1/meta/store.proto",
"proto/greptime/v1/meta/lock.proto",
"proto/greptime/v1/meta/cluster.proto",
"proto/greptime/v1/meta/procedure.proto",
"proto/greptime/v1/region/server.proto",
"proto/greptime/v1/flow/server.proto",
"proto/greptime/v1/frontend/server.proto",
"proto/greptime/v1/index/bloom_filter.proto",
"proto/greptime/v1/index/inverted_index.proto",
"proto/greptime/v1/index/vector_index.proto",
"proto/prometheus/remote/remote.proto",
"proto/substrait_extension/promql_plan.proto",
"proto/substrait_extension/dist_plan.proto",
];
const GENERATED_FILES: &[&str] = &[
"greptime.v1.rs",
"greptime.v1.meta.rs",
"greptime.v1.region.rs",
"greptime.v1.flow.rs",
"greptime.v1.frontend.rs",
"greptime.v1.index.rs",
"prometheus.rs",
"substrait_extension.rs",
"greptime_grpc_desc.bin",
];
fn main() -> Result<(), Box<dyn Error>> {
run()
}
fn run() -> Result<(), Box<dyn Error>> {
let mut args = env::args().skip(1);
match args.next().as_deref() {
Some("generate-rust") if args.next().is_none() => generate_rust(),
_ => Err("usage: cargo run --manifest-path xtask/Cargo.toml -- generate-rust".into()),
}
}
fn generate_rust() -> Result<(), Box<dyn Error>> {
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.ok_or("xtask manifest must live under the repository root")?
.to_path_buf();
let generated_dir = repo_root.join("src/generated");
fs::create_dir_all(&generated_dir)?;
for generated_file in GENERATED_FILES {
let path = generated_dir.join(generated_file);
if path.exists() {
fs::remove_file(path)?;
}
}
let proto_files: Vec<PathBuf> = PROTO_FILES
.iter()
.map(|path| repo_root.join(path))
.collect();
let include_dirs = [repo_root.join("proto")];
tonic_prost_build::configure()
.out_dir(&generated_dir)
.file_descriptor_set_path(generated_dir.join("greptime_grpc_desc.bin"))
.type_attribute(
".greptime.v1.SemanticType",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.Peer",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.HeartbeatRequest.node_workloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.DatanodeWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.FrontendWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.type_attribute(
".greptime.v1.meta.FlownodeWorkloads",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.enum_attribute(
"region.RegionRequest.body",
"#[derive(strum_macros::AsRefStr)]",
)
.bytes(".greptime.v1.ArrowIpc")
.compile_protos(&proto_files, &include_dirs)?;
for generated_file in GENERATED_FILES {
if generated_file.ends_with(".rs") {
prepend_license_header(&generated_dir.join(generated_file))?;
}
}
Ok(())
}
fn prepend_license_header(path: &PathBuf) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(path)?;
if contents.starts_with(LICENSE_HEADER) {
return Ok(());
}
fs::write(path, format!("{LICENSE_HEADER}{contents}"))?;
Ok(())
}