Skip to content

Commit 24d2742

Browse files
authored
chore: cleanup SessionPoolOptions (#3171)
Remove some unused options and make some fields final.
1 parent 52ee196 commit 24d2742

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ public class SessionPoolOptions {
7474

7575
private final boolean useMultiplexedSession;
7676

77-
private final boolean useRandomChannelHint;
78-
7977
// TODO: Change to use java.time.Duration.
8078
private final Duration multiplexedSessionMaintenanceDuration;
8179

@@ -110,7 +108,6 @@ private SessionPoolOptions(Builder builder) {
110108
builder.useMultiplexedSession
111109
&& !Boolean.parseBoolean(
112110
System.getenv("GOOGLE_CLOUD_SPANNER_FORCE_DISABLE_MULTIPLEXED_SESSIONS"));
113-
this.useRandomChannelHint = builder.useRandomChannelHint;
114111
this.multiplexedSessionMaintenanceDuration = builder.multiplexedSessionMaintenanceDuration;
115112
}
116113

@@ -147,7 +144,6 @@ public boolean equals(Object o) {
147144
this.inactiveTransactionRemovalOptions, other.inactiveTransactionRemovalOptions)
148145
&& Objects.equals(this.poolMaintainerClock, other.poolMaintainerClock)
149146
&& Objects.equals(this.useMultiplexedSession, other.useMultiplexedSession)
150-
&& Objects.equals(this.useRandomChannelHint, other.useRandomChannelHint)
151147
&& Objects.equals(
152148
this.multiplexedSessionMaintenanceDuration,
153149
other.multiplexedSessionMaintenanceDuration);
@@ -178,7 +174,6 @@ public int hashCode() {
178174
this.inactiveTransactionRemovalOptions,
179175
this.poolMaintainerClock,
180176
this.useMultiplexedSession,
181-
this.useRandomChannelHint,
182177
this.multiplexedSessionMaintenanceDuration);
183178
}
184179

@@ -312,10 +307,6 @@ public boolean getUseMultiplexedSession() {
312307
return useMultiplexedSession;
313308
}
314309

315-
boolean isUseRandomChannelHint() {
316-
return useRandomChannelHint;
317-
}
318-
319310
Duration getMultiplexedSessionMaintenanceDuration() {
320311
return multiplexedSessionMaintenanceDuration;
321312
}
@@ -350,24 +341,24 @@ enum ActionOnInactiveTransaction {
350341
static class InactiveTransactionRemovalOptions {
351342

352343
/** Option to set the behaviour when there are inactive transactions. */
353-
private ActionOnInactiveTransaction actionOnInactiveTransaction;
344+
private final ActionOnInactiveTransaction actionOnInactiveTransaction;
354345

355346
/**
356347
* Frequency for closing inactive transactions. Between two consecutive task executions, it's
357348
* ensured that the duration is greater or equal to this duration.
358349
*/
359-
private Duration executionFrequency;
350+
private final Duration executionFrequency;
360351

361352
/**
362353
* Long-running transactions will be cleaned up if utilisation is greater than the below value.
363354
*/
364-
private double usedSessionsRatioThreshold;
355+
private final double usedSessionsRatioThreshold;
365356

366357
/**
367358
* A transaction is considered to be idle if it has not been used for a duration greater than
368359
* the below value.
369360
*/
370-
private Duration idleTimeThreshold;
361+
private final Duration idleTimeThreshold;
371362

372363
InactiveTransactionRemovalOptions(final Builder builder) {
373364
this.actionOnInactiveTransaction = builder.actionOnInactiveTransaction;
@@ -509,7 +500,7 @@ public static class Builder {
509500
private boolean autoDetectDialect = false;
510501
private Duration waitForMinSessions = Duration.ZERO;
511502
private Duration acquireSessionTimeout = Duration.ofSeconds(60);
512-
private Position releaseToPosition = getReleaseToPositionFromSystemProperty();
503+
private final Position releaseToPosition = getReleaseToPositionFromSystemProperty();
513504
/**
514505
* The session pool will randomize the position of a session that is being returned when this
515506
* threshold is exceeded. That is: If the transactions per second exceeds this threshold, then
@@ -520,8 +511,6 @@ public static class Builder {
520511

521512
private boolean useMultiplexedSession = getUseMultiplexedSessionFromEnvVariable();
522513

523-
private boolean useRandomChannelHint;
524-
525514
private Duration multiplexedSessionMaintenanceDuration = Duration.ofDays(7);
526515
private Clock poolMaintainerClock = Clock.INSTANCE;
527516

@@ -760,11 +749,6 @@ Builder setUseMultiplexedSession(boolean useMultiplexedSession) {
760749
return this;
761750
}
762751

763-
Builder setUseRandomChannelHint(boolean useRandomChannelHint) {
764-
this.useRandomChannelHint = useRandomChannelHint;
765-
return this;
766-
}
767-
768752
@VisibleForTesting
769753
Builder setMultiplexedSessionMaintenanceDuration(
770754
Duration multiplexedSessionMaintenanceDuration) {
@@ -878,11 +862,6 @@ public Builder setAcquireSessionTimeout(Duration acquireSessionTimeout) {
878862
return this;
879863
}
880864

881-
Builder setReleaseToPosition(Position releaseToPosition) {
882-
this.releaseToPosition = Preconditions.checkNotNull(releaseToPosition);
883-
return this;
884-
}
885-
886865
Builder setRandomizePositionQPSThreshold(long randomizePositionQPSThreshold) {
887866
Preconditions.checkArgument(
888867
randomizePositionQPSThreshold >= 0L, "randomizePositionQPSThreshold must be >= 0");

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.ArrayList;
2929
import java.util.Collection;
3030
import java.util.List;
31+
import java.util.concurrent.ThreadLocalRandom;
3132
import org.junit.Test;
3233
import org.junit.runner.RunWith;
3334
import org.junit.runners.Parameterized;
@@ -169,6 +170,36 @@ public void setCloseIfInactiveTransactions() {
169170
assertTrue(sessionPoolOptions.closeInactiveTransactions());
170171
}
171172

173+
@Test
174+
public void testSetUsedSessionsRatioThreshold() {
175+
double threshold = ThreadLocalRandom.current().nextDouble();
176+
InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =
177+
InactiveTransactionRemovalOptions.newBuilder()
178+
.setUsedSessionsRatioThreshold(threshold)
179+
.build();
180+
assertEquals(
181+
threshold, inactiveTransactionRemovalOptions.getUsedSessionsRatioThreshold(), 0.0d);
182+
}
183+
184+
@Test
185+
public void testBlockIfPoolExhausted() {
186+
assertTrue(SessionPoolOptions.newBuilder().build().isBlockIfPoolExhausted());
187+
assertTrue(
188+
SessionPoolOptions.newBuilder().setBlockIfPoolExhausted().build().isBlockIfPoolExhausted());
189+
assertFalse(
190+
SessionPoolOptions.newBuilder().setFailIfPoolExhausted().build().isBlockIfPoolExhausted());
191+
}
192+
193+
@Test
194+
public void testFailIfSessionNotFound() {
195+
assertFalse(SessionPoolOptions.newBuilder().build().isFailIfSessionNotFound());
196+
assertTrue(
197+
SessionPoolOptions.newBuilder()
198+
.setFailIfSessionNotFound()
199+
.build()
200+
.isFailIfSessionNotFound());
201+
}
202+
172203
@Test(expected = IllegalArgumentException.class)
173204
public void setNegativeExecutionFrequency() {
174205
InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions =

0 commit comments

Comments
 (0)