Skip to content

Commit 040a054

Browse files
olavloitekolea2
authored andcommitted
---
yaml --- r: 34639 b: refs/heads/autosynth-texttospeech c: 308bc15 h: refs/heads/master i: 34637: f20c584 34635: 0f131b6 34631: 7fc16f9 34623: 581a3b9
1 parent 3b806bd commit 040a054

3 files changed

Lines changed: 108 additions & 75 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ refs/heads/autosynth-scheduler: a3de6480746d1cd586ca8b9d75c55a636f371539
140140
refs/heads/autosynth-spanner: d963fe4368e79cf6abae5d511785e8ced8ac57f4
141141
refs/heads/autosynth-speech: c563dcd420cce0a37c39b1b9c24be1b9ba604dc7
142142
refs/heads/autosynth-tasks: 25d1eafe8cb66b00e3dad765dac74a5b45b83e63
143-
refs/heads/autosynth-texttospeech: 5fbe077d191f522c4a629fc987d3c5c37dfaa836
143+
refs/heads/autosynth-texttospeech: 308bc15c9e5d8b9311bfa935856a5aeb60e5ada7
144144
refs/heads/autosynth-trace: c94eef6e4d9c6fd24888216e28ca7271959c1cf0
145145
refs/heads/autosynth-websecurityscanner: fa561b356aabcd92d415ae8dc88fd8d87dbc5b23
146146
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.spanner;
18+
19+
import static com.google.common.base.Preconditions.checkState;
20+
21+
import com.google.cloud.spanner.SpannerImpl.SessionImpl;
22+
import com.google.cloud.spanner.SpannerImpl.SessionTransaction;
23+
import com.google.cloud.spanner.spi.v1.SpannerRpc;
24+
import com.google.protobuf.ByteString;
25+
import com.google.spanner.v1.BeginTransactionRequest;
26+
import com.google.spanner.v1.ExecuteSqlRequest;
27+
import com.google.spanner.v1.ExecuteSqlRequest.QueryMode;
28+
import com.google.spanner.v1.Transaction;
29+
import com.google.spanner.v1.TransactionOptions;
30+
import com.google.spanner.v1.TransactionSelector;
31+
import java.util.Map;
32+
import java.util.concurrent.Callable;
33+
34+
/** Partitioned DML transaction for bulk updates and deletes. */
35+
class PartitionedDMLTransaction implements SessionTransaction {
36+
private final ByteString transactionId;
37+
private final SessionImpl session;
38+
private final SpannerRpc rpc;
39+
private volatile boolean isValid = true;
40+
41+
PartitionedDMLTransaction(SessionImpl session, SpannerRpc rpc) {
42+
this.session = session;
43+
this.rpc = rpc;
44+
this.transactionId = initTransaction();
45+
}
46+
47+
private ByteString initTransaction() {
48+
final BeginTransactionRequest request =
49+
BeginTransactionRequest.newBuilder()
50+
.setSession(session.getName())
51+
.setOptions(
52+
TransactionOptions.newBuilder()
53+
.setPartitionedDml(TransactionOptions.PartitionedDml.getDefaultInstance()))
54+
.build();
55+
Transaction txn =
56+
SpannerImpl.runWithRetries(
57+
new Callable<Transaction>() {
58+
@Override
59+
public Transaction call() throws Exception {
60+
return rpc.beginTransaction(request, session.getOptions());
61+
}
62+
});
63+
if (txn.getId().isEmpty()) {
64+
throw SpannerExceptionFactory.newSpannerException(
65+
ErrorCode.INTERNAL,
66+
"Failed to init transaction, missing transaction id\n" + session.getName());
67+
}
68+
return txn.getId();
69+
}
70+
71+
long executePartitionedUpdate(Statement statement) {
72+
checkState(isValid, "Partitioned DML has been invalidated by a new operation on the session");
73+
final ExecuteSqlRequest.Builder builder =
74+
ExecuteSqlRequest.newBuilder()
75+
.setSql(statement.getSql())
76+
.setQueryMode(QueryMode.NORMAL)
77+
.setSession(session.getName())
78+
.setTransaction(TransactionSelector.newBuilder().setId(transactionId).build());
79+
Map<String, Value> stmtParameters = statement.getParameters();
80+
if (!stmtParameters.isEmpty()) {
81+
com.google.protobuf.Struct.Builder paramsBuilder = builder.getParamsBuilder();
82+
for (Map.Entry<String, Value> param : stmtParameters.entrySet()) {
83+
paramsBuilder.putFields(param.getKey(), param.getValue().toProto());
84+
builder.putParamTypes(param.getKey(), param.getValue().getType().toProto());
85+
}
86+
}
87+
com.google.spanner.v1.ResultSet resultSet =
88+
SpannerImpl.runWithRetries(
89+
new Callable<com.google.spanner.v1.ResultSet>() {
90+
@Override
91+
public com.google.spanner.v1.ResultSet call() throws Exception {
92+
return rpc.executeQuery(builder.build(), session.getOptions());
93+
}
94+
});
95+
if (!resultSet.hasStats()) {
96+
throw new IllegalArgumentException(
97+
"Partitioned DML response missing stats possibly due to non-DML statement as input");
98+
}
99+
// For partitioned DML, using the row count lower bound.
100+
return resultSet.getStats().getRowCountLowerBound();
101+
}
102+
103+
@Override
104+
public void invalidate() {
105+
isValid = false;
106+
}
107+
}

branches/autosynth-texttospeech/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -771,80 +771,6 @@ private void backoff(Context context, BackOff backoff) {
771771
}
772772
}
773773

774-
static class PartitionedDMLTransaction implements SessionTransaction {
775-
private final ByteString transactionId;
776-
private final SessionImpl session;
777-
private final SpannerRpc rpc;
778-
private volatile boolean isValid = true;
779-
780-
PartitionedDMLTransaction(SessionImpl session, SpannerRpc rpc) {
781-
this.session = session;
782-
this.rpc = rpc;
783-
this.transactionId = initTransaction();
784-
}
785-
786-
ByteString initTransaction() {
787-
final BeginTransactionRequest request =
788-
BeginTransactionRequest.newBuilder()
789-
.setSession(session.getName())
790-
.setOptions(
791-
TransactionOptions.newBuilder()
792-
.setPartitionedDml(TransactionOptions.PartitionedDml.getDefaultInstance()))
793-
.build();
794-
Transaction txn =
795-
runWithRetries(
796-
new Callable<Transaction>() {
797-
@Override
798-
public Transaction call() throws Exception {
799-
return rpc.beginTransaction(request, session.options);
800-
}
801-
});
802-
if (txn.getId().isEmpty()) {
803-
throw SpannerExceptionFactory.newSpannerException(
804-
ErrorCode.INTERNAL,
805-
"Failed to init transaction, missing transaction id\n" + session.getName());
806-
}
807-
return txn.getId();
808-
}
809-
810-
public long executePartitionedUpdate(Statement statement) {
811-
checkState(isValid, "Partitioned DML has been invalidated by a new operation on the session");
812-
final ExecuteSqlRequest.Builder builder =
813-
ExecuteSqlRequest.newBuilder()
814-
.setSql(statement.getSql())
815-
.setQueryMode(QueryMode.NORMAL)
816-
.setSession(session.name)
817-
.setTransaction(TransactionSelector.newBuilder().setId(transactionId).build());
818-
Map<String, Value> stmtParameters = statement.getParameters();
819-
if (!stmtParameters.isEmpty()) {
820-
com.google.protobuf.Struct.Builder paramsBuilder = builder.getParamsBuilder();
821-
for (Map.Entry<String, Value> param : stmtParameters.entrySet()) {
822-
paramsBuilder.putFields(param.getKey(), param.getValue().toProto());
823-
builder.putParamTypes(param.getKey(), param.getValue().getType().toProto());
824-
}
825-
}
826-
com.google.spanner.v1.ResultSet resultSet =
827-
runWithRetries(
828-
new Callable<com.google.spanner.v1.ResultSet>() {
829-
@Override
830-
public com.google.spanner.v1.ResultSet call() throws Exception {
831-
return rpc.executeQuery(builder.build(), session.options);
832-
}
833-
});
834-
if (!resultSet.hasStats()) {
835-
throw new IllegalArgumentException(
836-
"Partitioned DML response missing stats possibly due to non-DML statement as input");
837-
}
838-
// For partitioned DML, using the row count lower bound.
839-
return resultSet.getStats().getRowCountLowerBound();
840-
}
841-
842-
@Override
843-
public void invalidate() {
844-
isValid = false;
845-
}
846-
}
847-
848774
@VisibleForTesting
849775
static class TransactionContextImpl extends AbstractReadContext implements TransactionContext {
850776
@GuardedBy("lock")

0 commit comments

Comments
 (0)