Given the above, Partitioned DML is good fit for large, database-wide, operations that are
* idempotent, such as deleting old rows from a very large table.
*/
- long executePartitionedUpdate(Statement stmt, UpdateOption... options);
+ long executePartitionedUpdate(Statement stmt, PartitionedUpdateOption... options);
}
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java
index b63ad379305..f19d492b492 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java
@@ -18,8 +18,8 @@
import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.Timestamp;
+import com.google.cloud.spanner.Options.PartitionedUpdateOption;
import com.google.cloud.spanner.Options.TransactionOption;
-import com.google.cloud.spanner.Options.UpdateOption;
import com.google.cloud.spanner.SessionPool.PooledSessionFuture;
import com.google.cloud.spanner.SpannerImpl.ClosedException;
import com.google.common.annotations.VisibleForTesting;
@@ -240,7 +240,8 @@ public AsyncTransactionManager transactionManagerAsync(TransactionOption... opti
}
@Override
- public long executePartitionedUpdate(final Statement stmt, final UpdateOption... options) {
+ public long executePartitionedUpdate(
+ final Statement stmt, final PartitionedUpdateOption... options) {
ISpan span = tracer.spanBuilder(PARTITION_DML_TRANSACTION);
try (IScope s = tracer.withSpan(span)) {
return runWithSessionRetry(session -> session.executePartitionedUpdate(stmt, options));
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java
index 3dbd0c1cda3..ca60eea4c96 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java
@@ -61,9 +61,6 @@ public interface ReadOption {}
public interface ReadQueryUpdateTransactionOption
extends ReadOption, QueryOption, UpdateOption, TransactionOption {}
- /** Marker interface to mark options applicable to Update and Write operations */
- public interface UpdateTransactionOption extends UpdateOption, TransactionOption {}
-
/**
* Marker interface to mark options applicable to Create, Update and Delete operations in admin
* API.
@@ -86,8 +83,15 @@ public interface QueryOption {}
/** Marker interface to mark options applicable to write operations */
public interface TransactionOption {}
+ /** Marker interface to mark options applicable to partitioned update */
+ public interface PartitionedUpdateOption {}
+
/** Marker interface to mark options applicable to update operation. */
- public interface UpdateOption {}
+ public interface UpdateOption extends PartitionedUpdateOption {}
+
+ /** Marker interface to mark options applicable to partitioned update and write operations */
+ public interface PartitionedUpdateTransactionOption
+ extends PartitionedUpdateOption, TransactionOption {}
/** Marker interface to mark options applicable to list operations in admin API. */
public interface ListOption {}
@@ -118,7 +122,7 @@ public static TransactionOption optimisticLock() {
* being recorded in the change streams with the DDL option `allow_txn_exclusion` being false or
* unset.
*/
- public static UpdateTransactionOption excludeTxnFromChangeStreams() {
+ public static PartitionedUpdateTransactionOption excludeTxnFromChangeStreams() {
return EXCLUDE_TXN_FROM_CHANGE_STREAMS_OPTION;
}
@@ -297,7 +301,7 @@ void appendToOptions(Options options) {
/** Option to request the transaction to be excluded from change streams. */
static final class ExcludeTxnFromChangeStreamsOption extends InternalOption
- implements UpdateTransactionOption {
+ implements PartitionedUpdateTransactionOption {
@Override
void appendToOptions(Options options) {
options.withExcludeTxnFromChangeStreams = true;
@@ -744,6 +748,16 @@ static Options fromUpdateOptions(UpdateOption... options) {
return updateOptions;
}
+ static Options fromPartitinoedUpdateOptions(PartitionedUpdateOption... options) {
+ Options partitionedUpdateOptions = new Options();
+ for (PartitionedUpdateOption option : options) {
+ if (option instanceof InternalOption) {
+ ((InternalOption) option).appendToOptions(partitionedUpdateOptions);
+ }
+ }
+ return partitionedUpdateOptions;
+ }
+
static Options fromTransactionOptions(TransactionOption... options) {
Options transactionOptions = new Options();
for (TransactionOption option : options) {
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java
index d498bb232a1..c811cedb845 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java
@@ -25,7 +25,7 @@
import com.google.api.gax.rpc.InternalException;
import com.google.api.gax.rpc.ServerStream;
import com.google.api.gax.rpc.UnavailableException;
-import com.google.cloud.spanner.Options.UpdateOption;
+import com.google.cloud.spanner.Options.PartitionedUpdateOption;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
@@ -71,7 +71,9 @@ public class PartitionedDmlTransaction implements SessionImpl.SessionTransaction
* last seen resume token if the server returns any.
*/
long executeStreamingPartitionedUpdate(
- final Statement statement, final Duration timeout, final UpdateOption... updateOptions) {
+ final Statement statement,
+ final Duration timeout,
+ final PartitionedUpdateOption... partitionedUpdateOptions) {
checkState(isValid, "Partitioned DML has been invalidated by a new operation on the session");
LOGGER.log(Level.FINER, "Starting PartitionedUpdate statement");
@@ -79,7 +81,7 @@ long executeStreamingPartitionedUpdate(
boolean foundStats = false;
long updateCount = 0L;
Stopwatch stopwatch = Stopwatch.createStarted(ticker);
- Options options = Options.fromUpdateOptions(updateOptions);
+ Options options = Options.fromPartitinoedUpdateOptions(partitionedUpdateOptions);
try {
ExecuteSqlRequest request = newTransactionRequestFrom(statement, options);
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java
index 83ee2812721..215b16f5bfb 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java
@@ -26,8 +26,8 @@
import com.google.cloud.spanner.AbstractReadContext.MultiUseReadOnlyTransaction;
import com.google.cloud.spanner.AbstractReadContext.SingleReadContext;
import com.google.cloud.spanner.AbstractReadContext.SingleUseReadOnlyTransaction;
+import com.google.cloud.spanner.Options.PartitionedUpdateOption;
import com.google.cloud.spanner.Options.TransactionOption;
-import com.google.cloud.spanner.Options.UpdateOption;
import com.google.cloud.spanner.SessionClient.SessionId;
import com.google.cloud.spanner.TransactionRunnerImpl.TransactionContextImpl;
import com.google.cloud.spanner.spi.v1.SpannerRpc;
@@ -140,7 +140,7 @@ void markUsed(Instant instant) {
}
@Override
- public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
+ public long executePartitionedUpdate(Statement stmt, PartitionedUpdateOption... options) {
setActive(null);
PartitionedDmlTransaction txn =
new PartitionedDmlTransaction(this, spanner.getRpc(), Ticker.systemTicker());
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java
index 8058802a8fc..ec58a728c04 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java
@@ -52,6 +52,7 @@
import com.google.cloud.Tuple;
import com.google.cloud.grpc.GrpcTransportOptions;
import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
+import com.google.cloud.spanner.Options.PartitionedUpdateOption;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.Options.ReadOption;
import com.google.cloud.spanner.Options.TransactionOption;
@@ -1270,7 +1271,7 @@ public AsyncTransactionManager transactionManagerAsync(TransactionOption... opti
}
@Override
- public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
+ public long executePartitionedUpdate(Statement stmt, PartitionedUpdateOption... options) {
try {
return get(true).executePartitionedUpdate(stmt, options);
} finally {
@@ -1470,7 +1471,7 @@ public ServerStream