@@ -531,7 +531,10 @@ public void onError(SpannerException e, boolean withBeginTransaction) {
|
531 | 531 | // Simulate an aborted transaction to force a retry with a new transaction.
|
532 | 532 | this.transactionIdFuture.setException(
|
533 | 533 | SpannerExceptionFactory.newSpannerException(
|
534 |
| -ErrorCode.ABORTED, "Aborted due to failed initial statement", e)); |
| 534 | +ErrorCode.ABORTED, |
| 535 | +"Aborted due to failed initial statement", |
| 536 | +SpannerExceptionFactory.createAbortedExceptionWithRetryDelay( |
| 537 | +"Aborted due to failed initial statement", e, 0, 1))); |
535 | 538 | }
|
536 | 539 |
|
537 | 540 | if (e.getErrorCode() == ErrorCode.ABORTED) {
|
@@ -684,6 +687,19 @@ public void run() {
|
684 | 687 | return updateCount;
|
685 | 688 | }
|
686 | 689 |
|
| 690 | +private SpannerException createAbortedExceptionForBatchDml(ExecuteBatchDmlResponse response) { |
| 691 | +// Manually construct an AbortedException with a 10ms retry delay for BatchDML responses that |
| 692 | +// return an Aborted status (and not an AbortedException). |
| 693 | +return newSpannerException( |
| 694 | +ErrorCode.fromRpcStatus(response.getStatus()), |
| 695 | +response.getStatus().getMessage(), |
| 696 | +SpannerExceptionFactory.createAbortedExceptionWithRetryDelay( |
| 697 | +response.getStatus().getMessage(), |
| 698 | +/* cause = */ null, |
| 699 | +/* retryDelaySeconds = */ 0, |
| 700 | +/* retryDelayNanos = */ (int) TimeUnit.MILLISECONDS.toNanos(10L))); |
| 701 | +} |
| 702 | + |
687 | 703 | @Override
|
688 | 704 | public long[] batchUpdate(Iterable<Statement> statements, UpdateOption... options) {
|
689 | 705 | beforeReadOrQuery();
|
@@ -705,8 +721,7 @@ public long[] batchUpdate(Iterable<Statement> statements, UpdateOption... option
|
705 | 721 | // If one of the DML statements was aborted, we should throw an aborted exception.
|
706 | 722 | // In all other cases, we should throw a BatchUpdateException.
|
707 | 723 | if (response.getStatus().getCode() == Code.ABORTED_VALUE) {
|
708 |
| -throw newSpannerException( |
709 |
| -ErrorCode.fromRpcStatus(response.getStatus()), response.getStatus().getMessage()); |
| 724 | +throw createAbortedExceptionForBatchDml(response); |
710 | 725 | } else if (response.getStatus().getCode() != 0) {
|
711 | 726 | throw newSpannerBatchUpdateException(
|
712 | 727 | ErrorCode.fromRpcStatus(response.getStatus()),
|
@@ -741,25 +756,24 @@ public ApiFuture<long[]> batchUpdateAsync(
|
741 | 756 | response,
|
742 | 757 | new ApiFunction<ExecuteBatchDmlResponse, long[]>() {
|
743 | 758 | @Override
|
744 |
| -public long[] apply(ExecuteBatchDmlResponse input) { |
745 |
| -long[] results = new long[input.getResultSetsCount()]; |
746 |
| -for (int i = 0; i < input.getResultSetsCount(); ++i) { |
747 |
| -results[i] = input.getResultSets(i).getStats().getRowCountExact(); |
748 |
| -if (input.getResultSets(i).getMetadata().hasTransaction()) { |
| 759 | +public long[] apply(ExecuteBatchDmlResponse batchDmlResponse) { |
| 760 | +long[] results = new long[batchDmlResponse.getResultSetsCount()]; |
| 761 | +for (int i = 0; i < batchDmlResponse.getResultSetsCount(); ++i) { |
| 762 | +results[i] = batchDmlResponse.getResultSets(i).getStats().getRowCountExact(); |
| 763 | +if (batchDmlResponse.getResultSets(i).getMetadata().hasTransaction()) { |
749 | 764 | onTransactionMetadata(
|
750 |
| -input.getResultSets(i).getMetadata().getTransaction(), |
| 765 | +batchDmlResponse.getResultSets(i).getMetadata().getTransaction(), |
751 | 766 | builder.getTransaction().hasBegin());
|
752 | 767 | }
|
753 | 768 | }
|
754 | 769 | // If one of the DML statements was aborted, we should throw an aborted exception.
|
755 | 770 | // In all other cases, we should throw a BatchUpdateException.
|
756 |
| -if (input.getStatus().getCode() == Code.ABORTED_VALUE) { |
757 |
| -throw newSpannerException( |
758 |
| -ErrorCode.fromRpcStatus(input.getStatus()), input.getStatus().getMessage()); |
759 |
| -} else if (input.getStatus().getCode() != 0) { |
| 771 | +if (batchDmlResponse.getStatus().getCode() == Code.ABORTED_VALUE) { |
| 772 | +throw createAbortedExceptionForBatchDml(batchDmlResponse); |
| 773 | +} else if (batchDmlResponse.getStatus().getCode() != 0) { |
760 | 774 | throw newSpannerBatchUpdateException(
|
761 |
| -ErrorCode.fromRpcStatus(input.getStatus()), |
762 |
| -input.getStatus().getMessage(), |
| 775 | +ErrorCode.fromRpcStatus(batchDmlResponse.getStatus()), |
| 776 | +batchDmlResponse.getStatus().getMessage(), |
763 | 777 | results);
|
764 | 778 | }
|
765 | 779 | return results;
|
|
0 commit comments