Skip to content

[Spark] Structured streaming runner: asynchronous cancel() should not report CANCELLED before the execution ended #40120

Open

Description

@tkaymak

SparkStructuredStreamingPipelineResult.cancel() requests cancellation asynchronously and sets the state to CANCELLED at once. Per the PipelineResult contract the state should be observed: getState() queries the execution, waitUntilFinish() blocks until the pipeline is actually cancelled on the (mini) cluster, and only then the state becomes CANCELLED.

Changing this touches the shared StructuredStreamingPipelineStateTest, which asserts CANCELLED right after cancel() for the batch path today, and the legacy SparkPipelineResult has the same shape. Scope: runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/SparkStructuredStreamingPipelineResult.java and that test.

Follow up from #40103 / Part of #36841

Activity

  1. tkaymak commented on Sep 14, 2026

    @tkaymak
    ContributorAuthor

    Also part of this: cancel() called after the execution already ended, but before anyone observed it, currently reports CANCELLED instead of the real DONE or FAILED. The state query should resolve that from the execution.

  2. singhmrinal02 commented on Sep 16, 2026

    @singhmrinal02
    Contributor

    Hi, I'd like to work on this issue. I'm familiar with Java and I'm willing to learn the relevant Beam/Spark code. Could you please assign this issue to me?

  3. tkaymak commented on Sep 16, 2026

    @tkaymak
    ContributorAuthor

    Hi @singhmrinal02
    I am not looking at this exact issue in the next 7 days, as I am afk.
    I would continue with the overall effort (#36841), when I am back.
    I think it makes sense to coordinate there.

  4. tkaymak commented on Sep 23, 2026

    @tkaymak
    ContributorAuthor

    Hi @singhmrinal02, I am back. Please go ahead, the issue is yours. I am not touching this code for now, my next work on #36841 is the state internals for slice 5.

    A few pointers:

    1. The main change is in SparkStructuredStreamingPipelineResult.cancel() and getState(). The state should come from the execution, so a cancel after the job already ended reports DONE or FAILED.
    2. StructuredStreamingPipelineStateTest asserts CANCELLED right after cancel(). Those assertions need to move behind waitUntilFinish().
    3. The code is shared by Spark 3 and 4, so please run the tests on both, :runners:spark:3:test and :runners:spark:4:test.
    4. Every test that cancels must also call waitUntilFinish(). Otherwise the session gets stopped under the next test class. This broke the Spark Versions precommit once on [Spark] Make cancel() cancel the Spark jobs and stop only a session the runner created #40103.

    Abacn reviewed #40103 and will likely review this one. He prefers no blocking waits or extra locks in cancel().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions