37
37
import com .google .api .gax .rpc .RequestParamsExtractor ;
38
38
import com .google .api .gax .rpc .ServerStreamingCallSettings ;
39
39
import com .google .api .gax .rpc .ServerStreamingCallable ;
40
+ import com .google .api .gax .rpc .UnaryCallSettings ;
40
41
import com .google .api .gax .rpc .UnaryCallable ;
41
42
import com .google .api .gax .tracing .OpencensusTracerFactory ;
42
43
import com .google .api .gax .tracing .SpanName ;
@@ -185,11 +186,14 @@ public static EnhancedBigtableStubSettings finalizeSettings(
185
186
// workaround JWT audience issues
186
187
patchCredentials (builder );
187
188
188
- // patch cookies interceptor
189
- InstantiatingGrpcChannelProvider .Builder transportProvider = null ;
190
- if (builder .getTransportChannelProvider () instanceof InstantiatingGrpcChannelProvider ) {
191
- transportProvider =
192
- ((InstantiatingGrpcChannelProvider ) builder .getTransportChannelProvider ()).toBuilder ();
189
+ InstantiatingGrpcChannelProvider .Builder transportProvider =
190
+ builder .getTransportChannelProvider () instanceof InstantiatingGrpcChannelProvider
191
+ ? ((InstantiatingGrpcChannelProvider ) builder .getTransportChannelProvider ()).toBuilder ()
192
+ : null ;
193
+
194
+ if (builder .getEnableRoutingCookie () && transportProvider != null ) {
195
+ // TODO: this also need to be added to BigtableClientFactory
196
+ // patch cookies interceptor
193
197
transportProvider .setInterceptorProvider (() -> ImmutableList .of (new CookiesInterceptor ()));
194
198
}
195
199
@@ -371,11 +375,7 @@ public <RowT> ServerStreamingCallable<Query, RowT> createReadRowsCallable(
371
375
new TracedServerStreamingCallable <>(
372
376
readRowsUserCallable , clientContext .getTracerFactory (), span );
373
377
374
- // CookieHolder needs to be injected to the CallOptions outside of retries, otherwise retry
375
- // attempts won't see a CookieHolder.
376
- ServerStreamingCallable <Query , RowT > withCookie = new CookiesServerStreamingCallable <>(traced );
377
-
378
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
378
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
379
379
}
380
380
381
381
/**
@@ -411,9 +411,7 @@ public <RowT> UnaryCallable<Query, RowT> createReadRowCallable(RowAdapter<RowT>
411
411
new TracedUnaryCallable <>(
412
412
firstRow , clientContext .getTracerFactory (), getSpanName ("ReadRow" ));
413
413
414
- UnaryCallable <Query , RowT > withCookie = new CookiesUnaryCallable <>(traced );
415
-
416
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
414
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
417
415
}
418
416
419
417
/**
@@ -485,7 +483,7 @@ public Map<String, String> extract(ReadRowsRequest readRowsRequest) {
485
483
new ReadRowsRetryCompletedCallable <>(withBigtableTracer );
486
484
487
485
ServerStreamingCallable <ReadRowsRequest , RowT > retrying2 =
488
- Callables . retrying (retrying1 , innerSettings , clientContext );
486
+ withRetries (retrying1 , innerSettings );
489
487
490
488
return new FilterMarkerRowsCallable <>(retrying2 , rowAdapter );
491
489
}
@@ -568,7 +566,7 @@ public Map<String, String> extract(
568
566
new BigtableTracerUnaryCallable <>(withStatsHeaders );
569
567
570
568
UnaryCallable <SampleRowKeysRequest , List <SampleRowKeysResponse >> retryable =
571
- Callables . retrying (withBigtableTracer , settings .sampleRowKeysSettings (), clientContext );
569
+ withRetries (withBigtableTracer , settings .sampleRowKeysSettings ());
572
570
573
571
return createUserFacingUnaryCallable (
574
572
methodName , new SampleRowKeysCallable (retryable , requestContext ));
@@ -607,7 +605,7 @@ public Map<String, String> extract(MutateRowRequest mutateRowRequest) {
607
605
new BigtableTracerUnaryCallable <>(withStatsHeaders );
608
606
609
607
UnaryCallable <MutateRowRequest , MutateRowResponse > retrying =
610
- Callables . retrying (withBigtableTracer , settings .mutateRowSettings (), clientContext );
608
+ withRetries (withBigtableTracer , settings .mutateRowSettings ());
611
609
612
610
return createUserFacingUnaryCallable (
613
611
methodName , new MutateRowCallable (retrying , requestContext ));
@@ -631,19 +629,25 @@ public Map<String, String> extract(MutateRowRequest mutateRowRequest) {
631
629
private UnaryCallable <BulkMutation , Void > createBulkMutateRowsCallable () {
632
630
UnaryCallable <MutateRowsRequest , Void > baseCallable = createMutateRowsBaseCallable ();
633
631
632
+ UnaryCallable <MutateRowsRequest , Void > withCookie = baseCallable ;
633
+
634
+ if (settings .getEnableRoutingCookie ()) {
635
+ withCookie = new CookiesUnaryCallable <>(baseCallable );
636
+ }
637
+
634
638
UnaryCallable <MutateRowsRequest , Void > flowControlCallable = null ;
635
639
if (settings .bulkMutateRowsSettings ().isLatencyBasedThrottlingEnabled ()) {
636
640
flowControlCallable =
637
641
new DynamicFlowControlCallable (
638
- baseCallable ,
642
+ withCookie ,
639
643
bulkMutationFlowController ,
640
644
bulkMutationDynamicFlowControlStats ,
641
645
settings .bulkMutateRowsSettings ().getTargetRpcLatencyMs (),
642
646
FLOW_CONTROL_ADJUSTING_INTERVAL_MS );
643
647
}
644
648
UnaryCallable <BulkMutation , Void > userFacing =
645
649
new BulkMutateRowsUserFacingCallable (
646
- flowControlCallable != null ? flowControlCallable : baseCallable , requestContext );
650
+ flowControlCallable != null ? flowControlCallable : withCookie , requestContext );
647
651
648
652
SpanName spanName = getSpanName ("MutateRows" );
649
653
@@ -654,9 +658,7 @@ private UnaryCallable<BulkMutation, Void> createBulkMutateRowsCallable() {
654
658
new TracedUnaryCallable <>(
655
659
tracedBatcherUnaryCallable , clientContext .getTracerFactory (), spanName );
656
660
657
- UnaryCallable <BulkMutation , Void > withCookie = new CookiesUnaryCallable <>(traced );
658
-
659
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
661
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
660
662
}
661
663
662
664
/**
@@ -810,7 +812,7 @@ public Map<String, String> extract(
810
812
new BigtableTracerUnaryCallable <>(withStatsHeaders );
811
813
812
814
UnaryCallable <CheckAndMutateRowRequest , CheckAndMutateRowResponse > retrying =
813
- Callables . retrying (withBigtableTracer , settings .checkAndMutateRowSettings (), clientContext );
815
+ withRetries (withBigtableTracer , settings .checkAndMutateRowSettings ());
814
816
815
817
return createUserFacingUnaryCallable (
816
818
methodName , new CheckAndMutateRowCallable (retrying , requestContext ));
@@ -851,8 +853,7 @@ public Map<String, String> extract(ReadModifyWriteRowRequest request) {
851
853
new BigtableTracerUnaryCallable <>(withStatsHeaders );
852
854
853
855
UnaryCallable <ReadModifyWriteRowRequest , ReadModifyWriteRowResponse > retrying =
854
- Callables .retrying (
855
- withBigtableTracer , settings .readModifyWriteRowSettings (), clientContext );
856
+ withRetries (withBigtableTracer , settings .readModifyWriteRowSettings ());
856
857
857
858
return createUserFacingUnaryCallable (
858
859
methodName , new ReadModifyWriteRowCallable (retrying , requestContext ));
@@ -932,16 +933,13 @@ public Map<String, String> extract(
932
933
new BigtableTracerStreamingCallable <>(watched );
933
934
934
935
ServerStreamingCallable <String , ByteStringRange > retrying =
935
- Callables . retrying (withBigtableTracer , innerSettings , clientContext );
936
+ withRetries (withBigtableTracer , innerSettings );
936
937
937
938
SpanName span = getSpanName ("GenerateInitialChangeStreamPartitions" );
938
939
ServerStreamingCallable <String , ByteStringRange > traced =
939
940
new TracedServerStreamingCallable <>(retrying , clientContext .getTracerFactory (), span );
940
941
941
- ServerStreamingCallable <String , ByteStringRange > withCookie =
942
- new CookiesServerStreamingCallable <>(traced );
943
-
944
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
942
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
945
943
}
946
944
947
945
/**
@@ -1010,7 +1008,7 @@ public Map<String, String> extract(
1010
1008
new BigtableTracerStreamingCallable <>(watched );
1011
1009
1012
1010
ServerStreamingCallable <ReadChangeStreamRequest , ChangeStreamRecordT > readChangeStreamCallable =
1013
- Callables . retrying (withBigtableTracer , innerSettings , clientContext );
1011
+ withRetries (withBigtableTracer , innerSettings );
1014
1012
1015
1013
ServerStreamingCallable <ReadChangeStreamQuery , ChangeStreamRecordT >
1016
1014
readChangeStreamUserCallable =
@@ -1021,10 +1019,7 @@ public Map<String, String> extract(
1021
1019
new TracedServerStreamingCallable <>(
1022
1020
readChangeStreamUserCallable , clientContext .getTracerFactory (), span );
1023
1021
1024
- ServerStreamingCallable <ReadChangeStreamQuery , ChangeStreamRecordT > withCookie =
1025
- new CookiesServerStreamingCallable <>(traced );
1026
-
1027
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
1022
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
1028
1023
}
1029
1024
1030
1025
/**
@@ -1037,11 +1032,7 @@ private <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUserFacin
1037
1032
UnaryCallable <RequestT , ResponseT > traced =
1038
1033
new TracedUnaryCallable <>(inner , clientContext .getTracerFactory (), getSpanName (methodName ));
1039
1034
1040
- // CookieHolder needs to be injected to the CallOptions outside of retries, otherwise retry
1041
- // attempts won't see a CookieHolder.
1042
- UnaryCallable <RequestT , ResponseT > withCookie = new CookiesUnaryCallable <>(traced );
1043
-
1044
- return withCookie .withDefaultCallContext (clientContext .getDefaultCallContext ());
1035
+ return traced .withDefaultCallContext (clientContext .getDefaultCallContext ());
1045
1036
}
1046
1037
1047
1038
private UnaryCallable <PingAndWarmRequest , PingAndWarmResponse > createPingAndWarmCallable () {
@@ -1062,6 +1053,27 @@ public Map<String, String> extract(PingAndWarmRequest request) {
1062
1053
Collections .emptySet ());
1063
1054
return pingAndWarm .withDefaultCallContext (clientContext .getDefaultCallContext ());
1064
1055
}
1056
+
1057
+ private <RequestT , ResponseT > UnaryCallable <RequestT , ResponseT > withRetries (
1058
+ UnaryCallable <RequestT , ResponseT > innerCallable , UnaryCallSettings <?, ?> unaryCallSettings ) {
1059
+ UnaryCallable <RequestT , ResponseT > retrying =
1060
+ Callables .retrying (innerCallable , unaryCallSettings , clientContext );
1061
+ if (settings .getEnableRoutingCookie ()) {
1062
+ return new CookiesUnaryCallable <>(retrying );
1063
+ }
1064
+ return retrying ;
1065
+ }
1066
+
1067
+ private <RequestT , ResponseT > ServerStreamingCallable <RequestT , ResponseT > withRetries (
1068
+ ServerStreamingCallable <RequestT , ResponseT > innerCallable ,
1069
+ ServerStreamingCallSettings <RequestT , ResponseT > serverStreamingCallSettings ) {
1070
+ ServerStreamingCallable <RequestT , ResponseT > retrying =
1071
+ Callables .retrying (innerCallable , serverStreamingCallSettings , clientContext );
1072
+ if (settings .getEnableRoutingCookie ()) {
1073
+ return new CookiesServerStreamingCallable <>(retrying );
1074
+ }
1075
+ return retrying ;
1076
+ }
1065
1077
// </editor-fold>
1066
1078
1067
1079
// <editor-fold desc="Callable accessors">
0 commit comments