Skip to content

Commit 4286e1c

Browse files
authored
Added support of grpc compression (#104)
2 parents 9626ff3 + 22e75c7 commit 4286e1c

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

jdbc/src/main/java/tech/ydb/jdbc/settings/YdbConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public DriverPropertyInfo[] toPropertyInfo() throws SQLException {
202202
YdbConnectionProperties.USE_METADATA.toInfo(properties),
203203
YdbConnectionProperties.IAM_ENDPOINT.toInfo(properties),
204204
YdbConnectionProperties.METADATA_URL.toInfo(properties),
205+
YdbConnectionProperties.GRPC_COMPRESSION.toInfo(properties),
205206

206207
YdbClientProperties.KEEP_QUERY_TEXT.toInfo(properties),
207208
YdbClientProperties.SESSION_KEEP_ALIVE_TIME.toInfo(properties),

jdbc/src/main/java/tech/ydb/jdbc/settings/YdbConnectionProperties.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tech.ydb.auth.iam.CloudAuthHelper;
1010
import tech.ydb.core.auth.StaticCredentials;
1111
import tech.ydb.core.grpc.BalancingSettings;
12+
import tech.ydb.core.grpc.GrpcCompression;
1213
import tech.ydb.core.grpc.GrpcTransportBuilder;
1314
import tech.ydb.jdbc.YdbDriver;
1415

@@ -47,6 +48,10 @@ public class YdbConnectionProperties {
4748
static final YdbProperty<String> METADATA_URL = YdbProperty.content("metadataURL",
4849
"Custom URL for the metadata service authentication");
4950

51+
static final YdbProperty<String> GRPC_COMPRESSION = YdbProperty.string(
52+
"grpcCompression", "Use specified GRPC compressor (supported only none and gzip)"
53+
);
54+
5055
private final String username;
5156
private final String password;
5257

@@ -60,6 +65,7 @@ public class YdbConnectionProperties {
6065
private final YdbValue<Boolean> useMetadata;
6166
private final YdbValue<String> iamEndpoint;
6267
private final YdbValue<String> metadataUrl;
68+
private final YdbValue<String> grpcCompression;
6369

6470
public YdbConnectionProperties(YdbConfig config) throws SQLException {
6571
this.username = config.getUsername();
@@ -77,6 +83,7 @@ public YdbConnectionProperties(YdbConfig config) throws SQLException {
7783
this.useMetadata = USE_METADATA.readValue(props);
7884
this.iamEndpoint = IAM_ENDPOINT.readValue(props);
7985
this.metadataUrl = METADATA_URL.readValue(props);
86+
this.grpcCompression = GRPC_COMPRESSION.readValue(props);
8087
}
8188

8289
String getLocalDataCenter() {
@@ -175,6 +182,17 @@ public GrpcTransportBuilder applyToGrpcTransport(GrpcTransportBuilder builder) {
175182
}
176183
}
177184

185+
if (grpcCompression.hasValue()) {
186+
String value = grpcCompression.getValue();
187+
if ("none".equalsIgnoreCase(value)) {
188+
builder = builder.withGrpcCompression(GrpcCompression.NO_COMPRESSION);
189+
} else if ("gzip".equalsIgnoreCase(value)) {
190+
builder = builder.withGrpcCompression(GrpcCompression.GZIP);
191+
} else {
192+
LOGGER.log(Level.WARNING, "Unknown value for option 'grpcCompression' : {0}", value);
193+
}
194+
}
195+
178196
return builder;
179197
}
180198
}

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbConnectionImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class YdbConnectionImplTest {
4040
private static final YdbHelperExtension ydb = new YdbHelperExtension();
4141

4242
@RegisterExtension
43-
private static final JdbcConnectionExtention jdbc = new JdbcConnectionExtention(ydb);
43+
private static final JdbcConnectionExtention jdbc = new JdbcConnectionExtention(ydb)
44+
.withArg("grpcCompression", "gzip");
4445

4546
private static final SqlQueries QUERIES = new SqlQueries("ydb_connection_test");
4647
private static final String SELECT_2_2 = "select 2 + 2";

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbTableConnectionImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class YdbTableConnectionImplTest {
4141

4242
@RegisterExtension
4343
private static final JdbcConnectionExtention jdbc = new JdbcConnectionExtention(ydb)
44-
.withArg("useQueryService", "false");
44+
.withArg("useQueryService", "false")
45+
.withArg("grpcCompression", "none");
4546

4647
private static final SqlQueries QUERIES = new SqlQueries("ydb_connection_test");
4748
private static final String SELECT_2_2 = "select 2 + 2";

jdbc/src/test/java/tech/ydb/jdbc/settings/YdbDriverProperitesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ static DriverPropertyInfo[] defaultPropertyInfo(@Nullable String localDatacenter
316316
new DriverPropertyInfo("useMetadata", ""),
317317
new DriverPropertyInfo("iamEndpoint", ""),
318318
new DriverPropertyInfo("metadataURL", ""),
319+
new DriverPropertyInfo("grpcCompression", ""),
319320
new DriverPropertyInfo("keepQueryText", ""),
320321
new DriverPropertyInfo("sessionKeepAliveTime", ""),
321322
new DriverPropertyInfo("sessionMaxIdleTime", ""),
@@ -360,6 +361,7 @@ static DriverPropertyInfo[] customizedPropertyInfo() {
360361
new DriverPropertyInfo("useMetadata", "true"),
361362
new DriverPropertyInfo("iamEndpoint", "iam.endpoint.com"),
362363
new DriverPropertyInfo("metadataURL", "https://metadata.com"),
364+
new DriverPropertyInfo("grpcCompression", "gzip"),
363365
new DriverPropertyInfo("keepQueryText", "true"),
364366
new DriverPropertyInfo("sessionKeepAliveTime", "15m"),
365367
new DriverPropertyInfo("sessionMaxIdleTime", "5m"),

0 commit comments

Comments
 (0)