Skip to content

Commit 1aebfa5

Browse files
authored
store: Make "grpc_max_decoding_message_size" configurable (#485)
Signed-off-by: Ping Yu <[email protected]>
1 parent 8f81873 commit 1aebfa5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ pub struct Config {
1919
pub cert_path: Option<PathBuf>,
2020
pub key_path: Option<PathBuf>,
2121
pub timeout: Duration,
22+
pub grpc_max_decoding_message_size: usize,
2223
}
2324

2425
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(2);
26+
const DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE: usize = 4 * 1024 * 1024; // 4MB
2527

2628
impl Default for Config {
2729
fn default() -> Self {
@@ -30,6 +32,7 @@ impl Default for Config {
3032
cert_path: None,
3133
key_path: None,
3234
timeout: DEFAULT_REQUEST_TIMEOUT,
35+
grpc_max_decoding_message_size: DEFAULT_GRPC_MAX_DECODING_MESSAGE_SIZE,
3336
}
3437
}
3538
}
@@ -83,4 +86,11 @@ impl Config {
8386
self.timeout = timeout;
8487
self
8588
}
89+
90+
/// Set the maximum decoding message size for gRPC.
91+
#[must_use]
92+
pub fn with_grpc_max_decoding_message_size(mut self, size: usize) -> Self {
93+
self.grpc_max_decoding_message_size = size;
94+
self
95+
}
8696
}

src/pd/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,13 @@ impl<Cod: Codec> PdRpcClient<Cod, TikvConnect, Cluster> {
306306
) -> Result<PdRpcClient<Cod>> {
307307
PdRpcClient::new(
308308
config.clone(),
309-
|security_mgr| TikvConnect::new(security_mgr, config.timeout),
309+
|security_mgr| {
310+
TikvConnect::new(
311+
security_mgr,
312+
config.timeout,
313+
config.grpc_max_decoding_message_size,
314+
)
315+
},
310316
|security_mgr| RetryClient::connect(pd_endpoints, security_mgr, config.timeout),
311317
enable_mvcc_codec,
312318
codec,

src/store/client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub trait KvConnect: Sized + Send + Sync + 'static {
2525
pub struct TikvConnect {
2626
security_mgr: Arc<SecurityManager>,
2727
timeout: Duration,
28+
grpc_max_decoding_message_size: usize,
2829
}
2930

3031
#[async_trait]
@@ -33,7 +34,10 @@ impl KvConnect for TikvConnect {
3334

3435
async fn connect(&self, address: &str) -> Result<KvRpcClient> {
3536
self.security_mgr
36-
.connect(address, TikvClient::new)
37+
.connect(address, move |channel| {
38+
TikvClient::new(channel)
39+
.max_decoding_message_size(self.grpc_max_decoding_message_size)
40+
})
3741
.await
3842
.map(|c| KvRpcClient::new(c, self.timeout))
3943
}

0 commit comments

Comments
 (0)