Skip to content

Commit 3fa44fd

Browse files
chore: simplify sample rows key callable chain (#2396)
Previously there were 3 chain creators: 1. createSampleRowKeysBaseCallable 2. createSampleRowKeysWithRequestCallable 3. createSampleRowKeysCallable The primary reason for this is that SampleRowKeysWithRequest was introduced after createSampleRowKeysCallable because it supports authorized views. This pr simplifies the logic by moving everything into createSampleRowKeysWithRequestCallable and makes createSampleRowKeysCallable be a tiny shim to convert a String tableId into a SampleRowKeysRequest
1 parent e7ffbda commit 3fa44fd

File tree

3 files changed

+40
-253
lines changed

3 files changed

+40
-253
lines changed

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

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INSTANCE_ID_KEY;
2222

2323
import com.google.api.core.ApiFunction;
24+
import com.google.api.core.ApiFuture;
2425
import com.google.api.core.BetaApi;
2526
import com.google.api.core.InternalApi;
2627
import com.google.api.gax.batching.Batcher;
@@ -39,6 +40,7 @@
3940
import com.google.api.gax.retrying.RetryAlgorithm;
4041
import com.google.api.gax.retrying.RetryingExecutorWithContext;
4142
import com.google.api.gax.retrying.ScheduledRetryingExecutor;
43+
import com.google.api.gax.rpc.ApiCallContext;
4244
import com.google.api.gax.rpc.Callables;
4345
import com.google.api.gax.rpc.ClientContext;
4446
import com.google.api.gax.rpc.RequestParamsExtractor;
@@ -98,6 +100,7 @@
98100
import com.google.cloud.bigtable.data.v2.models.RowMutation;
99101
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
100102
import com.google.cloud.bigtable.data.v2.models.SampleRowKeysRequest;
103+
import com.google.cloud.bigtable.data.v2.models.TableId;
101104
import com.google.cloud.bigtable.data.v2.models.TargetId;
102105
import com.google.cloud.bigtable.data.v2.models.sql.Statement;
103106
import com.google.cloud.bigtable.data.v2.stub.changestream.ChangeStreamRecordMergingCallable;
@@ -194,7 +197,7 @@ public class EnhancedBigtableStub implements AutoCloseable {
194197
private final ServerStreamingCallable<Query, Row> readRowsCallable;
195198
private final UnaryCallable<Query, Row> readRowCallable;
196199
private final UnaryCallable<Query, List<Row>> bulkReadRowsCallable;
197-
private final UnaryCallable<String, List<KeyOffset>> sampleRowKeysCallable;
200+
@Deprecated private final UnaryCallable<String, List<KeyOffset>> sampleRowKeysCallable;
198201
private final UnaryCallable<SampleRowKeysRequest, List<KeyOffset>>
199202
sampleRowKeysCallableWithRequest;
200203
private final UnaryCallable<RowMutation, Void> mutateRowCallable;
@@ -698,11 +701,40 @@ private <RowT> UnaryCallable<Query, List<RowT>> createBulkReadRowsCallable(
698701
}
699702

700703
/**
701-
* Helper function that should only be used by createSampleRowKeysCallable() and
702-
* createSampleRowKeysWithRequestCallable().
704+
* Simple wrapper around {@link #createSampleRowKeysCallableWithRequest()} to provide backwards
705+
* compatibility
706+
*
707+
* @deprecated
708+
*/
709+
@Deprecated
710+
private UnaryCallable<String, List<KeyOffset>> createSampleRowKeysCallable() {
711+
UnaryCallable<SampleRowKeysRequest, List<KeyOffset>> baseCallable =
712+
createSampleRowKeysCallableWithRequest();
713+
return new UnaryCallable<String, List<KeyOffset>>() {
714+
@Override
715+
public ApiFuture<List<KeyOffset>> futureCall(String s, ApiCallContext apiCallContext) {
716+
return baseCallable.futureCall(SampleRowKeysRequest.create(TableId.of(s)), apiCallContext);
717+
}
718+
};
719+
}
720+
721+
/**
722+
* Creates a callable chain to handle SampleRowKeys RPcs. The chain will:
723+
*
724+
* <ul>
725+
* <li>Convert a {@link SampleRowKeysRequest} to a {@link
726+
* com.google.bigtable.v2.SampleRowKeysRequest}.
727+
* <li>Dispatch the request to the GAPIC's {@link BigtableStub#sampleRowKeysCallable()}.
728+
* <li>Spool responses into a list.
729+
* <li>Retry on failure.
730+
* <li>Convert the responses into {@link KeyOffset}s.
731+
* <li>Add tracing & metrics.
732+
* </ul>
703733
*/
704-
private UnaryCallable<com.google.bigtable.v2.SampleRowKeysRequest, List<SampleRowKeysResponse>>
705-
createSampleRowKeysBaseCallable() {
734+
private UnaryCallable<SampleRowKeysRequest, List<KeyOffset>>
735+
createSampleRowKeysCallableWithRequest() {
736+
String methodName = "SampleRowKeys";
737+
706738
ServerStreamingCallable<com.google.bigtable.v2.SampleRowKeysRequest, SampleRowKeysResponse>
707739
base =
708740
GrpcRawCallableFactory.createServerStreamingCallable(
@@ -745,51 +777,8 @@ public Map<String, String> extract(
745777
UnaryCallable<com.google.bigtable.v2.SampleRowKeysRequest, List<SampleRowKeysResponse>>
746778
retryable = withRetries(withBigtableTracer, settings.sampleRowKeysSettings());
747779

748-
return retryable;
749-
}
750-
751-
/**
752-
* Creates a callable chain to handle SampleRowKeys RPcs. The chain will:
753-
*
754-
* <ul>
755-
* <li>Convert a table id to a {@link com.google.bigtable.v2.SampleRowKeysRequest}.
756-
* <li>Dispatch the request to the GAPIC's {@link BigtableStub#sampleRowKeysCallable()}.
757-
* <li>Spool responses into a list.
758-
* <li>Retry on failure.
759-
* <li>Convert the responses into {@link KeyOffset}s.
760-
* <li>Add tracing & metrics.
761-
* </ul>
762-
*/
763-
private UnaryCallable<String, List<KeyOffset>> createSampleRowKeysCallable() {
764-
String methodName = "SampleRowKeys";
765-
766-
UnaryCallable<com.google.bigtable.v2.SampleRowKeysRequest, List<SampleRowKeysResponse>>
767-
baseCallable = createSampleRowKeysBaseCallable();
768-
return createUserFacingUnaryCallable(
769-
methodName, new SampleRowKeysCallable(baseCallable, requestContext));
770-
}
771-
772-
/**
773-
* Creates a callable chain to handle SampleRowKeys RPcs. The chain will:
774-
*
775-
* <ul>
776-
* <li>Convert a {@link SampleRowKeysRequest} to a {@link
777-
* com.google.bigtable.v2.SampleRowKeysRequest}.
778-
* <li>Dispatch the request to the GAPIC's {@link BigtableStub#sampleRowKeysCallable()}.
779-
* <li>Spool responses into a list.
780-
* <li>Retry on failure.
781-
* <li>Convert the responses into {@link KeyOffset}s.
782-
* <li>Add tracing & metrics.
783-
* </ul>
784-
*/
785-
private UnaryCallable<SampleRowKeysRequest, List<KeyOffset>>
786-
createSampleRowKeysCallableWithRequest() {
787-
String methodName = "SampleRowKeys";
788-
789-
UnaryCallable<com.google.bigtable.v2.SampleRowKeysRequest, List<SampleRowKeysResponse>>
790-
baseCallable = createSampleRowKeysBaseCallable();
791780
return createUserFacingUnaryCallable(
792-
methodName, new SampleRowKeysCallableWithRequest(baseCallable, requestContext));
781+
methodName, new SampleRowKeysCallableWithRequest(retryable, requestContext));
793782
}
794783

795784
/**
@@ -1470,6 +1459,8 @@ public UnaryCallable<Query, Row> readRowCallable() {
14701459
return readRowCallable;
14711460
}
14721461

1462+
/** Deprecated, please use {@link #sampleRowKeysCallableWithRequest} */
1463+
@Deprecated
14731464
public UnaryCallable<String, List<KeyOffset>> sampleRowKeysCallable() {
14741465
return sampleRowKeysCallable;
14751466
}

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

Lines changed: 0 additions & 79 deletions
This file was deleted.

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/SampleRowKeysCallableTest.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)