[grpc-query] Respect client cancellations/disconnections#19005
Open
bsmithgall wants to merge 3 commits intoapache:masterfrom
Open
[grpc-query] Respect client cancellations/disconnections#19005bsmithgall wants to merge 3 commits intoapache:masterfrom
bsmithgall wants to merge 3 commits intoapache:masterfrom
Conversation
`maven-enforce-plugin`'s `RequireUpperBoundDeps` rule caught this change due to a transitive dependency from `assertj-core:3.27.7`.
This change allows in-flight queries to be cancelled (for example, by a gRPC client) by accepting a disconnection callback.
When a gRPC client disconnects or cancels, forward that cancellation signal into the in-flight Druid query and return `Status.CANCELLED` by: 1. Registering a gRPC `Context.CancellationListener` 2. Invoking `DirectStatement.cancel()` for SQL queries and `QueryScheduler.cancelQuery()` for native queries 3. Mapping exceptions back to the correct status codes In addition, guard against possible cancellation in the event that the cancellation happens before the listener callback is fully registered.
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.
Description
Add support for in-flight Druid query cancellation after a gRPC client disconnects or cancels. Previously, these events were ignored, leading to queries continuing to run. Now, these cancellations forward that signal into Druid by:
Context.CancellationListenerDirectStatement.cancel()for SQL queries andQueryScheduler.cancelQuery()for native queriesQueryInterruptedExceptionto appropriate gRPC status codesThis change uses an
AtomicReferenceto handle a race condition where the client cancels after the listener is registered but before the callback is set. We usegetAndSet()to ensure cancellation is fired at most once.Release note
The gRPC query extension now cancels in-flight queries when clients cancel/disconnect.
Key changed/added classes in this PR
QueryServiceQueryDriverGrpcEndpointInitializerQueryServiceTestThis PR has: