Skip to content

chore(x-goog-spanner-request-id): more updates for feature completion: WIP #3915

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DatabaseClientImpl implements DatabaseClient {
@VisibleForTesting final MultiplexedSessionDatabaseClient multiplexedSessionDatabaseClient;
@VisibleForTesting final boolean useMultiplexedSessionPartitionedOps;
@VisibleForTesting final boolean useMultiplexedSessionForRW;
private final int dbId;
@VisibleForTesting final int dbId;
private final AtomicInteger nthRequest;
private final Map<String, Integer> clientIdToOrdinalMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,6 @@ public boolean equals(Object o) {
return false;
}
RequestIdOption other = (RequestIdOption) o;
if (this.reqId == null || other.reqId == null) {
return this.reqId == null && other.reqId == null;
}
return Objects.equals(this.reqId, other.reqId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ interface SessionConsumer {
// SessionClient is created long before a DatabaseClientImpl is created,
// as batch sessions are firstly created then later attached to each Client.
private static final AtomicInteger NTH_ID = new AtomicInteger(0);
private final int nthId = NTH_ID.incrementAndGet();
private final int nthId;
private final AtomicInteger nthRequest = new AtomicInteger(0);

@GuardedBy("this")
Expand All @@ -205,6 +205,7 @@ interface SessionConsumer {
this.executorFactory = executorFactory;
this.executor = executorFactory.get();
this.commonAttributes = spanner.getTracer().createCommonAttributes(db);
this.nthId = NTH_ID.incrementAndGet();
}

@Override
Expand All @@ -223,7 +224,7 @@ DatabaseId getDatabaseId() {
@Override
public XGoogSpannerRequestId nextRequestId(long channelId, int attempt) {
return XGoogSpannerRequestId.of(
this.nthId, this.nthRequest.incrementAndGet(), channelId, attempt);
this.nthId, channelId, this.nthRequest.incrementAndGet(), attempt);
}

/** Create a single session. */
Expand Down Expand Up @@ -423,7 +424,7 @@ private List<SessionImpl> internalBatchCreateSessions(
span.addAnnotation(String.format("Requesting %d sessions", sessionCount));
try (IScope s = spanner.getTracer().withSpan(span)) {
XGoogSpannerRequestId reqId =
XGoogSpannerRequestId.of(this.nthId, this.nthRequest.incrementAndGet(), channelHint, 1);
XGoogSpannerRequestId.of(this.nthId, channelHint, this.nthRequest.incrementAndGet(), 1);
List<com.google.spanner.v1.Session> sessions =
spanner
.getRpc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,8 @@ <ReqT, RespT> GrpcCallContext newCallContext(
}
}
if (options != null) {
context = withRequestId(context, options);
// TODO(@odeke-em): Infer the affinity if it doesn't match up with in the request-id.
context = withRequestId(context, options, method);
}
context = context.withExtraHeaders(metadataProvider.newExtraHeaders(resource, projectName));
if (routeToLeader && leaderAwareRoutingEnabled) {
Expand All @@ -2060,15 +2061,44 @@ <ReqT, RespT> GrpcCallContext newCallContext(
if (configurator != null) {
apiCallContextFromContext = configurator.configure(context, request, method);
}

// Debug the call headers before this.
Map<String, List<String>> hdrs = context.getExtraHeaders();
if (false
&& method != null
&& method.getFullMethodName().compareTo("google.spanner.v1.Spanner/DeleteSession") != 0) {
System.out.println(
"\033[32mextraHeaders going out for " + method.getFullMethodName() + "\033[00m");
for (Map.Entry<String, List<String>> entry : hdrs.entrySet()) {
System.out.println(
"\t\033[36mcall.Key: " + entry.getKey() + ":: " + entry.getValue() + "\033[00m");
}
}
return (GrpcCallContext) context.merge(apiCallContextFromContext);
}

GrpcCallContext withRequestId(GrpcCallContext context, Map<SpannerRpc.Option, ?> options) {
<ReqT, RespT> GrpcCallContext withRequestId(
GrpcCallContext context,
Map<SpannerRpc.Option, ?> options,
MethodDescriptor<ReqT, RespT> method) {
XGoogSpannerRequestId reqId = (XGoogSpannerRequestId) options.get(Option.REQUEST_ID);
if (reqId == null) {
return context;
}

if (false
&& method != null
&& method.getFullMethodName().compareTo("google.spanner.v1.Spanner/ExecuteStreamingSql")
== 0) {
System.out.println(
"\033[36mGapiSpannerRpc.withRequestId: "
+ reqId
+ " for: "
+ method.getFullMethodName()
+ " "
+ System.identityHashCode(context)
+ "\033[00m");
}
Map<String, List<String>> withReqId =
ImmutableMap.of(
XGoogSpannerRequestId.REQUEST_HEADER_KEY.name(),
Expand Down
Loading
Loading