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: remove tracking latency from channel priming requests #1082

Merged
merged 6 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,9 @@
import com.google.api.gax.grpc.ChannelPrimer;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.auth.Credentials;
import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -143,9 +145,11 @@ private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException

// Prime all of the table ids in parallel
for (String tableId : tableIds) {
UnaryCallable<Query, Row> callable = stub.createReadRowRawCallable(new DefaultRowAdapter());

ApiFuture<Row> f =
stub.readRowCallable()
.futureCall(Query.create(tableId).rowKey(PRIMING_ROW_KEY).filter(FILTERS.block()));
callable.futureCall(
Query.create(tableId).rowKey(PRIMING_ROW_KEY).filter(FILTERS.block()));

primeFutures.put(tableId, f);
}
Expand Down
Expand Up @@ -327,6 +327,36 @@ public <RowT> ServerStreamingCallable<Query, RowT> createReadRowsCallable(
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}

/**
* Creates a callable chain to handle point ReadRows RPCs. The chain will:
*
* <ul>
* <li>Convert a {@link Query} into a {@link com.google.bigtable.v2.ReadRowsRequest} and
* dispatch the RPC.
* <li>Upon receiving the response stream, it will merge the {@link
* com.google.bigtable.v2.ReadRowsResponse.CellChunk}s in logical rows. The actual row
* implementation can be configured in by the {@code rowAdapter} parameter.
* <li>Retry/resume on failure.
* <li>Filter out marker rows.
* </ul>
*
* <p>NOTE: the caller is responsible for adding tracing & metrics.
*/
protected <RowT> UnaryCallable<Query, RowT> createReadRowRawCallable(
diegomez17 marked this conversation as resolved.
Show resolved Hide resolved
RowAdapter<RowT> rowAdapter) {
ServerStreamingCallable<ReadRowsRequest, RowT> readRowsCallable =
createReadRowsBaseCallable(
diegomez17 marked this conversation as resolved.
Show resolved Hide resolved
ServerStreamingCallSettings.<ReadRowsRequest, Row>newBuilder()
.setRetryableCodes(settings.readRowSettings().getRetryableCodes())
.setRetrySettings(settings.readRowSettings().getRetrySettings())
.setIdleTimeout(settings.readRowSettings().getRetrySettings().getTotalTimeout())
.build(),
rowAdapter)
.withDefaultCallContext(clientContext.getDefaultCallContext());

return new ReadRowsUserCallable<>(readRowsCallable, requestContext).first();
}

/**
* Creates a callable chain to handle point ReadRows RPCs. The chain will:
*
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.MutateRowsRequest;
Expand Down Expand Up @@ -262,6 +263,19 @@ public void testCreateReadRowsRawCallable() throws InterruptedException {
assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest2);
}

@Test
public void testCreateReadRowRawCallable() throws InterruptedException {
UnaryCallable<Query, Row> callable =
enhancedBigtableStub.createReadRowRawCallable(new DefaultRowAdapter());

Query request = Query.create("table-id").rowKey("row-key");
callable.call(request);

ReadRowsRequest expected =
request.toProto(RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID));
assertThat(fakeDataService.popLastRequest()).isEqualTo(expected);
}

@Test
public void testChannelPrimerConfigured() throws IOException {
EnhancedBigtableStubSettings settings =
Expand Down