From edbcde1a5b22317319803cb57401252aac6d580d Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Tue, 6 Oct 2020 14:09:53 -0600 Subject: [PATCH] feat: add keepalive changes in java client library (#409) * feat: Add keepalive logic in bigtable data client * fix: code formatting * fix: mvn formatting * fix: setting in emulator * feat: add keep alive in enhanced stub as well --- .../com/google/cloud/bigtable/emulator/v2/Emulator.java | 8 +++++++- .../cloud/bigtable/data/v2/BigtableDataSettings.java | 5 +++++ .../data/v2/stub/EnhancedBigtableStubSettings.java | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java index 8e8cd5ad0..3cfbc981a 100644 --- a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java +++ b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java @@ -179,7 +179,13 @@ public synchronized ManagedChannel getDataChannel() { } if (dataChannel == null) { - dataChannel = newChannelBuilder(port).maxInboundMessageSize(256 * 1024 * 1024).build(); + dataChannel = + newChannelBuilder(port) + .maxInboundMessageSize(256 * 1024 * 1024) + .keepAliveTimeout(10, TimeUnit.SECONDS) + .keepAliveTime(10, TimeUnit.SECONDS) + .keepAliveWithoutCalls(true) + .build(); } return dataChannel; } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java index 8dd0fa6d9..3b07eeaf2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.logging.Logger; import javax.annotation.Nonnull; +import org.threeten.bp.Duration; /** * Settings class to configure an instance of {@link BigtableDataClient}. @@ -122,6 +123,10 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) { return input.usePlaintext(); } }) + .setKeepAliveTime(Duration.ofSeconds(10)) // sends ping in this interval + .setKeepAliveTimeout( + Duration.ofSeconds(10)) // wait this long before considering the connection dead + .setKeepAliveWithoutCalls(true) // sends ping without active streams .build()); LOGGER.info("Connecting to the Bigtable emulator at " + hostname + ":" + port); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 5253a5a1b..360141083 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -241,6 +241,10 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi return BigtableStubSettings.defaultGrpcTransportProviderBuilder() .setPoolSize(getDefaultChannelPoolSize()) .setMaxInboundMessageSize(MAX_MESSAGE_SIZE) + .setKeepAliveTime(Duration.ofSeconds(10)) // sends ping in this interval + .setKeepAliveTimeout( + Duration.ofSeconds(10)) // wait this long before considering the connection dead + .setKeepAliveWithoutCalls(true) // sends ping without active streams // TODO(weiranf): Set this to true by default once DirectPath goes to public beta .setAttemptDirectPath(isDirectPathEnabled()); }