102
102
import com .google .cloud .bigtable .data .v2 .stub .metrics .StatsHeadersUnaryCallable ;
103
103
import com .google .cloud .bigtable .data .v2 .stub .metrics .TracedBatcherUnaryCallable ;
104
104
import com .google .cloud .bigtable .data .v2 .stub .mutaterows .BulkMutateRowsUserFacingCallable ;
105
+ import com .google .cloud .bigtable .data .v2 .stub .mutaterows .MutateRowsAttemptResult ;
105
106
import com .google .cloud .bigtable .data .v2 .stub .mutaterows .MutateRowsBatchingDescriptor ;
107
+ import com .google .cloud .bigtable .data .v2 .stub .mutaterows .MutateRowsPartialErrorRetryAlgorithm ;
106
108
import com .google .cloud .bigtable .data .v2 .stub .mutaterows .MutateRowsRetryingCallable ;
107
109
import com .google .cloud .bigtable .data .v2 .stub .readrows .FilterMarkerRowsCallable ;
108
110
import com .google .cloud .bigtable .data .v2 .stub .readrows .ReadRowsBatchingDescriptor ;
@@ -165,7 +167,8 @@ public class EnhancedBigtableStub implements AutoCloseable {
165
167
private final UnaryCallable <Query , List <Row >> bulkReadRowsCallable ;
166
168
private final UnaryCallable <String , List <KeyOffset >> sampleRowKeysCallable ;
167
169
private final UnaryCallable <RowMutation , Void > mutateRowCallable ;
168
- private final UnaryCallable <BulkMutation , Void > bulkMutateRowsCallable ;
170
+ private final UnaryCallable <BulkMutation , MutateRowsAttemptResult > bulkMutateRowsCallable ;
171
+ private final UnaryCallable <BulkMutation , Void > externalBulkMutateRowsCallable ;
169
172
private final UnaryCallable <ConditionalRowMutation , Boolean > checkAndMutateRowCallable ;
170
173
private final UnaryCallable <ReadModifyWriteRow , Row > readModifyWriteRowCallable ;
171
174
private final UnaryCallable <PingAndWarmRequest , PingAndWarmResponse > pingAndWarmCallable ;
@@ -368,7 +371,9 @@ public EnhancedBigtableStub(
368
371
bulkReadRowsCallable = createBulkReadRowsCallable (new DefaultRowAdapter ());
369
372
sampleRowKeysCallable = createSampleRowKeysCallable ();
370
373
mutateRowCallable = createMutateRowCallable ();
371
- bulkMutateRowsCallable = createBulkMutateRowsCallable ();
374
+ bulkMutateRowsCallable = createMutateRowsBaseCallable ();
375
+ externalBulkMutateRowsCallable =
376
+ new MutateRowsErrorConverterUnaryCallable (bulkMutateRowsCallable );
372
377
checkAndMutateRowCallable = createCheckAndMutateRowCallable ();
373
378
readModifyWriteRowCallable = createReadModifyWriteRowCallable ();
374
379
generateInitialChangeStreamPartitionsCallable =
@@ -665,14 +670,24 @@ public Map<String, String> extract(MutateRowRequest mutateRowRequest) {
665
670
}
666
671
667
672
/**
668
- * Internal helper to create the base MutateRows callable chain. The chain is responsible for
669
- * retrying individual entry in case of error.
673
+ * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for manual
674
+ * batching. The chain will:
670
675
*
671
- * <p>NOTE: the caller is responsible for adding tracing & metrics.
676
+ * <ul>
677
+ * <li>Convert a {@link BulkMutation} into a {@link MutateRowsRequest}.
678
+ * <li>Process the response and schedule retries. At the end of each attempt, entries that have
679
+ * been applied, are filtered from the next attempt. Also, any entries that failed with a
680
+ * nontransient error, are filtered from the next attempt. This will continue until there
681
+ * are no more entries or there are no more retry attempts left.
682
+ * <li>Wrap batch failures in a {@link MutateRowsAttemptResult}.
683
+ * <li>Add tracing & metrics.
684
+ * </ul>
685
+ *
686
+ * This callable returns an internal type {@link MutateRowsAttemptResult}.
672
687
*
673
- * @see MutateRowsRetryingCallable for more details
688
+ * <p>This function should not be exposed to external users, as it could cause a data loss.
674
689
*/
675
- private UnaryCallable <MutateRowsRequest , Void > createMutateRowsBaseCallable () {
690
+ private UnaryCallable <BulkMutation , MutateRowsAttemptResult > createMutateRowsBaseCallable () {
676
691
ServerStreamingCallable <MutateRowsRequest , MutateRowsResponse > base =
677
692
GrpcRawCallableFactory .createServerStreamingCallable (
678
693
GrpcCallSettings .<MutateRowsRequest , MutateRowsResponse >newBuilder ()
@@ -706,55 +721,38 @@ public Map<String, String> extract(MutateRowsRequest mutateRowsRequest) {
706
721
ServerStreamingCallable <MutateRowsRequest , MutateRowsResponse > withBigtableTracer =
707
722
new BigtableTracerStreamingCallable <>(convertException );
708
723
709
- BasicResultRetryAlgorithm <Void > resultRetryAlgorithm ;
724
+ BasicResultRetryAlgorithm <MutateRowsAttemptResult > resultRetryAlgorithm ;
710
725
if (settings .getEnableRetryInfo ()) {
711
726
resultRetryAlgorithm = new RetryInfoRetryAlgorithm <>();
712
727
} else {
713
728
resultRetryAlgorithm = new ApiResultRetryAlgorithm <>();
714
729
}
730
+ MutateRowsPartialErrorRetryAlgorithm mutateRowsPartialErrorRetryAlgorithm =
731
+ new MutateRowsPartialErrorRetryAlgorithm (resultRetryAlgorithm );
715
732
716
- RetryAlgorithm <Void > retryAlgorithm =
733
+ RetryAlgorithm <MutateRowsAttemptResult > retryAlgorithm =
717
734
new RetryAlgorithm <>(
718
- resultRetryAlgorithm ,
735
+ mutateRowsPartialErrorRetryAlgorithm ,
719
736
new ExponentialRetryAlgorithm (
720
737
settings .bulkMutateRowsSettings ().getRetrySettings (), clientContext .getClock ()));
721
738
722
- RetryingExecutorWithContext <Void > retryingExecutor =
739
+ RetryingExecutorWithContext <MutateRowsAttemptResult > retryingExecutor =
723
740
new ScheduledRetryingExecutor <>(retryAlgorithm , clientContext .getExecutor ());
741
+ UnaryCallable <MutateRowsRequest , MutateRowsAttemptResult > baseCallable =
742
+ new MutateRowsRetryingCallable (
743
+ clientContext .getDefaultCallContext (),
744
+ withBigtableTracer ,
745
+ retryingExecutor ,
746
+ settings .bulkMutateRowsSettings ().getRetryableCodes (),
747
+ retryAlgorithm );
724
748
725
- return new MutateRowsRetryingCallable (
726
- clientContext .getDefaultCallContext (),
727
- withBigtableTracer ,
728
- retryingExecutor ,
729
- settings .bulkMutateRowsSettings ().getRetryableCodes (),
730
- retryAlgorithm );
731
- }
732
-
733
- /**
734
- * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for manual
735
- * batching. The chain will:
736
- *
737
- * <ul>
738
- * <li>Convert a {@link BulkMutation} into a {@link MutateRowsRequest}.
739
- * <li>Process the response and schedule retries. At the end of each attempt, entries that have
740
- * been applied, are filtered from the next attempt. Also, any entries that failed with a
741
- * nontransient error, are filtered from the next attempt. This will continue until there
742
- * are no more entries or there are no more retry attempts left.
743
- * <li>Wrap batch failures in a {@link
744
- * com.google.cloud.bigtable.data.v2.models.MutateRowsException}.
745
- * <li>Add tracing & metrics.
746
- * </ul>
747
- */
748
- private UnaryCallable <BulkMutation , Void > createBulkMutateRowsCallable () {
749
- UnaryCallable <MutateRowsRequest , Void > baseCallable = createMutateRowsBaseCallable ();
750
-
751
- UnaryCallable <MutateRowsRequest , Void > withCookie = baseCallable ;
749
+ UnaryCallable <MutateRowsRequest , MutateRowsAttemptResult > withCookie = baseCallable ;
752
750
753
751
if (settings .getEnableRoutingCookie ()) {
754
752
withCookie = new CookiesUnaryCallable <>(baseCallable );
755
753
}
756
754
757
- UnaryCallable <MutateRowsRequest , Void > flowControlCallable = null ;
755
+ UnaryCallable <MutateRowsRequest , MutateRowsAttemptResult > flowControlCallable = null ;
758
756
if (settings .bulkMutateRowsSettings ().isLatencyBasedThrottlingEnabled ()) {
759
757
flowControlCallable =
760
758
new DynamicFlowControlCallable (
@@ -764,16 +762,16 @@ private UnaryCallable<BulkMutation, Void> createBulkMutateRowsCallable() {
764
762
settings .bulkMutateRowsSettings ().getTargetRpcLatencyMs (),
765
763
FLOW_CONTROL_ADJUSTING_INTERVAL_MS );
766
764
}
767
- UnaryCallable <BulkMutation , Void > userFacing =
765
+ UnaryCallable <BulkMutation , MutateRowsAttemptResult > userFacing =
768
766
new BulkMutateRowsUserFacingCallable (
769
767
flowControlCallable != null ? flowControlCallable : withCookie , requestContext );
770
768
771
769
SpanName spanName = getSpanName ("MutateRows" );
772
770
773
- UnaryCallable <BulkMutation , Void > tracedBatcherUnaryCallable =
771
+ UnaryCallable <BulkMutation , MutateRowsAttemptResult > tracedBatcherUnaryCallable =
774
772
new TracedBatcherUnaryCallable <>(userFacing );
775
773
776
- UnaryCallable <BulkMutation , Void > traced =
774
+ UnaryCallable <BulkMutation , MutateRowsAttemptResult > traced =
777
775
new TracedUnaryCallable <>(
778
776
tracedBatcherUnaryCallable , clientContext .getTracerFactory (), spanName );
779
777
@@ -1171,10 +1169,15 @@ public UnaryCallable<RowMutation, Void> mutateRowCallable() {
1171
1169
}
1172
1170
1173
1171
/**
1174
- * Returns the callable chain created in {@link #createBulkMutateRowsCallable()} ()} during stub
1172
+ * Returns the callable chain created in {@link #createMutateRowsBaseCallable ()} during stub
1175
1173
* construction.
1176
1174
*/
1177
1175
public UnaryCallable <BulkMutation , Void > bulkMutateRowsCallable () {
1176
+ return externalBulkMutateRowsCallable ;
1177
+ }
1178
+
1179
+ @ InternalApi
1180
+ public UnaryCallable <BulkMutation , MutateRowsAttemptResult > internalBulkMutateRowsCallable () {
1178
1181
return bulkMutateRowsCallable ;
1179
1182
}
1180
1183
0 commit comments