Skip to content

Commit 633c3b0

Browse files
committed
chore(x-goog-spanner-request-id): add SessionImpl.getChannel()
Implements channelId retrieval that'll then be used to plumb into x-goog-spanner-request-id's channel. Fixes #3899
1 parent 0906eac commit 633c3b0

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/SessionImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public CommitResponse writeAtLeastOnceWithOptions(
319319
private XGoogSpannerRequestId reqIdOrFresh(Options options) {
320320
XGoogSpannerRequestId reqId = options.reqId();
321321
if (reqId == null) {
322-
reqId = this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 1);
322+
reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 1);
323323
}
324324
return reqId;
325325
}
@@ -464,17 +464,15 @@ public AsyncTransactionManagerImpl transactionManagerAsync(TransactionOption...
464464

465465
@Override
466466
public ApiFuture<Empty> asyncClose() {
467-
XGoogSpannerRequestId reqId =
468-
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 0);
467+
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 0);
469468
return spanner.getRpc().asyncDeleteSession(getName(), reqId.withOptions(getOptions()));
470469
}
471470

472471
@Override
473472
public void close() {
474473
ISpan span = tracer.spanBuilder(SpannerImpl.DELETE_SESSION);
475474
try (IScope s = tracer.withSpan(span)) {
476-
XGoogSpannerRequestId reqId =
477-
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 0);
475+
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 0);
478476
spanner.getRpc().deleteSession(getName(), reqId.withOptions(getOptions()));
479477
} catch (RuntimeException e) {
480478
span.setStatus(e);
@@ -505,8 +503,7 @@ ApiFuture<Transaction> beginTransactionAsync(
505503
}
506504
final BeginTransactionRequest request = requestBuilder.build();
507505
final ApiFuture<Transaction> requestFuture;
508-
XGoogSpannerRequestId reqId =
509-
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 1);
506+
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 1);
510507
try (IScope ignore = tracer.withSpan(span)) {
511508
requestFuture =
512509
spanner
@@ -597,4 +594,9 @@ public void setRequestIdCreator(XGoogSpannerRequestId.RequestIdCreator creator)
597594
public XGoogSpannerRequestId.RequestIdCreator getRequestIdCreator() {
598595
return this.requestIdCreator;
599596
}
597+
598+
int getChannel() {
599+
Long channelHint = (Long) this.getOptions().get(SpannerRpc.Option.CHANNEL_HINT);
600+
return (int) (channelHint % this.spanner.getOptions().getNumChannels());
601+
}
600602
}

0 commit comments

Comments
 (0)