Skip to content

Cancel the Redshift statement when a user kills the deferred task#69631

Closed
steveahnahn wants to merge 1 commit into
apache:mainfrom
steveahnahn:redshift-cancel-statement-on-user-kill-deferred
Closed

Cancel the Redshift statement when a user kills the deferred task#69631
steveahnahn wants to merge 1 commit into
apache:mainfrom
steveahnahn:redshift-cancel-statement-on-user-kill-deferred

Conversation

@steveahnahn

Copy link
Copy Markdown
Contributor

Problem

A deferred RedshiftDataOperator parks its query in the triggerer, so the operator's own on_kill no longer runs once the task is deferred. When a user marks that task failed, clears it, or marks it success, RedshiftDataTrigger had no on_kill hook, so the Redshift statement kept running against the cluster or workgroup even though the operator already cancels the statement on kill in the non-deferred path.

On Redshift Serverless a runaway statement keeps billing RPU hours, and on a provisioned cluster it holds a WLM slot, until it finishes on its own.

Change

RedshiftDataTrigger gains an on_kill that cancels the running statement when the user acts on the deferred task, using the hook's async connection (cancel_statement). This matches the behaviour already shipped for the EMR, Dataproc, BigQuery, and Dataflow triggers, and closes the last common AWS gap from the deferrable on_kill work tracked in #36090.

A cancel_on_kill flag (default True) is added to both RedshiftDataOperator and RedshiftDataTrigger so users can opt out, and the operator threads it into the trigger at the defer site. Cancellation is best effort: failures while cancelling are logged and swallowed so the trigger teardown is not blocked.

Precedent

Tests

Trigger tests cover cancel on kill, the disabled and missing statement id no ops, best effort error swallowing, and serialization of the new flag. Operator tests cover the cancel_on_kill=False guard and that the flag is threaded into the trigger on defer. Every new assertion fails without the source change.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5)

Generated-by: Claude Code (Fable 5) following the guidelines

@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Jul 8, 2026
A deferred RedshiftDataOperator parks its query in the triggerer, so the
operator's own on_kill no longer runs once the task is deferred. When a user
marks that task failed, clears it, or marks it success, the trigger had no
on_kill hook, so the Redshift statement kept running against the cluster or
workgroup even though the operator already cancels the statement on kill in
the non-deferred path. On Redshift Serverless a runaway statement keeps
billing RPU-hours, and on a provisioned cluster it holds a WLM slot, until it
finishes on its own.

This adds on_kill to RedshiftDataTrigger to cancel the running statement when
the user acts on the deferred task, matching the behaviour already shipped for
the EMR, Dataproc, BigQuery, and Dataflow triggers. A cancel_on_kill flag on
both the operator and the trigger lets users opt out.
@steveahnahn
steveahnahn force-pushed the redshift-cancel-statement-on-user-kill-deferred branch from bde227d to a742e90 Compare July 9, 2026 01:03
@steveahnahn steveahnahn closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant