Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set wait timeout on watchdog #1898

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ public Map<String, String> extract(ReadRowsRequest readRowsRequest) {
.setRetryableCodes(readRowsSettings.getRetryableCodes())
.setRetrySettings(readRowsSettings.getRetrySettings())
.setIdleTimeout(readRowsSettings.getIdleTimeout())
.setWaitTimeout(readRowsSettings.getWaitTimeout())
.build();

ServerStreamingCallable<ReadRowsRequest, RowT> watched =
Expand Down Expand Up @@ -906,6 +907,8 @@ public Map<String, String> extract(
settings.generateInitialChangeStreamPartitionsSettings().getRetrySettings())
.setIdleTimeout(
settings.generateInitialChangeStreamPartitionsSettings().getIdleTimeout())
.setWaitTimeout(
settings.generateInitialChangeStreamPartitionsSettings().getWaitTimeout())
.build();

ServerStreamingCallable<String, ByteStringRange> watched =
Expand Down Expand Up @@ -980,6 +983,7 @@ public Map<String, String> extract(
.setRetryableCodes(settings.readChangeStreamSettings().getRetryableCodes())
.setRetrySettings(settings.readChangeStreamSettings().getRetrySettings())
.setIdleTimeout(settings.readChangeStreamSettings().getIdleTimeout())
.setWaitTimeout(settings.readChangeStreamSettings().getWaitTimeout())
.build();

ServerStreamingCallable<ReadChangeStreamRequest, ChangeStreamRecordT> watched =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,15 @@ private Builder() {
generateInitialChangeStreamPartitionsSettings
.setRetryableCodes(GENERATE_INITIAL_CHANGE_STREAM_PARTITIONS_RETRY_CODES)
.setRetrySettings(GENERATE_INITIAL_CHANGE_STREAM_PARTITIONS_RETRY_SETTINGS)
.setIdleTimeout(Duration.ofMinutes(5));
.setIdleTimeout(Duration.ofMinutes(5))
.setWaitTimeout(Duration.ofMinutes(5));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should lower the waitTimeout to 1m


readChangeStreamSettings = ServerStreamingCallSettings.newBuilder();
readChangeStreamSettings
.setRetryableCodes(READ_CHANGE_STREAM_RETRY_CODES)
.setRetrySettings(READ_CHANGE_STREAM_RETRY_SETTINGS)
.setIdleTimeout(Duration.ofMinutes(5));
.setIdleTimeout(Duration.ofMinutes(5))
.setWaitTimeout(Duration.ofMinutes(5));
Comment on lines +724 to +725
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should lower the wait timeout to 1m


pingAndWarmSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
pingAndWarmSettings.setRetrySettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.InstantiatingWatchdogProvider;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.WatchdogTimeoutException;
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.FeatureFlags;
Expand Down Expand Up @@ -82,11 +84,13 @@
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -101,6 +105,8 @@ public class EnhancedBigtableStubTest {
private static final String TABLE_NAME =
NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, "fake-table");
private static final String APP_PROFILE_ID = "app-profile-id";
private static final String WAIT_TIME_TABLE_ID = "test-wait-timeout";
private static final Duration WATCHDOG_CHECK_DURATION = Duration.ofMillis(100);

private Server server;
private MetadataInterceptor metadataInterceptor;
Expand Down Expand Up @@ -544,6 +550,25 @@ public void testBulkMutationFlowControlFeatureFlagIsNotSet() throws Exception {
assertThat(featureFlags.getMutateRowsRateLimit()).isFalse();
}

@Test
public void testWaitTimeoutIsSet() throws Exception {
EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder();
// Set a shorter wait timeout and make watchdog checks more frequently
settings.readRowsSettings().setWaitTimeout(WATCHDOG_CHECK_DURATION.dividedBy(2));
settings.setStreamWatchdogProvider(
InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION));

EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build());
Iterator<Row> iterator =
stub.readRowsCallable().call(Query.create(WAIT_TIME_TABLE_ID)).iterator();
try {
iterator.next();
Assert.fail("Should throw watchdog timeout exception");
} catch (WatchdogTimeoutException e) {
assertThat(e.getMessage()).contains("Canceled due to timeout waiting for next response");
}
}

private static class MetadataInterceptor implements ServerInterceptor {
final BlockingQueue<Metadata> headers = Queues.newLinkedBlockingDeque();

Expand Down Expand Up @@ -593,6 +618,13 @@ public void mutateRows(
@Override
public void readRows(
ReadRowsRequest request, StreamObserver<ReadRowsResponse> responseObserver) {
if (request.getTableName().contains(WAIT_TIME_TABLE_ID)) {
try {
Thread.sleep(WATCHDOG_CHECK_DURATION.toMillis() * 2);
} catch (Exception e) {

}
}
requests.add(request);
// Dummy row for stream
responseObserver.onNext(
Expand Down
Loading