Skip to content

Fix duplicate Dataproc job submission after a triggerer restart - #72685

Merged
shahar1 merged 5 commits into
apache:mainfrom
rjgoyln:fix/dataproc-direct-trigger-job-id
Sep 19, 2026
Merged

shahar1 merged 5 commits into
apache:mainfrom
rjgoyln:fix/dataproc-direct-trigger-job-id

Conversation

@rjgoyln

@rjgoyln rjgoyln commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

DataprocSubmitJobDirectTrigger — the start_from_trigger path of DataprocSubmitJobOperator — learns the job id only from the submit response, and cannot write it back into the Trigger row it is inflated from. Two ways to lose a job follow:

  • a triggerer that restarts mid-job re-enters run() and submits a second Dataproc job, leaving the first untracked
  • a kill that lands while the submit call is in flight leaves on_kill() with no id, so the job it created keeps running

On Airflow 3.3+ the second symptom also needs #72591, which restores the CancelledError propagation on_kill() is reached through.

Change

  • assign the job id before submitting instead of reading it from the response
  • default request_id to that same id
  • resume polling on AlreadyExists, but only for a job this trigger named
  • tolerate NotFound when cancelling a job that may never have reached Dataproc

The id must be derivable rather than remembered: the Trigger row's kwargs come from start_trigger_args, so nothing the trigger learns at runtime survives its re-creation. The trigger row id and the task instance uuid are both re-injected from the database on every inflation — the row id pins one deferral, and the uuid is reissued per try, so a retry submits a new job while a restart returns to the old one.

Being a uuid, it also separates two deployments that share a Dataproc project. Airflow 2 has no such column and falls back to the task identity, which is unique only within one deployment.

Resuming is decided by the job id alone: a job the caller named is never adopted, whatever request_id is in play.

Behavior change

Jobs submitted through start_from_trigger now carry an Airflow-assigned id (airflow-<hash>) rather than one generated by Dataproc.


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

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

@boring-cyborg boring-cyborg Bot added area:providers provider:google Google (including GCP) related issues labels Sep 8, 2026
DataprocSubmitJobDirectTrigger only learns the job id from the submit
response, and nothing carries that id back into the trigger's serialized
kwargs. A triggerer that restarts while the job is running therefore
re-runs run() from the top and submits a second job, and a kill that
lands while the submit call is in flight leaves behind a job that
on_kill() has no id to cancel.
The task identity the id was derived from is only unique within one
deployment. Two Airflow instances that share a Dataproc project and run
the same Dag can converge on the same id, and a metadata database
restored from another deployment makes that a certainty rather than a
coincidence. The trigger would then take the other deployment's job for
its own earlier submission, poll it, and cancel it on kill.

The task instance uuid is reissued per try and is unique across
deployments, so it carries the whole identity on its own. Airflow 2 has
no such column and keeps the task identity as its fallback.
The resume path keyed off self.job_id, which only means "the trigger
named this job" for as long as nothing sets that attribute earlier.
Setting it from a caller-supplied job reference -- the obvious way to
give on_kill() an id for a job the caller named -- would quietly turn
the guard into its opposite, and no test covered the branch that
refuses to resume.
Whether an AlreadyExists may resume polling has to read as a statement
about job id ownership: a job the caller named is never adopted, and one
the trigger named always is, whatever request_id happens to be in play.
Only two of the four caller id combinations were exercised, so nothing
stopped the rule from drifting onto request_id.

on_kill() tolerating a NotFound also has to stay narrow, or a kill that
cannot reach Dataproc at all would look like a job that was never there.
@rjgoyln
rjgoyln force-pushed the fix/dataproc-direct-trigger-job-id branch from 61dedf6 to 5f1fe79 Compare September 19, 2026 07:14
@rjgoyln
rjgoyln marked this pull request as ready for review September 19, 2026 07:17
@rjgoyln
rjgoyln requested a review from shahar1 as a code owner September 19, 2026 07:17
The method is an internal step of run(), not something a Dag author or
another provider has any reason to call, and a public name on a trigger
class is part of what the provider promises to keep.
@shahar1
shahar1 merged commit f8d6f40 into apache:main Sep 19, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants