From 87edb1d197c0830f02e6f07fc5dda49c4fedad5a Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Wed, 9 Sep 2020 19:09:04 -0400 Subject: [PATCH 1/5] feat: Add keepalive logic in bigtable data client --- .../google/cloud/bigtable/data/v2/BigtableDataSettings.java | 5 +++++ 1 file changed, 5 insertions(+) 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 8dd0fa6d97..d24012b36f 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 @@ -26,6 +26,8 @@ import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings; import com.google.common.base.Strings; import io.grpc.ManagedChannelBuilder; +import org.threeten.bp.Duration; + import java.util.List; import java.util.logging.Logger; import javax.annotation.Nonnull; @@ -122,6 +124,9 @@ 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); From 0a93d8b43a93ff184d3028aa35c6c2130f0678c9 Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Wed, 9 Sep 2020 19:22:26 -0400 Subject: [PATCH 2/5] fix: code formatting --- .../com/google/cloud/bigtable/data/v2/BigtableDataSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d24012b36f..e97c9500c0 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 @@ -28,9 +28,9 @@ import io.grpc.ManagedChannelBuilder; import org.threeten.bp.Duration; +import javax.annotation.Nonnull; import java.util.List; import java.util.logging.Logger; -import javax.annotation.Nonnull; /** * Settings class to configure an instance of {@link BigtableDataClient}. From f383d7665db64c7df7cd2b3753a01c6b64168cfe Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Thu, 10 Sep 2020 01:29:26 -0400 Subject: [PATCH 3/5] fix: mvn formatting --- .../cloud/bigtable/data/v2/BigtableDataSettings.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 e97c9500c0..3b07eeaf23 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 @@ -26,11 +26,10 @@ import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings; import com.google.common.base.Strings; import io.grpc.ManagedChannelBuilder; -import org.threeten.bp.Duration; - -import javax.annotation.Nonnull; 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}. @@ -125,8 +124,9 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) { } }) .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 + .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); From 63cc8cdc8fc3305248c3b964daf6199a005670ef Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Thu, 10 Sep 2020 02:38:29 -0400 Subject: [PATCH 4/5] fix: setting in emulator --- .../com/google/cloud/bigtable/emulator/v2/Emulator.java | 8 +++++++- 1 file changed, 7 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 9c2fa49b38..c764fbdda9 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 @@ -177,7 +177,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; } From ea7075516b6db66fa3bdee8dc7e23dd6c547d028 Mon Sep 17 00:00:00 2001 From: Sushan Bhattarai Date: Wed, 16 Sep 2020 11:15:20 -0400 Subject: [PATCH 5/5] feat: add keep alive in enhanced stub as well --- .../bigtable/data/v2/stub/EnhancedBigtableStubSettings.java | 4 ++++ 1 file changed, 4 insertions(+) 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 d843265d1e..5a93cc5d14 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 @@ -238,6 +238,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()); }