Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 11cf721

Browse files
committed
chore: some additional cleanup
1 parent c3f29e0 commit 11cf721

10 files changed

Lines changed: 211 additions & 273 deletions

File tree

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

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.cloud.spanner.Options.QueryOption;
2323
import com.google.cloud.spanner.Options.ReadOption;
2424
import com.google.cloud.spanner.spi.v1.SpannerRpc;
25-
import com.google.common.annotations.VisibleForTesting;
2625
import com.google.common.base.Preconditions;
2726
import com.google.common.collect.ImmutableList;
2827
import com.google.protobuf.Struct;
@@ -36,7 +35,6 @@
3635
import java.time.Instant;
3736
import java.util.List;
3837
import java.util.Map;
39-
import java.util.concurrent.atomic.AtomicBoolean;
4038
import java.util.concurrent.atomic.AtomicReference;
4139
import java.util.concurrent.locks.ReentrantLock;
4240
import javax.annotation.Nullable;
@@ -46,8 +44,6 @@
4644
public class BatchClientImpl implements BatchClient {
4745
private final SessionClient sessionClient;
4846

49-
private final boolean isMultiplexedSessionEnabled;
50-
5147
/** Lock to protect the multiplexed session. */
5248
private final ReentrantLock multiplexedSessionLock = new ReentrantLock();
5349

@@ -61,16 +57,8 @@ public class BatchClientImpl implements BatchClient {
6157
@GuardedBy("multiplexedSessionLock")
6258
private final AtomicReference<SessionImpl> multiplexedSessionReference;
6359

64-
/**
65-
* This flag is set to true if the server return UNIMPLEMENTED when partitioned transaction is
66-
* executed on a multiplexed session. TODO: Remove once this is guaranteed to be available.
67-
*/
68-
@VisibleForTesting
69-
static final AtomicBoolean unimplementedForPartitionedOps = new AtomicBoolean(false);
70-
71-
BatchClientImpl(SessionClient sessionClient, boolean isMultiplexedSessionEnabled) {
60+
BatchClientImpl(SessionClient sessionClient) {
7261
this.sessionClient = checkNotNull(sessionClient);
73-
this.isMultiplexedSessionEnabled = isMultiplexedSessionEnabled;
7462
this.sessionExpirationDuration =
7563
Duration.ofMillis(
7664
sessionClient
@@ -93,12 +81,7 @@ public String getDatabaseRole() {
9381

9482
@Override
9583
public BatchReadOnlyTransaction batchReadOnlyTransaction(TimestampBound bound) {
96-
SessionImpl session;
97-
if (canUseMultiplexedSession()) {
98-
session = getMultiplexedSession();
99-
} else {
100-
session = sessionClient.createSession();
101-
}
84+
SessionImpl session = getMultiplexedSession();
10285
return new BatchReadOnlyTransactionImpl(
10386
MultiUseReadOnlyTransaction.newBuilder()
10487
.setSession(session)
@@ -114,8 +97,7 @@ public BatchReadOnlyTransaction batchReadOnlyTransaction(TimestampBound bound) {
11497
sessionClient.getSpanner().getOptions().getDirectedReadOptions())
11598
.setSpan(sessionClient.getSpanner().getTracer().getCurrentSpan())
11699
.setTracer(sessionClient.getSpanner().getTracer()),
117-
checkNotNull(bound),
118-
sessionClient);
100+
checkNotNull(bound));
119101
}
120102

121103
@Override
@@ -138,12 +120,7 @@ public BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batc
138120
sessionClient.getSpanner().getOptions().getDirectedReadOptions())
139121
.setSpan(sessionClient.getSpanner().getTracer().getCurrentSpan())
140122
.setTracer(sessionClient.getSpanner().getTracer()),
141-
batchTransactionId,
142-
sessionClient);
143-
}
144-
145-
private boolean canUseMultiplexedSession() {
146-
return isMultiplexedSessionEnabled && !unimplementedForPartitionedOps.get();
123+
batchTransactionId);
147124
}
148125

149126
private SessionImpl getMultiplexedSession() {
@@ -162,28 +139,20 @@ private SessionImpl getMultiplexedSession() {
162139

163140
private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransaction
164141
implements BatchReadOnlyTransaction {
165-
private String sessionName;
142+
private final String sessionName;
166143
private final Map<SpannerRpc.Option, ?> options;
167-
private final SessionClient sessionClient;
168-
private final AtomicBoolean fallbackInitiated = new AtomicBoolean(false);
169144

170145
BatchReadOnlyTransactionImpl(
171-
MultiUseReadOnlyTransaction.Builder builder,
172-
TimestampBound bound,
173-
SessionClient sessionClient) {
146+
MultiUseReadOnlyTransaction.Builder builder, TimestampBound bound) {
174147
super(builder.setTimestampBound(bound));
175-
this.sessionClient = sessionClient;
176148
this.sessionName = session.getName();
177149
this.options = session.getOptions();
178150
initTransaction();
179151
}
180152

181153
BatchReadOnlyTransactionImpl(
182-
MultiUseReadOnlyTransaction.Builder builder,
183-
BatchTransactionId batchTransactionId,
184-
SessionClient sessionClient) {
154+
MultiUseReadOnlyTransaction.Builder builder, BatchTransactionId batchTransactionId) {
185155
super(builder.setTransactionId(batchTransactionId.getTransactionId()));
186-
this.sessionClient = sessionClient;
187156
this.sessionName = session.getName();
188157
this.options = session.getOptions();
189158
}
@@ -214,18 +183,6 @@ public List<Partition> partitionReadUsingIndex(
214183
Iterable<String> columns,
215184
ReadOption... option)
216185
throws SpannerException {
217-
return partitionReadUsingIndex(partitionOptions, table, index, keys, columns, false, option);
218-
}
219-
220-
private List<Partition> partitionReadUsingIndex(
221-
PartitionOptions partitionOptions,
222-
String table,
223-
String index,
224-
KeySet keys,
225-
Iterable<String> columns,
226-
boolean isFallback,
227-
ReadOption... option)
228-
throws SpannerException {
229186
Options readOptions = Options.fromReadOptions(option);
230187
Preconditions.checkArgument(
231188
!readOptions.hasLimit(),

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

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,6 @@ public CommitResponse writeAtLeastOnceWithOptions(
153153
}
154154
}
155155

156-
private int nextNthRequest() {
157-
return this.nthRequest.incrementAndGet();
158-
}
159-
160-
@VisibleForTesting
161-
int getNthRequest() {
162-
return this.nthRequest.get();
163-
}
164-
165156
@Override
166157
public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
167158
final Iterable<MutationGroup> mutationGroups, final TransactionOption... options)
@@ -306,41 +297,13 @@ private Future<Dialect> getDialectAsync() {
306297
return multiplexedSessionDatabaseClient.getDialectAsync();
307298
}
308299

309-
private UpdateOption[] withReqId(
310-
final XGoogSpannerRequestId reqId, final UpdateOption... options) {
311-
if (reqId == null) {
312-
return options;
313-
}
314-
if (options == null || options.length == 0) {
315-
return new UpdateOption[] {new Options.RequestIdOption(reqId)};
316-
}
317-
UpdateOption[] allOptions = new UpdateOption[options.length + 1];
318-
System.arraycopy(options, 0, allOptions, 0, options.length);
319-
allOptions[options.length] = new Options.RequestIdOption(reqId);
320-
return allOptions;
321-
}
322-
323-
private TransactionOption[] withReqId(
324-
final XGoogSpannerRequestId reqId, final TransactionOption... options) {
325-
if (reqId == null) {
326-
return options;
327-
}
328-
if (options == null || options.length == 0) {
329-
return new TransactionOption[] {new Options.RequestIdOption(reqId)};
330-
}
331-
TransactionOption[] allOptions = new TransactionOption[options.length + 1];
332-
System.arraycopy(options, 0, allOptions, 0, options.length);
333-
allOptions[options.length] = new Options.RequestIdOption(reqId);
334-
return allOptions;
335-
}
336-
337300
boolean isValid() {
338301
return multiplexedSessionDatabaseClient.isValid();
339302
}
340303

341304
ListenableFuture<Void> closeAsync(ClosedException closedException) {
342305
// This method is non-blocking.
343306
this.multiplexedSessionDatabaseClient.close();
344-
return Futures.immediateFuture(null);
307+
return Futures.immediateVoidFuture();
345308
}
346309
}

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@
2727
import java.util.Locale;
2828
import java.util.Objects;
2929

30-
/** Options for the session pool used by {@code DatabaseClient}. */
30+
/**
31+
* Options for the session pool used by {@code DatabaseClient}.
32+
*
33+
* @deprecated The Spanner Java client uses a single multiplexed session. All options related to the
34+
* session pool are no longer functional and will be removed in a future version.
35+
*/
3136
@Deprecated
3237
public class SessionPoolOptions {
38+
@Deprecated
3339
enum Position {
3440
FIRST,
3541
LAST,
@@ -228,10 +234,12 @@ public Builder toBuilder() {
228234
return new Builder(this);
229235
}
230236

237+
@Deprecated
231238
public int getMinSessions() {
232239
return minSessions;
233240
}
234241

242+
@Deprecated
235243
public int getMaxSessions() {
236244
return maxSessions;
237245
}
@@ -268,6 +276,7 @@ Duration getMultiplexedSessionMaintenanceLoopFrequency() {
268276
return this.multiplexedSessionMaintenanceLoopFrequency;
269277
}
270278

279+
@Deprecated
271280
public int getKeepAliveIntervalMinutes() {
272281
return keepAliveIntervalMinutes;
273282
}
@@ -278,14 +287,17 @@ public org.threeten.bp.Duration getRemoveInactiveSessionAfter() {
278287
return toThreetenDuration(getRemoveInactiveSessionAfterDuration());
279288
}
280289

290+
@Deprecated
281291
public Duration getRemoveInactiveSessionAfterDuration() {
282292
return removeInactiveSessionAfter;
283293
}
284294

295+
@Deprecated
285296
public boolean isFailIfPoolExhausted() {
286297
return actionOnExhaustion == ActionOnExhaustion.FAIL;
287298
}
288299

300+
@Deprecated
289301
public boolean isBlockIfPoolExhausted() {
290302
return actionOnExhaustion == ActionOnExhaustion.BLOCK;
291303
}
@@ -333,6 +345,7 @@ Clock getPoolMaintainerClock() {
333345
return poolMaintainerClock;
334346
}
335347

348+
@Deprecated
336349
public boolean isTrackStackTraceOfSessionCheckout() {
337350
return trackStackTraceOfSessionCheckout;
338351
}
@@ -687,6 +700,7 @@ private Builder(SessionPoolOptions options) {
687700
* Minimum number of sessions that this pool will always maintain. These will be created eagerly
688701
* in parallel. Defaults to 100.
689702
*/
703+
@Deprecated
690704
public Builder setMinSessions(int minSessions) {
691705
Preconditions.checkArgument(minSessions >= 0, "minSessions must be >= 0");
692706
this.minSessionsSet = true;
@@ -700,6 +714,7 @@ public Builder setMinSessions(int minSessions) {
700714
* operation. If current number of in use sessions is same as this and a new request comes, pool
701715
* can either block or fail. Defaults to 400.
702716
*/
717+
@Deprecated
703718
public Builder setMaxSessions(int maxSessions) {
704719
Preconditions.checkArgument(maxSessions > 0, "maxSessions must be > 0");
705720
this.maxSessions = maxSessions;
@@ -753,10 +768,12 @@ Builder setInactiveTransactionRemovalOptions(
753768
* instead.
754769
*/
755770
@ObsoleteApi("Use setRemoveInactiveSessionAfterDuration(Duration) instead")
771+
@Deprecated
756772
public Builder setRemoveInactiveSessionAfter(org.threeten.bp.Duration duration) {
757773
return setRemoveInactiveSessionAfterDuration(toJavaTimeDuration(duration));
758774
}
759775

776+
@Deprecated
760777
public Builder setRemoveInactiveSessionAfterDuration(Duration duration) {
761778
this.removeInactiveSessionAfter = duration;
762779
return this;
@@ -767,16 +784,18 @@ public Builder setRemoveInactiveSessionAfterDuration(Duration duration) {
767784
* is automatically closed after 60 minutes. Sessions will be kept alive by sending a dummy
768785
* query "Select 1". Default value is 30 minutes.
769786
*/
787+
@Deprecated
770788
public Builder setKeepAliveIntervalMinutes(int intervalMinutes) {
771789
this.keepAliveIntervalMinutes = intervalMinutes;
772790
return this;
773791
}
774792

775793
/**
776-
* If all sessions are in use and and {@code maxSessions} has been reached, fail the request by
794+
* If all sessions are in use and {@code maxSessions} has been reached, fail the request by
777795
* throwing a {@link SpannerException} with the error code {@code RESOURCE_EXHAUSTED}. Default
778796
* behavior is to block the request.
779797
*/
798+
@Deprecated
780799
public Builder setFailIfPoolExhausted() {
781800
this.actionOnExhaustion = ActionOnExhaustion.FAIL;
782801
return this;
@@ -791,6 +810,7 @@ public Builder setFailIfPoolExhausted() {
791810
* different period use the option {@link Builder#setAcquireSessionTimeoutDuration(Duration)}
792811
* ()}
793812
*/
813+
@Deprecated
794814
public Builder setBlockIfPoolExhausted() {
795815
this.actionOnExhaustion = ActionOnExhaustion.BLOCK;
796816
return this;
@@ -806,6 +826,7 @@ public Builder setBlockIfPoolExhausted() {
806826
*
807827
* @return this builder for chaining
808828
*/
829+
@Deprecated
809830
public Builder setWarnIfInactiveTransactions() {
810831
this.inactiveTransactionRemovalOptions =
811832
InactiveTransactionRemovalOptions.newBuilder()
@@ -825,6 +846,7 @@ public Builder setWarnIfInactiveTransactions() {
825846
*
826847
* @return this builder for chaining
827848
*/
849+
@Deprecated
828850
public Builder setWarnAndCloseIfInactiveTransactions() {
829851
this.inactiveTransactionRemovalOptions =
830852
InactiveTransactionRemovalOptions.newBuilder()
@@ -976,6 +998,7 @@ Builder setFailOnSessionLeak() {
976998
* <p>Some monitoring tools might log these exceptions even though they are not thrown. This
977999
* option can be used to suppress the creation and logging of these exceptions.
9781000
*/
1001+
@Deprecated
9791002
public Builder setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSessionCheckout) {
9801003
this.trackStackTraceOfSessionCheckout = trackStackTraceOfSessionCheckout;
9811004
return this;
@@ -988,6 +1011,7 @@ public Builder setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSess
9881011
* BeginTransaction option with that statement.
9891012
* <p>This method may be removed in a future release.
9901013
*/
1014+
@Deprecated
9911015
public Builder setWriteSessionsFraction(float writeSessionsFraction) {
9921016
this.writeSessionsFraction = writeSessionsFraction;
9931017
return this;
@@ -1016,6 +1040,7 @@ public Builder setWaitForMinSessionsDuration(Duration waitForMinSessions) {
10161040

10171041
/** This method is obsolete. Use {@link #setAcquireSessionTimeoutDuration(Duration)} instead. */
10181042
@ObsoleteApi("Use setAcquireSessionTimeoutDuration(Duration) instead")
1043+
@Deprecated
10191044
public Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionTimeout) {
10201045
return setAcquireSessionTimeoutDuration(toJavaTimeDuration(acquireSessionTimeout));
10211046
}
@@ -1024,6 +1049,7 @@ public Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionT
10241049
* If greater than zero, we wait for said duration when no sessions are available in the
10251050
* SessionPool. The default is a 60s timeout. Set the value to null to disable the timeout.
10261051
*/
1052+
@Deprecated
10271053
public Builder setAcquireSessionTimeoutDuration(Duration acquireSessionTimeout) {
10281054
try {
10291055
if (acquireSessionTimeout != null) {

0 commit comments

Comments
 (0)