Skip to content

Commit 5ce6a88

Browse files
Merge branch 'main' into generate-libraries-main
2 parents d11d7cb + 5783116 commit 5ce6a88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1644
-23
lines changed

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,38 @@
566566
<method>java.util.List getFloat32Array()</method>
567567
</difference>
568568

569+
<!-- UUID -->
570+
<difference>
571+
<differenceType>7012</differenceType>
572+
<className>com/google/cloud/spanner/StructReader</className>
573+
<method>java.util.UUID getUuid(int)</method>
574+
</difference>
575+
<difference>
576+
<differenceType>7012</differenceType>
577+
<className>com/google/cloud/spanner/StructReader</className>
578+
<method>java.util.UUID getUuid(java.lang.String)</method>
579+
</difference>
580+
<difference>
581+
<differenceType>7012</differenceType>
582+
<className>com/google/cloud/spanner/StructReader</className>
583+
<method>java.util.List getUuidList(int)</method>
584+
</difference>
585+
<difference>
586+
<differenceType>7012</differenceType>
587+
<className>com/google/cloud/spanner/StructReader</className>
588+
<method>java.util.List getUuidList(java.lang.String)</method>
589+
</difference>
590+
<difference>
591+
<differenceType>7013</differenceType>
592+
<className>com/google/cloud/spanner/Value</className>
593+
<method>java.util.UUID getUuid()</method>
594+
</difference>
595+
<difference>
596+
<differenceType>7013</differenceType>
597+
<className>com/google/cloud/spanner/Value</className>
598+
<method>java.util.List getUuidArray()</method>
599+
</difference>
600+
569601
<!-- INTERVAL -->
570602
<difference>
571603
<differenceType>7012</differenceType>
@@ -964,4 +996,16 @@
964996
<className>com/google/cloud/spanner/DatabaseClient</className>
965997
<method>com.google.cloud.spanner.Statement$StatementFactory getStatementFactory()</method>
966998
</difference>
999+
1000+
<!-- Add method begin() with AbortedException in TransactionManager and AsyncTransactionManager -->
1001+
<difference>
1002+
<differenceType>7012</differenceType>
1003+
<className>com/google/cloud/spanner/AsyncTransactionManager</className>
1004+
<method>com.google.cloud.spanner.AsyncTransactionManager$TransactionContextFuture beginAsync(com.google.cloud.spanner.AbortedException)</method>
1005+
</difference>
1006+
<difference>
1007+
<differenceType>7012</differenceType>
1008+
<className>com/google/cloud/spanner/TransactionManager</className>
1009+
<method>com.google.cloud.spanner.TransactionContext begin(com.google.cloud.spanner.AbortedException)</method>
1010+
</difference>
9671011
</differences>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbortedException.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.spanner;
1818

1919
import com.google.api.gax.rpc.ApiException;
20+
import com.google.protobuf.ByteString;
2021
import javax.annotation.Nullable;
2122

2223
/**
@@ -32,6 +33,8 @@ public class AbortedException extends SpannerException {
3233
*/
3334
private static final boolean IS_RETRYABLE = false;
3435

36+
private ByteString transactionID;
37+
3538
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3639
AbortedException(
3740
DoNotConstructDirectly token, @Nullable String message, @Nullable Throwable cause) {
@@ -46,6 +49,9 @@ public class AbortedException extends SpannerException {
4649
@Nullable ApiException apiException,
4750
@Nullable XGoogSpannerRequestId reqId) {
4851
super(token, ErrorCode.ABORTED, IS_RETRYABLE, message, cause, apiException, reqId);
52+
if (cause instanceof AbortedException) {
53+
this.transactionID = ((AbortedException) cause).getTransactionID();
54+
}
4955
}
5056

5157
/**
@@ -55,4 +61,12 @@ public class AbortedException extends SpannerException {
5561
public boolean isEmulatorOnlySupportsOneTransactionException() {
5662
return getMessage().endsWith("The emulator only supports one transaction at a time.");
5763
}
64+
65+
void setTransactionID(ByteString transactionID) {
66+
this.transactionID = transactionID;
67+
}
68+
69+
ByteString getTransactionID() {
70+
return this.transactionID;
71+
}
5872
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractResultSet.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Iterator;
3939
import java.util.List;
4040
import java.util.Objects;
41+
import java.util.UUID;
4142
import java.util.function.Function;
4243
import javax.annotation.Nonnull;
4344
import javax.annotation.Nullable;
@@ -434,6 +435,11 @@ protected Date getDateInternal(int columnIndex) {
434435
return currRow().getDateInternal(columnIndex);
435436
}
436437

438+
@Override
439+
protected UUID getUuidInternal(int columnIndex) {
440+
return currRow().getUuidInternal(columnIndex);
441+
}
442+
437443
@Override
438444
protected Interval getIntervalInternal(int columnIndex) {
439445
return currRow().getIntervalInternal(columnIndex);
@@ -531,6 +537,11 @@ protected List<Date> getDateListInternal(int columnIndex) {
531537
return currRow().getDateListInternal(columnIndex);
532538
}
533539

540+
@Override
541+
protected List<UUID> getUuidListInternal(int columnIndex) {
542+
return currRow().getUuidListInternal(columnIndex);
543+
}
544+
534545
@Override
535546
protected List<Interval> getIntervalListInternal(int columnIndex) {
536547
return currRow().getIntervalListInternal(columnIndex);

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Arrays;
2929
import java.util.Collections;
3030
import java.util.List;
31+
import java.util.UUID;
3132
import java.util.function.Function;
3233

3334
/**
@@ -67,6 +68,10 @@ protected String getPgJsonbInternal(int columnIndex) {
6768

6869
protected abstract Date getDateInternal(int columnIndex);
6970

71+
protected UUID getUuidInternal(int columnIndex) {
72+
throw new UnsupportedOperationException("Not implemented");
73+
}
74+
7075
protected Interval getIntervalInternal(int columnIndex) {
7176
throw new UnsupportedOperationException("Not implemented");
7277
}
@@ -132,6 +137,10 @@ protected List<String> getPgJsonbListInternal(int columnIndex) {
132137

133138
protected abstract List<Date> getDateListInternal(int columnIndex);
134139

140+
protected List<UUID> getUuidListInternal(int columnIndex) {
141+
throw new UnsupportedOperationException("Not implemented");
142+
}
143+
135144
protected List<Interval> getIntervalListInternal(int columnIndex) {
136145
throw new UnsupportedOperationException("Not implemented");
137146
}
@@ -307,6 +316,19 @@ public Date getDate(String columnName) {
307316
return getDateInternal(columnIndex);
308317
}
309318

319+
@Override
320+
public UUID getUuid(int columnIndex) {
321+
checkNonNullOfType(columnIndex, Type.uuid(), columnIndex);
322+
return getUuidInternal(columnIndex);
323+
}
324+
325+
@Override
326+
public UUID getUuid(String columnName) {
327+
final int columnIndex = getColumnIndex(columnName);
328+
checkNonNullOfType(columnIndex, Type.uuid(), columnName);
329+
return getUuidInternal(columnIndex);
330+
}
331+
310332
@Override
311333
public Interval getInterval(int columnIndex) {
312334
checkNonNullOfType(columnIndex, Type.interval(), columnIndex);
@@ -604,6 +626,19 @@ public List<Date> getDateList(String columnName) {
604626
return getDateListInternal(columnIndex);
605627
}
606628

629+
@Override
630+
public List<UUID> getUuidList(int columnIndex) {
631+
checkNonNullOfType(columnIndex, Type.array(Type.uuid()), columnIndex);
632+
return getUuidListInternal(columnIndex);
633+
}
634+
635+
@Override
636+
public List<UUID> getUuidList(String columnName) {
637+
final int columnIndex = getColumnIndex(columnName);
638+
checkNonNullOfType(columnIndex, Type.array(Type.uuid()), columnName);
639+
return getUuidListInternal(columnIndex);
640+
}
641+
607642
@Override
608643
public List<Interval> getIntervalList(int columnIndex) {
609644
checkNonNullOfType(columnIndex, Type.array(Type.interval()), columnIndex);

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ interface AsyncTransactionFunction<I, O> {
170170
*/
171171
TransactionContextFuture beginAsync();
172172

173+
/**
174+
* Initializes a new read-write transaction that is a retry of a previously aborted transaction.
175+
* This method must be called before performing any operations, and it can only be invoked once
176+
* per transaction lifecycle.
177+
*
178+
* <p>This method should only be used when multiplexed sessions are enabled to create a retry for
179+
* a previously aborted transaction. This method can be used instead of {@link
180+
* #resetForRetryAsync()} to create a retry. Using this method or {@link #resetForRetryAsync()}
181+
* will have the same effect. You must pass in the {@link AbortedException} from the previous
182+
* attempt to preserve the transaction's priority.
183+
*
184+
* <p>For regular sessions, this behaves the same as {@link #beginAsync()}.
185+
*/
186+
TransactionContextFuture beginAsync(AbortedException exception);
187+
173188
/**
174189
* Rolls back the currently active transaction. In most cases there should be no need to call this
175190
* explicitly since {@link #close()} would automatically roll back any active transaction.

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManagerImpl.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,27 @@ public ApiFuture<Void> closeAsync() {
7676
@Override
7777
public TransactionContextFutureImpl beginAsync() {
7878
Preconditions.checkState(txn == null, "begin can only be called once");
79-
return new TransactionContextFutureImpl(this, internalBeginAsync(true));
79+
return new TransactionContextFutureImpl(this, internalBeginAsync(true, ByteString.EMPTY));
8080
}
8181

82-
private ApiFuture<TransactionContext> internalBeginAsync(boolean firstAttempt) {
82+
@Override
83+
public TransactionContextFutureImpl beginAsync(AbortedException exception) {
84+
Preconditions.checkState(txn == null, "begin can only be called once");
85+
Preconditions.checkNotNull(exception, "AbortedException from the previous attempt is required");
86+
ByteString abortedTransactionId =
87+
exception.getTransactionID() != null ? exception.getTransactionID() : ByteString.EMPTY;
88+
return new TransactionContextFutureImpl(this, internalBeginAsync(true, abortedTransactionId));
89+
}
90+
91+
private ApiFuture<TransactionContext> internalBeginAsync(
92+
boolean firstAttempt, ByteString abortedTransactionID) {
8393
txnState = TransactionState.STARTED;
8494

8595
// Determine the latest transactionId when using a multiplexed session.
8696
ByteString multiplexedSessionPreviousTransactionId = ByteString.EMPTY;
97+
if (firstAttempt && session.getIsMultiplexed()) {
98+
multiplexedSessionPreviousTransactionId = abortedTransactionID;
99+
}
87100
if (txn != null && session.getIsMultiplexed() && !firstAttempt) {
88101
// Use the current transactionId if available, otherwise fallback to the previous aborted
89102
// transactionId.
@@ -187,7 +200,7 @@ public TransactionContextFuture resetForRetryAsync() {
187200
throw new IllegalStateException(
188201
"resetForRetry can only be called if the previous attempt aborted");
189202
}
190-
return new TransactionContextFutureImpl(this, internalBeginAsync(false));
203+
return new TransactionContextFutureImpl(this, internalBeginAsync(false, ByteString.EMPTY));
191204
}
192205

193206
@Override

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedAsyncTransactionManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public TransactionContextFuture beginAsync() {
5050
return getAsyncTransactionManager().beginAsync();
5151
}
5252

53+
@Override
54+
public TransactionContextFuture beginAsync(AbortedException exception) {
55+
return getAsyncTransactionManager().beginAsync(exception);
56+
}
57+
5358
@Override
5459
public ApiFuture<Void> rollbackAsync() {
5560
return getAsyncTransactionManager().rollbackAsync();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedTransactionManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public TransactionContext begin() {
4949
return getTransactionManager().begin();
5050
}
5151

52+
@Override
53+
public TransactionContext begin(AbortedException exception) {
54+
return getTransactionManager().begin(exception);
55+
}
56+
5257
@Override
5358
public void commit() {
5459
getTransactionManager().commit();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingStructReader.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.protobuf.ProtocolMessageEnum;
2727
import java.math.BigDecimal;
2828
import java.util.List;
29+
import java.util.UUID;
2930
import java.util.function.Function;
3031

3132
/** Forwarding implements of StructReader */
@@ -231,6 +232,18 @@ public Date getDate(String columnName) {
231232
return delegate.get().getDate(columnName);
232233
}
233234

235+
@Override
236+
public UUID getUuid(int columnIndex) {
237+
checkValidState();
238+
return delegate.get().getUuid(columnIndex);
239+
}
240+
241+
@Override
242+
public UUID getUuid(String columnName) {
243+
checkValidState();
244+
return delegate.get().getUuid(columnName);
245+
}
246+
234247
@Override
235248
public Interval getInterval(int columnIndex) {
236249
checkValidState();
@@ -421,6 +434,18 @@ public List<Date> getDateList(String columnName) {
421434
return delegate.get().getDateList(columnName);
422435
}
423436

437+
@Override
438+
public List<UUID> getUuidList(int columnIndex) {
439+
checkValidState();
440+
return delegate.get().getUuidList(columnIndex);
441+
}
442+
443+
@Override
444+
public List<UUID> getUuidList(String columnName) {
445+
checkValidState();
446+
return delegate.get().getUuidList(columnName);
447+
}
448+
424449
@Override
425450
public List<Interval> getIntervalList(int columnIndex) {
426451
checkValidState();

0 commit comments

Comments
 (0)