-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(bigtable): route point read rows to shim #13542
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |||||
| import com.google.api.gax.retrying.BasicResultRetryAlgorithm; | ||||||
| import com.google.api.gax.retrying.ExponentialRetryAlgorithm; | ||||||
| import com.google.api.gax.retrying.RetryAlgorithm; | ||||||
| import com.google.api.gax.retrying.RetrySettings; | ||||||
| import com.google.api.gax.retrying.RetryingExecutorWithContext; | ||||||
| import com.google.api.gax.retrying.ScheduledRetryingExecutor; | ||||||
| import com.google.api.gax.retrying.SimpleStreamResumptionStrategy; | ||||||
|
|
@@ -37,6 +38,7 @@ | |||||
| import com.google.api.gax.rpc.RequestParamsExtractor; | ||||||
| import com.google.api.gax.rpc.ServerStreamingCallSettings; | ||||||
| import com.google.api.gax.rpc.ServerStreamingCallable; | ||||||
| import com.google.api.gax.rpc.StatusCode; | ||||||
| import com.google.api.gax.rpc.UnaryCallSettings; | ||||||
| import com.google.api.gax.rpc.UnaryCallable; | ||||||
| import com.google.api.gax.tracing.SpanName; | ||||||
|
|
@@ -97,6 +99,7 @@ | |||||
| import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.FilterMarkerRowsCallable; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.LargeReadRowsResumptionStrategy; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.MaybePointReadCallable; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsResumptionStrategy; | ||||||
| import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsRetryCompletedCallable; | ||||||
|
|
@@ -119,6 +122,7 @@ | |||||
| import java.time.Duration; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
| import java.util.Set; | ||||||
| import java.util.concurrent.TimeUnit; | ||||||
| import java.util.function.Function; | ||||||
| import javax.annotation.Nonnull; | ||||||
|
|
@@ -259,11 +263,20 @@ public <RowT> ServerStreamingCallable<Query, RowT> createReadRowsCallable( | |||||
| bigtableClientContext.getClientContext().getTracerFactory(), | ||||||
| span); | ||||||
|
|
||||||
| return traced.withDefaultCallContext( | ||||||
| bigtableClientContext | ||||||
| .getClientContext() | ||||||
| .getDefaultCallContext() | ||||||
| .withRetrySettings(perOpSettings.readRowsSettings.getRetrySettings())); | ||||||
| ServerStreamingCallable<Query, RowT> classic = | ||||||
| traced.withDefaultCallContext( | ||||||
| bigtableClientContext | ||||||
| .getClientContext() | ||||||
| .getDefaultCallContext() | ||||||
| .withRetrySettings(perOpSettings.readRowsSettings.getRetrySettings())); | ||||||
|
|
||||||
| return new MaybePointReadCallable<>( | ||||||
| classic, | ||||||
| createPointReadCallable( | ||||||
| rowAdapter, | ||||||
| "ReadRows", | ||||||
| perOpSettings.readRowsSettings.getRetrySettings(), | ||||||
| perOpSettings.readRowsSettings.getRetryableCodes())); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -281,13 +294,25 @@ public <RowT> ServerStreamingCallable<Query, RowT> createReadRowsCallable( | |||||
| * </ul> | ||||||
| */ | ||||||
| public <RowT> UnaryCallable<Query, RowT> createReadRowCallable(RowAdapter<RowT> rowAdapter) { | ||||||
| return createPointReadCallable( | ||||||
| rowAdapter, | ||||||
| "ReadRow", | ||||||
| perOpSettings.readRowSettings.getRetrySettings(), | ||||||
| perOpSettings.readRowSettings.getRetryableCodes()); | ||||||
| } | ||||||
|
|
||||||
| private <RowT> UnaryCallable<Query, RowT> createPointReadCallable( | ||||||
| RowAdapter<RowT> rowAdapter, | ||||||
| String spanName, | ||||||
| RetrySettings retrySettings, | ||||||
| Set<StatusCode.Code> retryableCodes) { | ||||||
| ClientContext clientContext = bigtableClientContext.getClientContext(); | ||||||
|
|
||||||
| ServerStreamingCallable<ReadRowsRequest, RowT> readRowsCallable = | ||||||
| createReadRowsBaseCallable( | ||||||
| ServerStreamingCallSettings.<ReadRowsRequest, Row>newBuilder() | ||||||
| .setRetryableCodes(perOpSettings.readRowSettings.getRetryableCodes()) | ||||||
| .setRetrySettings(perOpSettings.readRowSettings.getRetrySettings()) | ||||||
| .setRetryableCodes(retryableCodes) | ||||||
| .setRetrySettings(retrySettings) | ||||||
| .setIdleTimeoutDuration(Duration.ZERO) | ||||||
| .setWaitTimeoutDuration(Duration.ZERO) | ||||||
| .build(), | ||||||
|
|
@@ -302,16 +327,20 @@ public <RowT> UnaryCallable<Query, RowT> createReadRowCallable(RowAdapter<RowT> | |||||
| BigtableUnaryOperationCallable<Query, RowT> classic = | ||||||
| new BigtableUnaryOperationCallable<>( | ||||||
| readRowCallable, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bug here where the locally created
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this review is right. readRows callable is converted to readRow callable with Transforming callable. |
||||||
| clientContext | ||||||
| .getDefaultCallContext() | ||||||
| .withRetrySettings(perOpSettings.readRowSettings.getRetrySettings()), | ||||||
| clientContext.getDefaultCallContext().withRetrySettings(retrySettings), | ||||||
| clientContext.getTracerFactory(), | ||||||
| getSpanName("ReadRow"), | ||||||
| getSpanName(spanName), | ||||||
| /* allowNoResponse= */ true); | ||||||
|
|
||||||
| UnaryCallSettings<?, ?> shimSettings = | ||||||
| perOpSettings.readRowSettings.toBuilder() | ||||||
| .setRetrySettings(retrySettings) | ||||||
| .setRetryableCodes(retryableCodes) | ||||||
| .build(); | ||||||
|
|
||||||
| return bigtableClientContext | ||||||
| .getSessionShim() | ||||||
| .decorateReadRow(classic, rowAdapter, perOpSettings.readRowSettings); | ||||||
| .decorateReadRow(classic, rowAdapter, shimSettings); | ||||||
| } | ||||||
|
|
||||||
| private <ReqT, RowT> ServerStreamingCallable<ReadRowsRequest, RowT> createReadRowsBaseCallable( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.stub.readrows; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.ApiFutureCallback; | ||
| import com.google.api.core.ApiFutures; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.api.gax.rpc.ApiCallContext; | ||
| import com.google.api.gax.rpc.ResponseObserver; | ||
| import com.google.api.gax.rpc.ServerStreamingCallable; | ||
| import com.google.api.gax.rpc.StreamController; | ||
| import com.google.api.gax.rpc.UnaryCallable; | ||
| import com.google.cloud.bigtable.data.v2.models.Query; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| /** | ||
| * Routes ReadRows calls whose query identifies a single row through a unary point-read callable, | ||
| * letting them benefit from the same session-shim diversion as {@code ReadRow}. Queries that cannot | ||
| * be reduced to a point read fall through to the classic {@code ReadRows} callable. | ||
| */ | ||
| @InternalApi | ||
| public class MaybePointReadCallable<RowT> extends ServerStreamingCallable<Query, RowT> { | ||
|
mutianf marked this conversation as resolved.
|
||
| private final ServerStreamingCallable<Query, RowT> classic; | ||
| private final UnaryCallable<Query, RowT> pointReader; | ||
|
|
||
| public MaybePointReadCallable( | ||
| ServerStreamingCallable<Query, RowT> classic, UnaryCallable<Query, RowT> pointReader) { | ||
| this.classic = classic; | ||
| this.pointReader = pointReader; | ||
| } | ||
|
|
||
| @Override | ||
| public void call(Query request, ResponseObserver<RowT> responseObserver, ApiCallContext context) { | ||
| if (!request.isSinglePointQuery()) { | ||
| classic.call(request, responseObserver, context); | ||
| return; | ||
| } | ||
|
|
||
| AtomicBoolean cancelled = new AtomicBoolean(); | ||
| AtomicReference<ApiFuture<RowT>> futureRef = new AtomicReference<>(); | ||
|
|
||
| responseObserver.onStart( | ||
| new StreamController() { | ||
| @Override | ||
| public void cancel() { | ||
| cancelled.set(true); | ||
| ApiFuture<RowT> f = futureRef.get(); | ||
| if (f != null) { | ||
| f.cancel(false); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void disableAutoInboundFlowControl() {} | ||
|
|
||
| @Override | ||
| public void request(int count) {} | ||
| }); | ||
|
|
||
| ApiFuture<RowT> future; | ||
| try { | ||
| future = pointReader.futureCall(request, context); | ||
| } catch (Throwable t) { | ||
| if (!cancelled.get()) { | ||
| responseObserver.onError(t); | ||
| } | ||
| return; | ||
| } | ||
| futureRef.set(future); | ||
| if (cancelled.get()) { | ||
| future.cancel(false); | ||
| } | ||
|
|
||
| ApiFutures.addCallback( | ||
| future, | ||
| new ApiFutureCallback<RowT>() { | ||
| @Override | ||
| public void onSuccess(RowT row) { | ||
| if (cancelled.get()) { | ||
| return; | ||
| } | ||
| if (row != null) { | ||
| try { | ||
| responseObserver.onResponse(row); | ||
| } catch (Throwable t) { | ||
| responseObserver.onError(t); | ||
| return; | ||
| } | ||
| } | ||
| responseObserver.onComplete(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Throwable t) { | ||
| if (cancelled.get()) { | ||
| return; | ||
| } | ||
| responseObserver.onError(t); | ||
| } | ||
| }, | ||
| MoreExecutors.directExecutor()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.