Skip to content

Commit

Permalink
chore(spanner): create package protected setter to disable background…
Browse files Browse the repository at this point in the history
… begintxn verification
  • Loading branch information
harshachinta committed Dec 18, 2024
1 parent 606c052 commit 85e2bb1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ public void onSessionReady(SessionImpl session) {
// initiate a begin transaction request to verify if read-write transactions are
// supported using multiplexed sessions.
if (sessionClient
.getSpanner()
.getOptions()
.getSessionPoolOptions()
.getUseMultiplexedSessionForRW()) {
.getSpanner()
.getOptions()
.getSessionPoolOptions()
.getUseMultiplexedSessionForRW()
&& !sessionClient
.getSpanner()
.getOptions()
.getSessionPoolOptions()
.getSkipVerifyBeginTransactionForMuxRW()) {
verifyBeginTransactionWithRWOnMultiplexedSessionAsync(session.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SessionPoolOptions {

// TODO: Change to use java.time.Duration.
private final Duration multiplexedSessionMaintenanceDuration;
private final boolean skipVerifyingBeginTransactionForMuxRW;

private SessionPoolOptions(Builder builder) {
// minSessions > maxSessions is only possible if the user has only set a value for maxSessions.
Expand Down Expand Up @@ -132,6 +133,7 @@ private SessionPoolOptions(Builder builder) {
? useMultiplexedSessionFromEnvVariablePartitionedOps
: builder.useMultiplexedSessionPartitionedOps;
this.multiplexedSessionMaintenanceDuration = builder.multiplexedSessionMaintenanceDuration;
this.skipVerifyingBeginTransactionForMuxRW = builder.skipVerifyingBeginTransactionForMuxRW;
}

@Override
Expand Down Expand Up @@ -169,8 +171,10 @@ public boolean equals(Object o) {
&& Objects.equals(this.useMultiplexedSession, other.useMultiplexedSession)
&& Objects.equals(this.useMultiplexedSessionForRW, other.useMultiplexedSessionForRW)
&& Objects.equals(
this.multiplexedSessionMaintenanceDuration,
other.multiplexedSessionMaintenanceDuration);
this.multiplexedSessionMaintenanceDuration, other.multiplexedSessionMaintenanceDuration)
&& Objects.equals(
this.skipVerifyingBeginTransactionForMuxRW,
other.skipVerifyingBeginTransactionForMuxRW);
}

@Override
Expand Down Expand Up @@ -199,7 +203,8 @@ public int hashCode() {
this.poolMaintainerClock,
this.useMultiplexedSession,
this.useMultiplexedSessionForRW,
this.multiplexedSessionMaintenanceDuration);
this.multiplexedSessionMaintenanceDuration,
this.skipVerifyingBeginTransactionForMuxRW);
}

public Builder toBuilder() {
Expand Down Expand Up @@ -390,6 +395,12 @@ Duration getMultiplexedSessionMaintenanceDuration() {
return multiplexedSessionMaintenanceDuration;
}

@VisibleForTesting
@InternalApi
boolean getSkipVerifyBeginTransactionForMuxRW() {
return skipVerifyingBeginTransactionForMuxRW;
}

public static Builder newBuilder() {
return new Builder();
}
Expand Down Expand Up @@ -605,6 +616,7 @@ public static class Builder {

private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7);
private Clock poolMaintainerClock = Clock.INSTANCE;
private boolean skipVerifyingBeginTransactionForMuxRW = false;

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

/**
Expand Down Expand Up @@ -870,6 +883,13 @@ Builder setMultiplexedSessionMaintenanceDuration(
return this;
}

@VisibleForTesting
Builder setSkipVerifyingBeginTransactionForMuxRW(
boolean skipVerifyingBeginTransactionForMuxRW) {
this.skipVerifyingBeginTransactionForMuxRW = skipVerifyingBeginTransactionForMuxRW;
return this;
}

/**
* Sets whether the client should automatically execute a background query to detect the dialect
* that is used by the database or not. Set this option to true if you do not know what the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ private SpannerOptions createSpannerOptions() {
.setCompressorName("gzip")
.setHost("http://" + endpoint)
.setCredentials(NoCredentials.getInstance())
.setSessionPoolOption(
SessionPoolOptions.newBuilder().setSkipVerifyingBeginTransactionForMuxRW(true).build())
.build();
}

Expand Down

0 comments on commit 85e2bb1

Please sign in to comment.