|
47 | 47 | import com.google.bigtable.v2.BigtableGrpc; |
48 | 48 | import com.google.bigtable.v2.CheckAndMutateRowRequest; |
49 | 49 | import com.google.bigtable.v2.CheckAndMutateRowResponse; |
| 50 | +import com.google.bigtable.v2.ListChangeStreamPartitionsRequest; |
| 51 | +import com.google.bigtable.v2.ListChangeStreamPartitionsResponse; |
50 | 52 | import com.google.bigtable.v2.MutateRowRequest; |
51 | 53 | import com.google.bigtable.v2.MutateRowResponse; |
52 | 54 | import com.google.bigtable.v2.MutateRowsRequest; |
|
65 | 67 | import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter; |
66 | 68 | import com.google.cloud.bigtable.data.v2.models.KeyOffset; |
67 | 69 | import com.google.cloud.bigtable.data.v2.models.Query; |
| 70 | +import com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange; |
68 | 71 | import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; |
69 | 72 | import com.google.cloud.bigtable.data.v2.models.Row; |
70 | 73 | import com.google.cloud.bigtable.data.v2.models.RowAdapter; |
71 | 74 | import com.google.cloud.bigtable.data.v2.models.RowMutation; |
72 | 75 | import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; |
| 76 | +import com.google.cloud.bigtable.data.v2.stub.changestream.ListChangeStreamPartitionsUserCallable; |
73 | 77 | import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerStreamingCallable; |
74 | 78 | import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracerUnaryCallable; |
75 | 79 | import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTracerFactory; |
@@ -142,6 +146,8 @@ public class EnhancedBigtableStub implements AutoCloseable { |
142 | 146 | private final UnaryCallable<ConditionalRowMutation, Boolean> checkAndMutateRowCallable; |
143 | 147 | private final UnaryCallable<ReadModifyWriteRow, Row> readModifyWriteRowCallable; |
144 | 148 |
|
| 149 | + private final ServerStreamingCallable<String, ByteStringRange> listChangeStreamPartitionsCallable; |
| 150 | + |
145 | 151 | public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings) |
146 | 152 | throws IOException { |
147 | 153 | settings = finalizeSettings(settings, Tags.getTagger(), Stats.getStatsRecorder()); |
@@ -284,6 +290,7 @@ public EnhancedBigtableStub(EnhancedBigtableStubSettings settings, ClientContext |
284 | 290 | bulkMutateRowsCallable = createBulkMutateRowsCallable(); |
285 | 291 | checkAndMutateRowCallable = createCheckAndMutateRowCallable(); |
286 | 292 | readModifyWriteRowCallable = createReadModifyWriteRowCallable(); |
| 293 | + listChangeStreamPartitionsCallable = createListChangeStreamPartitionsCallable(); |
287 | 294 | } |
288 | 295 |
|
289 | 296 | // <editor-fold desc="Callable creators"> |
@@ -798,6 +805,71 @@ public Map<String, String> extract(ReadModifyWriteRowRequest request) { |
798 | 805 | methodName, new ReadModifyWriteRowCallable(retrying, requestContext)); |
799 | 806 | } |
800 | 807 |
|
| 808 | + /** |
| 809 | + * Creates a callable chain to handle streaming ListChangeStreamPartitions RPCs. The chain will: |
| 810 | + * |
| 811 | + * <ul> |
| 812 | + * <li>Convert a String format tableId into a {@link com.google.bigtable.v2.ReadChangeStreamRequest} and |
| 813 | + * dispatch the RPC. |
| 814 | + * <li>Upon receiving the response stream, it will convert the {@link |
| 815 | + * com.google.bigtable.v2.ListChangeStreamPartitionsResponse}s into {@link ByteStringRange}. |
| 816 | + * </ul> |
| 817 | + */ |
| 818 | + private ServerStreamingCallable<String, ByteStringRange> |
| 819 | + createListChangeStreamPartitionsCallable() { |
| 820 | + ServerStreamingCallable<ListChangeStreamPartitionsRequest, ListChangeStreamPartitionsResponse> |
| 821 | + base = |
| 822 | + GrpcRawCallableFactory.createServerStreamingCallable( |
| 823 | + GrpcCallSettings |
| 824 | + .<ListChangeStreamPartitionsRequest, ListChangeStreamPartitionsResponse> |
| 825 | + newBuilder() |
| 826 | + .setMethodDescriptor(BigtableGrpc.getListChangeStreamPartitionsMethod()) |
| 827 | + .setParamsExtractor( |
| 828 | + new RequestParamsExtractor<ListChangeStreamPartitionsRequest>() { |
| 829 | + @Override |
| 830 | + public Map<String, String> extract( |
| 831 | + ListChangeStreamPartitionsRequest listChangeStreamPartitionsRequest) { |
| 832 | + return ImmutableMap.of( |
| 833 | + "table_name", |
| 834 | + listChangeStreamPartitionsRequest.getTableName(), |
| 835 | + "app_profile_id", |
| 836 | + listChangeStreamPartitionsRequest.getAppProfileId()); |
| 837 | + } |
| 838 | + }) |
| 839 | + .build(), |
| 840 | + settings.listChangeStreamPartitionsSettings().getRetryableCodes()); |
| 841 | + |
| 842 | + ServerStreamingCallable<String, ByteStringRange> userCallable = |
| 843 | + new ListChangeStreamPartitionsUserCallable(base, requestContext); |
| 844 | + |
| 845 | + ServerStreamingCallable<String, ByteStringRange> withStatsHeaders = |
| 846 | + new StatsHeadersServerStreamingCallable<>(userCallable); |
| 847 | + |
| 848 | + // Copy settings for the middle String -> ByteStringRange callable (as opposed to the inner |
| 849 | + // ListChangeStreamPartitionsRequest -> ListChangeStreamPartitionsResponse callable). |
| 850 | + ServerStreamingCallSettings<String, ByteStringRange> innerSettings = |
| 851 | + ServerStreamingCallSettings.<String, ByteStringRange>newBuilder() |
| 852 | + .setRetryableCodes(settings.listChangeStreamPartitionsSettings().getRetryableCodes()) |
| 853 | + .setRetrySettings(settings.listChangeStreamPartitionsSettings().getRetrySettings()) |
| 854 | + .setIdleTimeout(settings.listChangeStreamPartitionsSettings().getIdleTimeout()) |
| 855 | + .build(); |
| 856 | + |
| 857 | + ServerStreamingCallable<String, ByteStringRange> watched = |
| 858 | + Callables.watched(withStatsHeaders, innerSettings, clientContext); |
| 859 | + |
| 860 | + ServerStreamingCallable<String, ByteStringRange> withBigtableTracer = |
| 861 | + new BigtableTracerStreamingCallable<>(watched); |
| 862 | + |
| 863 | + ServerStreamingCallable<String, ByteStringRange> retrying = |
| 864 | + Callables.retrying(withBigtableTracer, innerSettings, clientContext); |
| 865 | + |
| 866 | + SpanName span = getSpanName("ListChangeStreamPartitions"); |
| 867 | + ServerStreamingCallable<String, ByteStringRange> traced = |
| 868 | + new TracedServerStreamingCallable<>(retrying, clientContext.getTracerFactory(), span); |
| 869 | + |
| 870 | + return traced.withDefaultCallContext(clientContext.getDefaultCallContext()); |
| 871 | + } |
| 872 | + |
801 | 873 | /** |
802 | 874 | * Wraps a callable chain in a user presentable callable that will inject the default call context |
803 | 875 | * and trace the call. |
@@ -854,6 +926,11 @@ public UnaryCallable<ConditionalRowMutation, Boolean> checkAndMutateRowCallable( |
854 | 926 | public UnaryCallable<ReadModifyWriteRow, Row> readModifyWriteRowCallable() { |
855 | 927 | return readModifyWriteRowCallable; |
856 | 928 | } |
| 929 | + |
| 930 | + /** Returns a streaming list change stream partitions callable */ |
| 931 | + public ServerStreamingCallable<String, ByteStringRange> listChangeStreamPartitionsCallable() { |
| 932 | + return listChangeStreamPartitionsCallable; |
| 933 | + } |
857 | 934 | // </editor-fold> |
858 | 935 |
|
859 | 936 | private SpanName getSpanName(String methodName) { |
|
0 commit comments