Skip to content

Commit 00360f0

Browse files
committed
chore(spanner): lint format
1 parent 28704e3 commit 00360f0

File tree

9 files changed

+69
-16
lines changed

9 files changed

+69
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class AbortedException extends SpannerException {
3232
* new transaction attempt) before a retry can succeed.
3333
*/
3434
private static final boolean IS_RETRYABLE = false;
35+
3536
private ByteString transactionID;
3637

3738
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,16 @@ interface AsyncTransactionFunction<I, O> {
170170
*/
171171
TransactionContextFuture beginAsync();
172172

173-
TransactionContextFuture beginAsync(AbortedException abortedException);
173+
/**
174+
* Initializes a new read-write transaction. This method must be called before performing any
175+
* operations, and it can only be invoked once per transaction lifecycle.
176+
*
177+
* <p>This is especially useful in scenarios involving multiplexed sessions and when creating a
178+
* new transaction for retry attempts. If {@link #resetForRetryAsync()} is not used, you can pass
179+
* the {@link AbortedException} from a previous attempt here to preserve the transaction's
180+
* priority.
181+
*/
182+
TransactionContextFuture beginAsync(AbortedException exception);
174183

175184
/**
176185
* Rolls back the currently active transaction. In most cases there should be no need to call this

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ public TransactionContextFutureImpl beginAsync() {
8080
}
8181

8282
@Override
83-
public TransactionContextFutureImpl beginAsync(AbortedException abortedException) {
83+
public TransactionContextFutureImpl beginAsync(AbortedException exception) {
8484
Preconditions.checkState(txn == null, "begin can only be called once");
85-
ByteString abortedTransactionId = abortedException.getTransactionID() != null ? abortedException.getTransactionID() : ByteString.EMPTY;
85+
ByteString abortedTransactionId =
86+
exception.getTransactionID() != null ? exception.getTransactionID() : ByteString.EMPTY;
8687
return new TransactionContextFutureImpl(this, internalBeginAsync(true, abortedTransactionId));
8788
}
8889

89-
private ApiFuture<TransactionContext> internalBeginAsync(boolean firstAttempt, ByteString abortedTransactionID) {
90+
private ApiFuture<TransactionContext> internalBeginAsync(
91+
boolean firstAttempt, ByteString abortedTransactionID) {
9092
txnState = TransactionState.STARTED;
9193

9294
// Determine the latest transactionId when using a multiplexed session.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public TransactionContextFuture beginAsync() {
5151
}
5252

5353
@Override
54-
public TransactionContextFuture beginAsync(AbortedException abortedException) {
55-
return getAsyncTransactionManager().beginAsync(abortedException);
54+
public TransactionContextFuture beginAsync(AbortedException exception) {
55+
return getAsyncTransactionManager().beginAsync(exception);
5656
}
5757

5858
@Override

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,8 @@ public TransactionContext begin() {
902902

903903
@Override
904904
public TransactionContext begin(AbortedException exception) {
905+
// For regular sessions, the input exception is ignored and the behavior is equivalent to
906+
// calling {@link #begin()}.
905907
return begin();
906908
}
907909

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ public void onSuccess(TransactionContext result) {
164164
}
165165

166166
@Override
167-
public TransactionContextFuture beginAsync(AbortedException abortedException) {
167+
public TransactionContextFuture beginAsync(AbortedException exception) {
168+
// For regular sessions, the input exception is ignored and the behavior is equivalent to
169+
// calling {@link #beginAsync()}.
168170
return beginAsync();
169171
}
170172

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ enum TransactionState {
6161
*/
6262
TransactionContext begin();
6363

64+
/**
65+
* Initializes a new read-write transaction. This method must be called before performing any
66+
* operations, and it can only be invoked once per transaction lifecycle.
67+
*
68+
* <p>This is especially useful in scenarios involving multiplexed sessions and when creating a
69+
* new transaction for retry attempts. If {@link #resetForRetry()} is not used, you can pass the
70+
* {@link AbortedException} from a previous attempt here to preserve the transaction's priority.
71+
*/
6472
TransactionContext begin(AbortedException exception);
6573

6674
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public TransactionContext begin() {
5959
@Override
6060
public TransactionContext begin(AbortedException exception) {
6161
Preconditions.checkState(txn == null, "begin can only be called once");
62-
ByteString previousAbortedTransactionID = exception.getTransactionID() != null ? exception.getTransactionID() : ByteString.EMPTY;
62+
ByteString previousAbortedTransactionID =
63+
exception.getTransactionID() != null ? exception.getTransactionID() : ByteString.EMPTY;
6364
return begin(previousAbortedTransactionID);
6465
}
6566

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,8 @@ public void testBatchWriteAtLeastOnce() {
21722172

21732173
@Test
21742174
public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_DuringAborted() {
2175-
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set in the AbortedException class.
2175+
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set
2176+
// in the AbortedException class.
21762177
DatabaseClientImpl client =
21772178
(DatabaseClientImpl) spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
21782179
// Force the Commit RPC to return Aborted the first time it is called. The exception is cleared
@@ -2229,17 +2230,32 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22292230
mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
22302231
assertEquals(1, executeSqlRequests.size());
22312232
assertTrue(mockSpanner.getSession(executeSqlRequests.get(0).getSession()).getMultiplexed());
2232-
assertNotNull(executeSqlRequests.get(0).getTransaction().getBegin().getReadWrite().getMultiplexedSessionPreviousTransactionId());
2233-
assertEquals(executeSqlRequests.get(0).getTransaction().getBegin().getReadWrite().getMultiplexedSessionPreviousTransactionId(), abortedTransactionID);
2233+
assertNotNull(
2234+
executeSqlRequests
2235+
.get(0)
2236+
.getTransaction()
2237+
.getBegin()
2238+
.getReadWrite()
2239+
.getMultiplexedSessionPreviousTransactionId());
2240+
assertEquals(
2241+
executeSqlRequests
2242+
.get(0)
2243+
.getTransaction()
2244+
.getBegin()
2245+
.getReadWrite()
2246+
.getMultiplexedSessionPreviousTransactionId(),
2247+
abortedTransactionID);
22342248

22352249
assertNotNull(client.multiplexedSessionDatabaseClient);
22362250
assertEquals(2L, client.multiplexedSessionDatabaseClient.getNumSessionsAcquired().get());
22372251
assertEquals(2L, client.multiplexedSessionDatabaseClient.getNumSessionsReleased().get());
22382252
}
22392253

22402254
@Test
2241-
public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_DuringAbortedInExecuteSql() {
2242-
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set in the AbortedException class.
2255+
public void
2256+
testReadWriteTransactionUsingTransactionManager_SetsTransactionID_DuringAbortedInExecuteSql() {
2257+
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set
2258+
// in the AbortedException class.
22432259
DatabaseClientImpl client =
22442260
(DatabaseClientImpl) spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
22452261

@@ -2303,9 +2319,21 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
23032319
mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
23042320
assertEquals(1, executeSqlRequests.size());
23052321
assertTrue(mockSpanner.getSession(executeSqlRequests.get(0).getSession()).getMultiplexed());
2306-
assertNotNull(executeSqlRequests.get(0).getTransaction().getBegin().getReadWrite().getMultiplexedSessionPreviousTransactionId());
2307-
assertEquals(executeSqlRequests.get(0).getTransaction().getBegin().getReadWrite().getMultiplexedSessionPreviousTransactionId(), abortedTransactionID);
2308-
2322+
assertNotNull(
2323+
executeSqlRequests
2324+
.get(0)
2325+
.getTransaction()
2326+
.getBegin()
2327+
.getReadWrite()
2328+
.getMultiplexedSessionPreviousTransactionId());
2329+
assertEquals(
2330+
executeSqlRequests
2331+
.get(0)
2332+
.getTransaction()
2333+
.getBegin()
2334+
.getReadWrite()
2335+
.getMultiplexedSessionPreviousTransactionId(),
2336+
abortedTransactionID);
23092337

23102338
assertNotNull(client.multiplexedSessionDatabaseClient);
23112339
assertEquals(2L, client.multiplexedSessionDatabaseClient.getNumSessionsAcquired().get());

0 commit comments

Comments
 (0)