From c163907e688a5a2cf5c7d1345493c0bf8bef7379 Mon Sep 17 00:00:00 2001 From: snehashah16 Date: Thu, 27 Sep 2018 09:46:12 -0700 Subject: [PATCH] Cloud Spanner DML & PartitionedDML support (#3703) * Support for Cloud Spanner DML & PDML * Fix for DML/PDML - manual error from sync * Codacybot & Stylecheck fixes. * Fix merge conflict * PR pull/3703 fixes --- .../google/cloud/spanner/DatabaseClient.java | 49 ++- .../cloud/spanner/DatabaseClientImpl.java | 14 +- .../com/google/cloud/spanner/ResultSet.java | 13 +- .../com/google/cloud/spanner/SessionPool.java | 12 + .../com/google/cloud/spanner/SpannerImpl.java | 184 ++++++++--- .../cloud/spanner/TransactionContext.java | 7 + .../cloud/spanner/spi/v1/GrpcSpannerRpc.java | 12 + .../cloud/spanner/spi/v1/SpannerRpc.java | 3 + .../cloud/spanner/GrpcResultSetTest.java | 24 +- .../google/cloud/spanner/it/ITDMLTest.java | 298 ++++++++++++++++++ 10 files changed, 552 insertions(+), 64 deletions(-) create mode 100644 google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITDMLTest.java diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java index 3120e651feb2..969af0275fcf 100644 --- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java +++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java @@ -135,7 +135,7 @@ public interface DatabaseClient { ReadOnlyTransaction singleUseReadOnlyTransaction(); /** -   * Returns a read-only transaction context in which a single read or query can be performed at the + * Returns a read-only transaction context in which a single read or query can be performed at * given timestamp bound. This method differs from {@link #singleUse(TimestampBound)} in that the * read timestamp used may be inspected after the read has returned data or finished successfully. * @@ -269,4 +269,51 @@ public interface DatabaseClient { * */ TransactionManager transactionManager(); + + /** + * Returns the lower bound of rows modified by this DML statement. + * + *

The method will block until the update is complete. Running a DML statement with this method + * does not offer exactly once semantics, and therfore the DML statement should be idempotent. The + * DML statement must be fully-partitionable. Specifically, the statement must be expressible as + * the union of many statements which each access only a single row of the table. This is a + * Partitioned DML transaction in which a single Partitioned DML statement is executed. + * Partitioned DML partitions the key space and runs the DML statement over each partition in + * parallel using separate, internal transactions that commit independently. Partitioned DML + * transactions do not need to be committed. + * + *

Partitioned DML updates are used to execute a single DML statement with a different + * execution strategy that provides different, and often better, scalability properties for large, + * table-wide operations than DML in a {@link #readWriteTransaction()} transaction. Smaller scoped + * statements, such as an OLTP workload, should prefer using {@link + * TransactionContext#executeUpdate(Statement)} with {@link #readWriteTransaction()}. + * + *