-
Notifications
You must be signed in to change notification settings - Fork 132
chore(x-goog-spanner-request-id): add SessionImpl.getChannel() and Options.RequestIdOption.(equals, hashCode) #3900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,7 +319,7 @@ public CommitResponse writeAtLeastOnceWithOptions( | |
private XGoogSpannerRequestId reqIdOrFresh(Options options) { | ||
XGoogSpannerRequestId reqId = options.reqId(); | ||
if (reqId == null) { | ||
reqId = this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 1); | ||
reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 1); | ||
} | ||
return reqId; | ||
} | ||
|
@@ -464,17 +464,15 @@ public AsyncTransactionManagerImpl transactionManagerAsync(TransactionOption... | |
|
||
@Override | ||
public ApiFuture<Empty> asyncClose() { | ||
XGoogSpannerRequestId reqId = | ||
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 0); | ||
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the initial attempt 0 here and in the |
||
return spanner.getRpc().asyncDeleteSession(getName(), reqId.withOptions(getOptions())); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
ISpan span = tracer.spanBuilder(SpannerImpl.DELETE_SESSION); | ||
try (IScope s = tracer.withSpan(span)) { | ||
XGoogSpannerRequestId reqId = | ||
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 0); | ||
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 0); | ||
spanner.getRpc().deleteSession(getName(), reqId.withOptions(getOptions())); | ||
} catch (RuntimeException e) { | ||
span.setStatus(e); | ||
|
@@ -505,8 +503,7 @@ ApiFuture<Transaction> beginTransactionAsync( | |
} | ||
final BeginTransactionRequest request = requestBuilder.build(); | ||
final ApiFuture<Transaction> requestFuture; | ||
XGoogSpannerRequestId reqId = | ||
this.getRequestIdCreator().nextRequestId(1 /* TODO: channelId */, 1); | ||
XGoogSpannerRequestId reqId = this.getRequestIdCreator().nextRequestId(this.getChannel(), 1); | ||
try (IScope ignore = tracer.withSpan(span)) { | ||
requestFuture = | ||
spanner | ||
|
@@ -597,4 +594,12 @@ public void setRequestIdCreator(XGoogSpannerRequestId.RequestIdCreator creator) | |
public XGoogSpannerRequestId.RequestIdCreator getRequestIdCreator() { | ||
return this.requestIdCreator; | ||
} | ||
|
||
int getChannel() { | ||
if (getIsMultiplexed()) { | ||
return 0; | ||
} | ||
Comment on lines
+599
to
+601
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that this means that we will be getting the channel that is being used in a different way for multiplexed sessions, and that this method is only intended for actual use with regular sessions. |
||
Long channelHint = (Long) this.getOptions().get(SpannerRpc.Option.CHANNEL_HINT); | ||
return (int) (channelHint % this.spanner.getOptions().getNumChannels()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tip for next time (just leave as-is for now);Java has a utility method for this: