perf(spanner): complete query stream immediately on PartialResultSet.last - #9258
Open
olavloite wants to merge 1 commit into
Open
perf(spanner): complete query stream immediately on PartialResultSet.last#9258olavloite wants to merge 1 commit into
olavloite wants to merge 1 commit into
Conversation
…last Optimizes query streaming completion and server-side RPC status by leveraging PartialResultSet.last: 1. Latency: Completes user stream immediately upon receiving chunk.last = true via this.push(null) and next(), bypassing the wait for gRPC trailers, the gRPC 'end' event, and secondary flush ticks. 2. Graceful Drain: Detaches the underlying gRPC request stream from the pipeline and calls resume() when chunk.last is true. This allows trailing gRPC metadata and EOF to drain asynchronously in the background without canceling the call, preventing successful queries from being reported as CANCELLED in Cloud Monitoring. 3. Natural Lifecycle: Signals requestsStream.end() on chunk.last so EOF cascades through CheckpointStream and PartialResultStream naturally, allowing 'finish', 'close', and stream.finished() to resolve cleanly without ad-hoc stream destruction. 4. Error Safety: Symmetrically detaches error/end listeners and attaches a no-op error handler during background drain to prevent late socket resets from triggering retries or unhandled exceptions.
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves the handling of the final chunk (chunk.last) in PartialResultStream. Specifically, it ensures that when the last chunk is received, the stream is flushed immediately, the request stream is resumed to drain remaining trailers/EOF in the background (preventing CANCELLED status), and the stream is properly cleaned up without premature destruction. A comprehensive suite of unit tests has been added to verify these behaviors. There are no review comments, so I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimizes query streaming completion and server-side RPC status by leveraging PartialResultSet.last: