Skip to content

Commit edbcde1

Browse files
authored
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
1 parent 25eafdd commit edbcde1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@ public synchronized ManagedChannel getDataChannel() {
179179
}
180180

181181
if (dataChannel == null) {
182-
dataChannel = newChannelBuilder(port).maxInboundMessageSize(256 * 1024 * 1024).build();
182+
dataChannel =
183+
newChannelBuilder(port)
184+
.maxInboundMessageSize(256 * 1024 * 1024)
185+
.keepAliveTimeout(10, TimeUnit.SECONDS)
186+
.keepAliveTime(10, TimeUnit.SECONDS)
187+
.keepAliveWithoutCalls(true)
188+
.build();
183189
}
184190
return dataChannel;
185191
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.logging.Logger;
3131
import javax.annotation.Nonnull;
32+
import org.threeten.bp.Duration;
3233

3334
/**
3435
* Settings class to configure an instance of {@link BigtableDataClient}.
@@ -122,6 +123,10 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
122123
return input.usePlaintext();
123124
}
124125
})
126+
.setKeepAliveTime(Duration.ofSeconds(10)) // sends ping in this interval
127+
.setKeepAliveTimeout(
128+
Duration.ofSeconds(10)) // wait this long before considering the connection dead
129+
.setKeepAliveWithoutCalls(true) // sends ping without active streams
125130
.build());
126131

127132
LOGGER.info("Connecting to the Bigtable emulator at " + hostname + ":" + port);

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java

+4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi
241241
return BigtableStubSettings.defaultGrpcTransportProviderBuilder()
242242
.setPoolSize(getDefaultChannelPoolSize())
243243
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
244+
.setKeepAliveTime(Duration.ofSeconds(10)) // sends ping in this interval
245+
.setKeepAliveTimeout(
246+
Duration.ofSeconds(10)) // wait this long before considering the connection dead
247+
.setKeepAliveWithoutCalls(true) // sends ping without active streams
244248
// TODO(weiranf): Set this to true by default once DirectPath goes to public beta
245249
.setAttemptDirectPath(isDirectPathEnabled());
246250
}

0 commit comments

Comments
 (0)