[FEAT] Cancel server-side query when caller context is cancelled (#126)#182
Open
40u5 wants to merge 1 commit into
Open
[FEAT] Cancel server-side query when caller context is cancelled (#126)#18240u5 wants to merge 1 commit into
40u5 wants to merge 1 commit into
Conversation
Fixes apache#126. dataframe.Collect(ctx) previously dropped the gRPC stream locally on ctx cancellation but left the Spark executor running until the 5-minute idle timeout. This change: - Adds Interrupt(ctx, type, idOrTag) to the SparkConnectClient interface and to sparkConnectClientImpl, wrapping the existing proto-level Interrupt RPC. - Records the operation id and the caller's context on ExecutePlanClient and arms a watcher in ToTable that sends InterruptRequest{OPERATION_ID} when the caller's ctx is cancelled. - Exposes InterruptAll, InterruptTag, and InterruptOperation on SparkSession so users can also kill operations explicitly. Includes regression tests covering ctx-cancellation -> Interrupt and the new InterruptAll / InterruptOperation paths.
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.
What changes were proposed in this pull request?
Fixes #126.
Interrupt(ctx, interruptType, operationIdOrTag)to theSparkConnectClientinterface (spark/client/base/base.go) and implements it onsparkConnectClientImpl(spark/client/client.go), wrapping the proto-levelInterruptRPC and branching onINTERRUPT_TYPE_ALL/TAG/OPERATION_ID.ExecutePlanClientnow remembers the caller'scontext.Context, the operation id, and a back-reference to the client.ToTablearms a watcher goroutine that, oncallerCtx.Done(), sendsInterruptRequest{OPERATION_ID, operationId}using a detached 10 s context so the cancellation actually reaches the server.InterruptAll,InterruptTag, andInterruptOperationonSparkSession(spark/sql/sparksession.go) so users can also kill operations explicitly, mirroring PySpark.spark/mocks/mock_executor.goto satisfy the extended interface.Why are the changes needed?
As reported in #126,
dataframe.Collect(ctx)previously dropped the gRPC stream locally when the caller cancelledctx, but the Spark executor kept running the query until the server's idle timeout (5 min). This addresses all three follow-ups from @grundprinzip's reply on the issue:InterruptTagonSparkSession.InterruptOperationonSparkSession.Does this PR introduce any user-facing change?
Yes — additive only:
SparkSessiongainsInterruptAll(ctx),InterruptTag(ctx, tag), andInterruptOperation(ctx, operationId), each returning the server-reported list of interrupted operation ids.context.Contextpassed toCollect/ExecutePlan/ExecuteCommandnow causes the server-side operation to be interrupted instead of running to idle timeout.No backward-incompatible breakages for users — the
SparkConnectClientinterface gains a method, but it has no known external implementers; the in-treemocks.TestExecutoris updated in the same commit.How was this patch tested?
Added three unit tests in
spark/client/client_test.go:TestExecutePlanCancellingContextSendsInterrupt— uses aRecv-blocking stream and verifies that cancellingctxtriggers anInterruptRequestwithINTERRUPT_TYPE_OPERATION_IDand the matching operation id within 2 s.TestInterruptAllCallsClient— verifiesInterrupt(ALL, "")plumbs through.TestInterruptOperationCallsClient— verifiesInterrupt(OPERATION_ID, opID)plumbs through.go build ./...,go vet ./...,gofmt -l ./spark(no diff), andgo test ./spark/...(all packages PASS) run cleanly. The only failure undergo test ./...is the existinginternal/tests/integrationsuite, which requiresSPARK_HOMEto be set and is unrelated to this change.