Skip to content
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

Fix parent/child spans relationship in Spanner. #3690

Merged
merged 2 commits into from
Sep 27, 2018
Merged
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 @@ -1063,7 +1063,7 @@ ResultSet executeQueryInternalWithOptions(
final int prefetchChunks =
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks;
ResumableStreamIterator stream =
new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY) {
new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY, span) {
@Override
CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) {
GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks);
Expand Down Expand Up @@ -1176,7 +1176,7 @@ ResultSet readInternalWithOptions(
final int prefetchChunks =
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks;
ResumableStreamIterator stream =
new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ) {
new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ, span) {
@Override
CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) {
GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks);
Expand Down Expand Up @@ -1426,7 +1426,7 @@ void commit() {
mutations = null;
}
final CommitRequest commitRequest = builder.build();
Span opSpan = tracer.spanBuilder(COMMIT).startSpan();
Span opSpan = tracer.spanBuilderWithExplicitParent(COMMIT, span).startSpan();
try (Scope s = tracer.withSpan(opSpan)) {
CommitResponse commitResponse =
runWithRetries(
Expand Down Expand Up @@ -2452,20 +2452,20 @@ abstract static class ResumableStreamIterator extends AbstractIterator<PartialRe
*/
private boolean safeToRetry = true;

protected ResumableStreamIterator(int maxBufferSize, String streamName) {
protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) {
checkArgument(maxBufferSize >= 0);
this.maxBufferSize = maxBufferSize;
this.span = tracer.spanBuilder(streamName).startSpan();
this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan();
}

abstract CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken);

@Override
public void close(@Nullable String message) {
span.end();
if (stream != null) {
stream.close(message);
}
span.end();
}

@Override
Expand All @@ -2478,7 +2478,11 @@ protected PartialResultSet computeNext() {
ImmutableMap.of("ResumeToken",
AttributeValue.stringAttributeValue(
resumeToken == null ? "null" : resumeToken.toStringUtf8())));
stream = checkNotNull(startStream(resumeToken));
try (Scope s = tracer.withSpan(span)) {
// When start a new stream set the Span as current to make the gRPC Span a child of
// this Span.
stream = checkNotNull(startStream(resumeToken));
}
}
// Buffer contains items up to a resume token or has reached capacity: flush.
if (!buffer.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void setUp() {

private void initWithLimit(int maxBufferSize) {
iterator =
new SpannerImpl.ResumableStreamIterator(maxBufferSize, "") {
new SpannerImpl.ResumableStreamIterator(maxBufferSize, "", null) {
@Override
SpannerImpl.CloseableIterator<PartialResultSet> startStream(
@Nullable ByteString resumeToken) {
Expand Down