Skip to content

Commit f4a4599

Browse files
authored
support setting gzip level (tikv#577)
Signed-off-by: zkkxu <[email protected]>
1 parent 41e3e09 commit f4a4599

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
- run: cargo build
8484
- run: cargo test --all
8585
- run: RUSTFLAGS="-Z sanitizer=address" cargo test --all --target x86_64-unknown-linux-gnu
86+
- run: cargo test --features "nightly"
8687

8788
Mac:
8889
name: Mac
@@ -98,6 +99,7 @@ jobs:
9899
- run: cargo build --no-default-features --features "prost-codec"
99100
- run: cargo build
100101
- run: cargo test --all
102+
- run: cargo test --features "nightly"
101103

102104
Mac-openssl:
103105
name: Mac-openssl
@@ -124,6 +126,7 @@ jobs:
124126
- run: cargo xtask submodule
125127
- run: cargo build
126128
- run: cargo test --all
129+
- run: cargo test --features "nightly"
127130

128131
Pre-Release:
129132
name: Pre-Release

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ default = ["protobuf-codec", "boringssl"]
4545
_secure = []
4646
protobuf-codec = ["protobuf"]
4747
prost-codec = ["prost", "bytes"]
48+
nightly = []
4849
boringssl = ["grpcio-sys/boringssl", "_secure"]
4950
openssl = ["_secure", "grpcio-sys/openssl"]
5051
openssl-vendored = ["_secure", "grpcio-sys/openssl-vendored"]

grpc-sys/bindings/bindings.rs

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub const GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION: &[u8; 39usize] =
7676
pub const GRPC_ARG_LB_POLICY_NAME: &[u8; 20usize] = b"grpc.lb_policy_name\0";
7777
pub const GRPC_ARG_SOCKET_MUTATOR: &[u8; 20usize] = b"grpc.socket_mutator\0";
7878
pub const GRPC_ARG_SOCKET_FACTORY: &[u8; 20usize] = b"grpc.socket_factory\0";
79+
pub const GRPC_ARG_GZIP_COMPRESSION_LEVEL: &[u8; 28usize] = b"grpc.gzip_compression_level\0";
80+
pub const GRPC_ARG_MIN_MESSAGE_SIZE_TO_COMPRESS: &[u8; 39usize] =
81+
b"grpc.gprc_min_message_size_to_compress\0";
7982
pub const GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE: &[u8; 45usize] =
8083
b"grpc.max_channel_trace_event_memory_per_node\0";
8184
pub const GRPC_ARG_ENABLE_CHANNELZ: &[u8; 21usize] = b"grpc.enable_channelz\0";

grpc-sys/grpc

Submodule grpc updated from d560d06 to 38a9cd9

src/channel.rs

+46
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,29 @@ impl ChannelBuilder {
314314
self
315315
}
316316

317+
/// Set default gzip compression level.
318+
#[cfg(feature = "nightly")]
319+
pub fn default_gzip_compression_level(mut self, level: usize) -> ChannelBuilder {
320+
self.options.insert(
321+
Cow::Borrowed(grpcio_sys::GRPC_ARG_GZIP_COMPRESSION_LEVEL),
322+
Options::Integer(level as i32),
323+
);
324+
self
325+
}
326+
327+
/// Set default grpc min message size to compression.
328+
#[cfg(feature = "nightly")]
329+
pub fn default_grpc_min_message_size_to_compress(
330+
mut self,
331+
lower_bound: usize,
332+
) -> ChannelBuilder {
333+
self.options.insert(
334+
Cow::Borrowed(grpcio_sys::GRPC_ARG_MIN_MESSAGE_SIZE_TO_COMPRESS),
335+
Options::Integer(lower_bound as i32),
336+
);
337+
self
338+
}
339+
317340
/// Set default compression level for the channel.
318341
pub fn default_compression_level(mut self, level: CompressionLevel) -> ChannelBuilder {
319342
self.options.insert(
@@ -733,3 +756,26 @@ impl Channel {
733756
&self.cq
734757
}
735758
}
759+
760+
#[cfg(test)]
761+
#[cfg(feature = "nightly")]
762+
mod tests {
763+
use crate::env::Environment;
764+
use crate::ChannelBuilder;
765+
use std::sync::Arc;
766+
767+
#[test]
768+
#[cfg(feature = "nightly")]
769+
fn test_grpc_min_message_size_to_compress() {
770+
let env = Arc::new(Environment::new(1));
771+
let cb = ChannelBuilder::new(env);
772+
cb.default_grpc_min_message_size_to_compress(1);
773+
}
774+
#[test]
775+
#[cfg(feature = "nightly")]
776+
fn test_gzip_compression_level() {
777+
let env = Arc::new(Environment::new(1));
778+
let cb = ChannelBuilder::new(env);
779+
cb.default_gzip_compression_level(1);
780+
}
781+
}

0 commit comments

Comments
 (0)