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

Commit b3742d9

Browse files
committed
chore: address review comment + fix test
1 parent 5226c7f commit b3742d9

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353
* transactions.
5454
*/
5555
final class MultiplexedSessionDatabaseClient extends AbstractMultiplexedSessionDatabaseClient {
56+
/**
57+
* The maximum number of attempts that the client will try to execute CreateSession for the
58+
* initial multiplexed session. This value is only used for the very first multiplexed session
59+
* that is created, and it is only used if the application has not set a waitForMinSessions value.
60+
* If waitForMinSessions has been set, then the client will retry until the duration in
61+
* waitForMinSessions has been reached.
62+
*/
63+
private static final int MAX_INITIAL_CREATE_SESSION_ATTEMPTS = 10;
64+
5665
@VisibleForTesting
5766
static final Statement DETERMINE_DIALECT_STATEMENT =
5867
Statement.newBuilder(
@@ -229,7 +238,8 @@ public void close() {
229238

230239
Duration waitDuration =
231240
sessionClient.getSpanner().getOptions().getSessionPoolOptions().getWaitForMinSessions();
232-
int initialAttempts = waitDuration == null || waitDuration.isZero() ? 10 : 1;
241+
int initialAttempts =
242+
waitDuration == null || waitDuration.isZero() ? MAX_INITIAL_CREATE_SESSION_ATTEMPTS : 1;
233243
asyncCreateMultiplexedSession(initialSessionReferenceFuture, initialAttempts);
234244
maybeWaitForSessionCreation(
235245
sessionClient.getSpanner().getOptions().getSessionPoolOptions(),

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,21 @@ public void testRetryWithNoSessionCreationWaitTime() {
377377
});
378378
assertEquals(ErrorCode.DEADLINE_EXCEEDED, spannerException.getErrorCode());
379379

380+
// The CreateSession RPC will be retried, and as the exception is removed by the first call,
381+
// the second attempt will succeed.
382+
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
383+
//noinspection StatementWithEmptyBody
384+
while (resultSet.next()) {
385+
// ignore
386+
}
387+
}
388+
380389
List<CreateSessionRequest> createSessionRequests =
381390
mockSpanner.getRequestsOfType(CreateSessionRequest.class);
382-
assertEquals(1, createSessionRequests.size());
391+
assertEquals(2, createSessionRequests.size());
383392

384393
List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
385-
assertEquals(0, requests.size());
394+
assertEquals(1, requests.size());
386395

387396
testSpanner.close();
388397
}

0 commit comments

Comments
 (0)