Skip to content

Commit 7e3ed4c

Browse files
committed
More code review updates
1 parent 8234a26 commit 7e3ed4c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ interface SessionConsumer {
185185

186186
// SessionClient is created long before a DatabaseClientImpl is created,
187187
// as batch sessions are firstly created then later attached to each Client.
188-
private static AtomicInteger NTH_ID = new AtomicInteger(0);
189-
private final int nthId;
190-
private final AtomicInteger nthRequest;
188+
private static final AtomicInteger NTH_ID = new AtomicInteger(0);
189+
private final int nthId = NTH_ID.incrementAndGet();
190+
private final AtomicInteger nthRequest = new AtomicInteger(0);
191191

192192
@GuardedBy("this")
193193
private volatile long sessionChannelCounter;
@@ -201,8 +201,6 @@ interface SessionConsumer {
201201
this.executorFactory = executorFactory;
202202
this.executor = executorFactory.get();
203203
this.commonAttributes = spanner.getTracer().createCommonAttributes(db);
204-
this.nthId = SessionClient.NTH_ID.incrementAndGet();
205-
this.nthRequest = new AtomicInteger(0);
206204
}
207205

208206
@Override
@@ -220,7 +218,8 @@ DatabaseId getDatabaseId() {
220218

221219
@Override
222220
public XGoogSpannerRequestId nextRequestId(long channelId, int attempt) {
223-
return XGoogSpannerRequestId.of(this.nthId, this.nthRequest.incrementAndGet(), channelId, 1);
221+
return XGoogSpannerRequestId.of(
222+
this.nthId, this.nthRequest.incrementAndGet(), channelId, attempt);
224223
}
225224

226225
/** Create a single session. */
@@ -287,6 +286,9 @@ SessionImpl createMultiplexedSession() {
287286
spanner
288287
.getTracer()
289288
.spanBuilder(SpannerImpl.CREATE_MULTIPLEXED_SESSION, this.commonAttributes);
289+
// MultiplexedSession doesn't use a channelId hence this hard-coded value.
290+
int channelId = 0;
291+
XGoogSpannerRequestId reqId = nextRequestId(channelId, 1);
290292
try (IScope s = spanner.getTracer().withSpan(span)) {
291293
com.google.spanner.v1.Session session =
292294
spanner
@@ -295,7 +297,7 @@ SessionImpl createMultiplexedSession() {
295297
db.getName(),
296298
spanner.getOptions().getDatabaseRole(),
297299
spanner.getOptions().getSessionLabels(),
298-
null,
300+
createRequestOptions(channelId, reqId),
299301
true);
300302
SessionImpl sessionImpl =
301303
new SessionImpl(

0 commit comments

Comments
 (0)