Skip to content

Commit 85e2bb1

Browse files
committed
chore(spanner): create package protected setter to disable background begintxn verification
1 parent 606c052 commit 85e2bb1

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,15 @@ public void onSessionReady(SessionImpl session) {
253253
// initiate a begin transaction request to verify if read-write transactions are
254254
// supported using multiplexed sessions.
255255
if (sessionClient
256-
.getSpanner()
257-
.getOptions()
258-
.getSessionPoolOptions()
259-
.getUseMultiplexedSessionForRW()) {
256+
.getSpanner()
257+
.getOptions()
258+
.getSessionPoolOptions()
259+
.getUseMultiplexedSessionForRW()
260+
&& !sessionClient
261+
.getSpanner()
262+
.getOptions()
263+
.getSessionPoolOptions()
264+
.getSkipVerifyBeginTransactionForMuxRW()) {
260265
verifyBeginTransactionWithRWOnMultiplexedSessionAsync(session.getName());
261266
}
262267
}

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class SessionPoolOptions {
8383

8484
// TODO: Change to use java.time.Duration.
8585
private final Duration multiplexedSessionMaintenanceDuration;
86+
private final boolean skipVerifyingBeginTransactionForMuxRW;
8687

8788
private SessionPoolOptions(Builder builder) {
8889
// minSessions > maxSessions is only possible if the user has only set a value for maxSessions.
@@ -132,6 +133,7 @@ private SessionPoolOptions(Builder builder) {
132133
? useMultiplexedSessionFromEnvVariablePartitionedOps
133134
: builder.useMultiplexedSessionPartitionedOps;
134135
this.multiplexedSessionMaintenanceDuration = builder.multiplexedSessionMaintenanceDuration;
136+
this.skipVerifyingBeginTransactionForMuxRW = builder.skipVerifyingBeginTransactionForMuxRW;
135137
}
136138

137139
@Override
@@ -169,8 +171,10 @@ public boolean equals(Object o) {
169171
&& Objects.equals(this.useMultiplexedSession, other.useMultiplexedSession)
170172
&& Objects.equals(this.useMultiplexedSessionForRW, other.useMultiplexedSessionForRW)
171173
&& Objects.equals(
172-
this.multiplexedSessionMaintenanceDuration,
173-
other.multiplexedSessionMaintenanceDuration);
174+
this.multiplexedSessionMaintenanceDuration, other.multiplexedSessionMaintenanceDuration)
175+
&& Objects.equals(
176+
this.skipVerifyingBeginTransactionForMuxRW,
177+
other.skipVerifyingBeginTransactionForMuxRW);
174178
}
175179

176180
@Override
@@ -199,7 +203,8 @@ public int hashCode() {
199203
this.poolMaintainerClock,
200204
this.useMultiplexedSession,
201205
this.useMultiplexedSessionForRW,
202-
this.multiplexedSessionMaintenanceDuration);
206+
this.multiplexedSessionMaintenanceDuration,
207+
this.skipVerifyingBeginTransactionForMuxRW);
203208
}
204209

205210
public Builder toBuilder() {
@@ -390,6 +395,12 @@ Duration getMultiplexedSessionMaintenanceDuration() {
390395
return multiplexedSessionMaintenanceDuration;
391396
}
392397

398+
@VisibleForTesting
399+
@InternalApi
400+
boolean getSkipVerifyBeginTransactionForMuxRW() {
401+
return skipVerifyingBeginTransactionForMuxRW;
402+
}
403+
393404
public static Builder newBuilder() {
394405
return new Builder();
395406
}
@@ -605,6 +616,7 @@ public static class Builder {
605616

606617
private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7);
607618
private Clock poolMaintainerClock = Clock.INSTANCE;
619+
private boolean skipVerifyingBeginTransactionForMuxRW = false;
608620

609621
private static Position getReleaseToPositionFromSystemProperty() {
610622
// NOTE: This System property is a beta feature. Support for it can be removed in the future.
@@ -648,6 +660,7 @@ private Builder(SessionPoolOptions options) {
648660
this.useMultiplexedSessionPartitionedOps = options.useMultiplexedSessionForPartitionedOps;
649661
this.multiplexedSessionMaintenanceDuration = options.multiplexedSessionMaintenanceDuration;
650662
this.poolMaintainerClock = options.poolMaintainerClock;
663+
this.skipVerifyingBeginTransactionForMuxRW = options.skipVerifyingBeginTransactionForMuxRW;
651664
}
652665

653666
/**
@@ -870,6 +883,13 @@ Builder setMultiplexedSessionMaintenanceDuration(
870883
return this;
871884
}
872885

886+
@VisibleForTesting
887+
Builder setSkipVerifyingBeginTransactionForMuxRW(
888+
boolean skipVerifyingBeginTransactionForMuxRW) {
889+
this.skipVerifyingBeginTransactionForMuxRW = skipVerifyingBeginTransactionForMuxRW;
890+
return this;
891+
}
892+
873893
/**
874894
* Sets whether the client should automatically execute a background query to detect the dialect
875895
* that is used by the database or not. Set this option to true if you do not know what the

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ private SpannerOptions createSpannerOptions() {
188188
.setCompressorName("gzip")
189189
.setHost("http://" + endpoint)
190190
.setCredentials(NoCredentials.getInstance())
191+
.setSessionPoolOption(
192+
SessionPoolOptions.newBuilder().setSkipVerifyingBeginTransactionForMuxRW(true).build())
191193
.build();
192194
}
193195

0 commit comments

Comments
 (0)