Skip to content

Commit dea3c08

Browse files
committed
chore(spanner): support multiplexed sessions for writewithoptions
1 parent a463917 commit dea3c08

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public CommitResponse writeWithOptions(
129129
throws SpannerException {
130130
ISpan span = tracer.spanBuilder(READ_WRITE_TRANSACTION, options);
131131
try (IScope s = tracer.withSpan(span)) {
132+
if (this.useMultiplexedSessionForRW && getMultiplexedSessionDatabaseClient() != null) {
133+
return getMultiplexedSessionDatabaseClient().writeWithOptions(mutations, options);
134+
}
132135
return runWithSessionRetry(session -> session.writeWithOptions(mutations, options));
133136
} catch (RuntimeException e) {
134137
span.setStatus(e);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ public CommitResponse writeAtLeastOnceWithOptions(
136136
}
137137
}
138138

139+
/**
140+
* This is a blocking method, as the interface that it implements is also defined as a blocking
141+
* method.
142+
*/
143+
@Override
144+
public CommitResponse writeWithOptions(Iterable<Mutation> mutations, TransactionOption... options)
145+
throws SpannerException {
146+
SessionReference sessionReference = getSessionReference();
147+
try (MultiplexedSessionTransaction transaction =
148+
new MultiplexedSessionTransaction(client, span, sessionReference, NO_CHANNEL_HINT, false)) {
149+
return transaction.writeWithOptions(mutations, options);
150+
}
151+
}
152+
139153
@Override
140154
public TransactionRunner readWriteTransaction(TransactionOption... options) {
141155
return new DelayedTransactionRunner(

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ private int getSingleUseChannelHint() {
367367
}
368368
}
369369

370+
@Override
371+
public CommitResponse writeWithOptions(
372+
final Iterable<Mutation> mutations, final TransactionOption... options)
373+
throws SpannerException {
374+
return createMultiplexedSessionTransaction(false).writeWithOptions(mutations, options);
375+
}
376+
370377
@Override
371378
public CommitResponse writeAtLeastOnceWithOptions(
372379
Iterable<Mutation> mutations, TransactionOption... options) throws SpannerException {

0 commit comments

Comments
 (0)