Skip to content

Commit 3da6837

Browse files
committed
revert changes and add transactionTag option
1 parent 4fa9b28 commit 3da6837

File tree

11 files changed

+55
-101
lines changed

11 files changed

+55
-101
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,5 @@
790790
<className>com/google/cloud/spanner/connection/Connection</className>
791791
<method>boolean isAutoBatchDmlUpdateCountVerification()</method>
792792
</difference>
793-
<difference>
794-
<differenceType>7012</differenceType>
795-
<className>com/google/cloud/spanner/DatabaseClient</className>
796-
<method>long executePartitionedUpdate(com.google.cloud.spanner.Statement, java.lang.String, com.google.cloud.spanner.Options$UpdateOption[])</method>
797-
</difference>
793+
798794
</differences>

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.cloud.spanner.Options.TransactionOption;
2222
import com.google.cloud.spanner.Options.UpdateOption;
2323
import com.google.spanner.v1.BatchWriteResponse;
24-
import javax.annotation.Nullable;
2524

2625
/**
2726
* Base class for the Multiplexed Session {@link DatabaseClient} implementation. Throws {@link
@@ -57,10 +56,4 @@ public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
5756
public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
5857
throw new UnsupportedOperationException();
5958
}
60-
61-
@Override
62-
public long executePartitionedUpdate(
63-
Statement stmt, @Nullable String transactionTag, UpdateOption... options) {
64-
throw new UnsupportedOperationException();
65-
}
6659
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.cloud.spanner.Options.TransactionOption;
2323
import com.google.cloud.spanner.Options.UpdateOption;
2424
import com.google.spanner.v1.BatchWriteResponse;
25-
import javax.annotation.Nullable;
2625

2726
/**
2827
* Interface for all the APIs that are used to read/write data into a Cloud Spanner database. An
@@ -602,21 +601,4 @@ ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
602601
* idempotent, such as deleting old rows from a very large table.
603602
*/
604603
long executePartitionedUpdate(Statement stmt, UpdateOption... options);
605-
606-
/**
607-
* Executes a Partitioned DML statement with the specified transaction tag.
608-
*
609-
* <p>This method has the same behavior as {@link #executePartitionedUpdate(Statement,
610-
* UpdateOption...)} but allows specifying a transaction tag that will be applied to all
611-
* partitioned operations.
612-
*
613-
* @param stmt The Partitioned DML statement to execute
614-
* @param transactionTag The transaction tag to apply to all partitioned operations. The tag must
615-
* be a printable string (ASCII 32-126) with maximum length of 50 characters.
616-
* @param options The options to use for the update operation
617-
* @return The total number of rows modified by the statement
618-
* @throws SpannerException if the operation failed
619-
*/
620-
long executePartitionedUpdate(
621-
Statement stmt, @Nullable String transactionTag, UpdateOption... options);
622604
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,21 +309,9 @@ public AsyncTransactionManager transactionManagerAsync(TransactionOption... opti
309309

310310
@Override
311311
public long executePartitionedUpdate(final Statement stmt, final UpdateOption... options) {
312-
return executePartitionedUpdateWithOptions(stmt, null, options);
313-
}
314-
315-
@Override
316-
public long executePartitionedUpdate(
317-
final Statement stmt, @Nullable String transactionTag, final UpdateOption... options) {
318-
return executePartitionedUpdateWithOptions(stmt, transactionTag, options);
319-
}
320-
321-
private long executePartitionedUpdateWithOptions(
322-
final Statement stmt, @Nullable String transactionTag, final UpdateOption... options) {
323312
ISpan span = tracer.spanBuilder(PARTITION_DML_TRANSACTION);
324313
try (IScope s = tracer.withSpan(span)) {
325-
return runWithSessionRetry(
326-
session -> session.executePartitionedUpdate(stmt, transactionTag, options));
314+
return runWithSessionRetry(session -> session.executePartitionedUpdate(stmt, options));
327315
} catch (RuntimeException e) {
328316
span.setStatus(e);
329317
span.end();

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ public static ReadQueryUpdateTransactionOption tag(String name) {
197197
return new TagOption(name);
198198
}
199199

200+
public static ReadQueryUpdateTransactionOption transactionTag(String name) {
201+
return new TransactionTagOption(name);
202+
}
203+
200204
/**
201205
* Specifying this will cause the list operations to fetch at most this many records in a page.
202206
*/
@@ -394,6 +398,24 @@ void appendToOptions(Options options) {
394398
}
395399
}
396400

401+
static final class TransactionTagOption extends InternalOption
402+
implements ReadQueryUpdateTransactionOption {
403+
private final String transactionTag;
404+
405+
TransactionTagOption(String transactionTag) {
406+
this.transactionTag = transactionTag;
407+
}
408+
409+
String getTransactionTag() {
410+
return transactionTag;
411+
}
412+
413+
@Override
414+
void appendToOptions(Options options) {
415+
options.transactionTag = transactionTag;
416+
}
417+
}
418+
397419
static final class EtagOption extends InternalOption implements DeleteAdminApiOption {
398420
private final String etag;
399421

@@ -462,6 +484,7 @@ void appendToOptions(Options options) {
462484
private RpcPriority priority;
463485
private String tag;
464486
private String etag;
487+
private String transactionTag;
465488
private Boolean validateOnly;
466489
private Boolean withOptimisticLock;
467490
private Boolean withExcludeTxnFromChangeStreams;
@@ -545,6 +568,14 @@ boolean hasTag() {
545568
return tag != null;
546569
}
547570

571+
boolean hasTransactionTag() {
572+
return transactionTag != null;
573+
}
574+
575+
String transactionTag() {
576+
return transactionTag;
577+
}
578+
548579
String tag() {
549580
return tag;
550581
}
@@ -661,6 +692,9 @@ public String toString() {
661692
if (orderBy != null) {
662693
b.append("orderBy: ").append(orderBy).append(' ');
663694
}
695+
if (transactionTag != null) {
696+
b.append("transactionTag: ").append(transactionTag).append(' ');
697+
}
664698
return b.toString();
665699
}
666700

@@ -694,6 +728,7 @@ public boolean equals(Object o) {
694728
&& Objects.equals(filter(), that.filter())
695729
&& Objects.equals(priority(), that.priority())
696730
&& Objects.equals(tag(), that.tag())
731+
&& Objects.equals(transactionTag, that.transactionTag)
697732
&& Objects.equals(etag(), that.etag())
698733
&& Objects.equals(validateOnly(), that.validateOnly())
699734
&& Objects.equals(withOptimisticLock(), that.withOptimisticLock())
@@ -760,6 +795,9 @@ public int hashCode() {
760795
if (orderBy != null) {
761796
result = 31 * result + orderBy.hashCode();
762797
}
798+
if (transactionTag != null) {
799+
result = 31 * result + transactionTag.hashCode();
800+
}
763801
return result;
764802
}
765803

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.concurrent.TimeUnit;
4444
import java.util.logging.Level;
4545
import java.util.logging.Logger;
46-
import javax.annotation.Nullable;
4746
import org.threeten.bp.Duration;
4847
import org.threeten.bp.temporal.ChronoUnit;
4948

@@ -55,16 +54,13 @@ public class PartitionedDmlTransaction implements SessionImpl.SessionTransaction
5554
private final SessionImpl session;
5655
private final SpannerRpc rpc;
5756
private final Ticker ticker;
58-
private final @Nullable String transactionTag;
5957
private final IsRetryableInternalError isRetryableInternalErrorPredicate;
6058
private volatile boolean isValid = true;
6159

62-
PartitionedDmlTransaction(
63-
SessionImpl session, SpannerRpc rpc, Ticker ticker, @Nullable String transactionTag) {
60+
PartitionedDmlTransaction(SessionImpl session, SpannerRpc rpc, Ticker ticker) {
6461
this.session = session;
6562
this.rpc = rpc;
6663
this.ticker = ticker;
67-
this.transactionTag = transactionTag;
6864
this.isRetryableInternalErrorPredicate = new IsRetryableInternalError();
6965
}
7066

@@ -198,8 +194,8 @@ ExecuteSqlRequest newTransactionRequestFrom(final Statement statement, final Opt
198194
if (options.hasTag()) {
199195
requestOptionsBuilder.setRequestTag(options.tag());
200196
}
201-
if (transactionTag != null) {
202-
requestOptionsBuilder.setTransactionTag(transactionTag);
197+
if (options.hasTransactionTag()) {
198+
requestOptionsBuilder.setTransactionTag(options.transactionTag());
203199
}
204200
builder.setRequestOptions(requestOptionsBuilder.build());
205201
}
@@ -216,9 +212,9 @@ private ByteString initTransaction(final Options options) {
216212
.setExcludeTxnFromChangeStreams(
217213
options.withExcludeTxnFromChangeStreams() == Boolean.TRUE));
218214

219-
if (transactionTag != null) {
215+
if (options.hasTransactionTag()) {
220216
builder.setRequestOptions(
221-
RequestOptions.newBuilder().setTransactionTag(transactionTag).build());
217+
RequestOptions.newBuilder().setTransactionTag(options.transactionTag()).build());
222218
}
223219
Transaction tx = rpc.beginTransaction(builder.build(), session.getOptions(), true);
224220
if (tx.getId().isEmpty()) {

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,7 @@ public DatabaseId getDatabaseId() {
201201
public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
202202
setActive(null);
203203
PartitionedDmlTransaction txn =
204-
new PartitionedDmlTransaction(this, spanner.getRpc(), Ticker.systemTicker(), null);
205-
return txn.executeStreamingPartitionedUpdate(
206-
stmt, spanner.getOptions().getPartitionedDmlTimeout(), options);
207-
}
208-
209-
@Override
210-
public long executePartitionedUpdate(
211-
Statement stmt, @Nullable String transactionTag, UpdateOption... options) {
212-
setActive(null);
213-
PartitionedDmlTransaction txn =
214-
new PartitionedDmlTransaction(
215-
this, spanner.getRpc(), Ticker.systemTicker(), transactionTag);
204+
new PartitionedDmlTransaction(this, spanner.getRpc(), Ticker.systemTicker());
216205
return txn.executeStreamingPartitionedUpdate(
217206
stmt, spanner.getOptions().getPartitionedDmlTimeout(), options);
218207
}

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,6 @@ default AsyncTransactionManager transactionManagerAsync(TransactionOption... opt
12731273
default long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
12741274
return get().executePartitionedUpdate(stmt, options);
12751275
}
1276-
1277-
default long executePartitionedUpdate(
1278-
Statement stmt, @Nullable String transactionTag, UpdateOption... options) {
1279-
return get().executePartitionedUpdate(stmt, transactionTag, options);
1280-
}
12811276
}
12821277

12831278
class PooledSessionFutureWrapper implements SessionFutureWrapper<PooledSessionFuture> {
@@ -1499,16 +1494,6 @@ public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
14991494
}
15001495
}
15011496

1502-
@Override
1503-
public long executePartitionedUpdate(
1504-
Statement stmt, @Nullable String transactionTag, UpdateOption... options) {
1505-
try {
1506-
return get(true).executePartitionedUpdate(stmt, transactionTag, options);
1507-
} finally {
1508-
close();
1509-
}
1510-
}
1511-
15121497
@Override
15131498
public String getName() {
15141499
return get().getName();
@@ -1724,18 +1709,6 @@ public long executePartitionedUpdate(Statement stmt, UpdateOption... options)
17241709
}
17251710
}
17261711

1727-
@Override
1728-
public long executePartitionedUpdate(
1729-
Statement stmt, @Nullable String transactionTag, UpdateOption... options)
1730-
throws SpannerException {
1731-
try {
1732-
markUsed();
1733-
return delegate.executePartitionedUpdate(stmt, transactionTag, options);
1734-
} catch (SpannerException e) {
1735-
throw lastException = e;
1736-
}
1737-
}
1738-
17391712
@Override
17401713
public ReadContext singleUse() {
17411714
return delegate.singleUse();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,9 @@ public void testPartitionedDMLWithTransactionTag() {
19491949
DatabaseClient client =
19501950
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
19511951
client.executePartitionedUpdate(
1952-
UPDATE_STATEMENT, "testTransactionTag", Options.tag("app=spanner,env=test,action=dml"));
1952+
UPDATE_STATEMENT,
1953+
Options.transactionTag("testTransactionTag"),
1954+
Options.tag("app=spanner,env=test,action=dml"));
19531955

19541956
List<BeginTransactionRequest> beginTransactions =
19551957
mockSpanner.getRequestsOfType(BeginTransactionRequest.class);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void setup() {
101101
when(rpc.beginTransaction(any(BeginTransactionRequest.class), anyMap(), eq(true)))
102102
.thenReturn(Transaction.newBuilder().setId(txId).build());
103103

104-
tx = new PartitionedDmlTransaction(session, rpc, ticker, null);
104+
tx = new PartitionedDmlTransaction(session, rpc, ticker);
105105
}
106106

107107
@Test
@@ -332,7 +332,7 @@ public void testExecuteStreamingPartitionedUpdateUnexpectedEOS() {
332332
Mockito.eq(executeRequestWithResumeToken), anyMap(), any(Duration.class)))
333333
.thenReturn(stream2);
334334

335-
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker, null);
335+
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker);
336336
long count = tx.executeStreamingPartitionedUpdate(Statement.of(sql), Duration.ofMinutes(10));
337337

338338
assertThat(count).isEqualTo(1000L);
@@ -371,7 +371,7 @@ public void testExecuteStreamingPartitionedUpdateRSTstream() {
371371
Mockito.eq(executeRequestWithResumeToken), anyMap(), any(Duration.class)))
372372
.thenReturn(stream2);
373373

374-
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker, null);
374+
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker);
375375
long count = tx.executeStreamingPartitionedUpdate(Statement.of(sql), Duration.ofMinutes(10));
376376

377377
assertThat(count).isEqualTo(1000L);
@@ -400,7 +400,7 @@ public void testExecuteStreamingPartitionedUpdateGenericInternalException() {
400400
Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class)))
401401
.thenReturn(stream1);
402402

403-
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker, null);
403+
PartitionedDmlTransaction tx = new PartitionedDmlTransaction(session, rpc, ticker);
404404
SpannerException e =
405405
assertThrows(
406406
SpannerException.class,

0 commit comments

Comments
 (0)