From e0621588a0ee2ca7dab54ad4273c1e2477001719 Mon Sep 17 00:00:00 2001 From: Ping Yu Date: Fri, 11 Apr 2025 08:32:58 +0800 Subject: [PATCH 1/3] store: Make "grpc_max_decoding_message_size" configurable (#485) Signed-off-by: Ping Yu --- src/config.rs | 10 ++++++++++ src/pd/client.rs | 8 +++++++- src/store/client.rs | 6 +++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 79dad855..e5ff51eb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,10 +19,12 @@ pub struct Config { pub cert_path: Option, pub key_path: Option, pub timeout: Duration, + pub grpc_max_decoding_message_size: usize, pub keyspace: Option, } const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(2); +const DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE: usize = 4 * 1024 * 1024; // 4MB impl Default for Config { fn default() -> Self { @@ -31,6 +33,7 @@ impl Default for Config { cert_path: None, key_path: None, timeout: DEFAULT_REQUEST_TIMEOUT, + grpc_max_decoding_message_size: DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE, keyspace: None, } } @@ -86,6 +89,13 @@ impl Config { self } + /// Set the maximum decoding message size for gRPC. + #[must_use] + pub fn with_grpc_max_decoding_message_size(mut self, size: usize) -> Self { + self.grpc_max_decoding_message_size = size; + self + } + /// Set to use default keyspace. /// /// Server should enable `storage.api-version = 2` to use this feature. diff --git a/src/pd/client.rs b/src/pd/client.rs index 417fd19e..05b9c07c 100644 --- a/src/pd/client.rs +++ b/src/pd/client.rs @@ -290,7 +290,13 @@ impl PdRpcClient { ) -> Result { PdRpcClient::new( config.clone(), - |security_mgr| TikvConnect::new(security_mgr, config.timeout), + |security_mgr| { + TikvConnect::new( + security_mgr, + config.timeout, + config.grpc_max_decoding_message_size, + ) + }, |security_mgr| RetryClient::connect(pd_endpoints, security_mgr, config.timeout), enable_codec, ) diff --git a/src/store/client.rs b/src/store/client.rs index 363d4137..88880c7f 100644 --- a/src/store/client.rs +++ b/src/store/client.rs @@ -25,6 +25,7 @@ pub trait KvConnect: Sized + Send + Sync + 'static { pub struct TikvConnect { security_mgr: Arc, timeout: Duration, + grpc_max_decoding_message_size: usize, } #[async_trait] @@ -33,7 +34,10 @@ impl KvConnect for TikvConnect { async fn connect(&self, address: &str) -> Result { self.security_mgr - .connect(address, TikvClient::new) + .connect(address, move |channel| { + TikvClient::new(channel) + .max_decoding_message_size(self.grpc_max_decoding_message_size) + }) .await .map(|c| KvRpcClient::new(c, self.timeout)) } From f8c2113671115f58bca768324297b6acd9754acf Mon Sep 17 00:00:00 2001 From: Ping Yu Date: Mon, 19 May 2025 13:58:28 +0800 Subject: [PATCH 2/3] store: Enable gRPC gzip compression (#490) Signed-off-by: Ping Yu --- Cargo.toml | 2 +- config/tikv.toml | 3 +++ src/store/client.rs | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 03d0198d..2e340d74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ serde_json = "1" take_mut = "0.2.2" thiserror = "1" tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] } -tonic = { version = "0.10", features = ["tls"] } +tonic = { version = "0.10", features = ["tls", "gzip"] } [dev-dependencies] clap = "2" diff --git a/config/tikv.toml b/config/tikv.toml index 21c6d896..275c7127 100644 --- a/config/tikv.toml +++ b/config/tikv.toml @@ -20,3 +20,6 @@ max-open-files = 10000 api-version = 2 enable-ttl = true reserve-space = "0MiB" + +[server] +grpc-compression-type = "gzip" diff --git a/src/store/client.rs b/src/store/client.rs index 88880c7f..1c873285 100644 --- a/src/store/client.rs +++ b/src/store/client.rs @@ -6,6 +6,7 @@ use std::time::Duration; use async_trait::async_trait; use derive_new::new; +use tonic::codec::CompressionEncoding; use tonic::transport::Channel; use super::Request; @@ -37,6 +38,7 @@ impl KvConnect for TikvConnect { .connect(address, move |channel| { TikvClient::new(channel) .max_decoding_message_size(self.grpc_max_decoding_message_size) + .accept_compressed(CompressionEncoding::Gzip) }) .await .map(|c| KvRpcClient::new(c, self.timeout)) From d6162b2749a95b2846092eaad7cbbe40c191e8fb Mon Sep 17 00:00:00 2001 From: Ping Yu Date: Tue, 20 Jan 2026 15:41:10 +0800 Subject: [PATCH 3/3] bump 0.4.0 Signed-off-by: Ping Yu --- Cargo.toml | 2 +- src/config.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2e340d74..8d6cd57d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-client" -version = "0.3.0" +version = "0.4.0" keywords = ["TiKV", "KV", "distributed-systems"] license = "Apache-2.0" authors = ["The TiKV Project Authors"] diff --git a/src/config.rs b/src/config.rs index e5ff51eb..92a67e65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,9 +11,14 @@ use serde_derive::Serialize; /// /// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure /// requests. +/// +/// This struct is marked `#[non_exhaustive]` to allow adding new configuration options in the +/// future without breaking downstream code. Construct it via [`Config::default`] and then use the +/// `with_*` methods (or field assignment) to customize it. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] #[serde(rename_all = "kebab-case")] +#[non_exhaustive] pub struct Config { pub ca_path: Option, pub cert_path: Option,