Replace reattach_on_restart with durable execution in KPO#69914
Replace reattach_on_restart with durable execution in KPO#69914amoghrajesh wants to merge 2 commits into
reattach_on_restart with durable execution in KPO#69914Conversation
|
with but with thanks |
|
@raphaelauv good comment, but that's covered already. So, the crash-before-persist window youre describing falls to the exact old behavior for that one retry & the operator still checks for a matching pod via labels, same as |
|
thanks for the quick answer :) That's perfect ,also it would be great to make it explicit in the doc |
|
@raphaelauv thanks, handled it in 7a75ba6 |
| :param reattach_on_restart: deprecated, use ``durable`` instead. If the worker dies while the pod | ||
| is running, reattach and monitor during the next try. If False, always create a new pod for | ||
| each try. |
There was a problem hiding this comment.
| :param reattach_on_restart: deprecated, use ``durable`` instead. If the worker dies while the pod | |
| is running, reattach and monitor during the next try. If False, always create a new pod for | |
| each try. | |
| :param reattach_on_restart: deprecated for Airflow 3.3+, use ``durable`` instead. If the worker dies while the pod | |
| is running, reattach and monitor during the next try. If False, always create a new pod for | |
| each try. |
| :param durable: if the worker dies while the pod is running, reattach and monitor during the next | ||
| try instead of creating a duplicate pod. If False, always create a new pod for each try. | ||
| Supersedes ``reattach_on_restart``; on Airflow 3.3+ the reconnection uses a persisted pod | ||
| identity in task state store instead of a label search, removing the ambiguity failure a label | ||
| search can hit when more than one matching pod exists. Defaults to ``True``. |
There was a problem hiding this comment.
| :param durable: if the worker dies while the pod is running, reattach and monitor during the next | |
| try instead of creating a duplicate pod. If False, always create a new pod for each try. | |
| Supersedes ``reattach_on_restart``; on Airflow 3.3+ the reconnection uses a persisted pod | |
| identity in task state store instead of a label search, removing the ambiguity failure a label | |
| search can hit when more than one matching pod exists. Defaults to ``True``. | |
| :param durable: if the worker dies while the pod is running, reattach and monitor during the next | |
| try instead of creating a duplicate pod. If False, always create a new pod for each try. | |
| Supersedes ``reattach_on_restart``; on Airflow 3.3+ the reconnection uses a persisted pod | |
| identity in task state store instead of a label search, removing the ambiguity failure a label | |
| search can hit when more than one matching pod exists. Defaults to ``True``. Only available for Airflow 3.3+ |
| if "reattach_on_restart" in kwargs: | ||
| # Dropped from the named signature entirely so the warning fires on any explicit use, | ||
| # `True` or `False`. | ||
| reattach_on_restart = kwargs.pop("reattach_on_restart") | ||
| if AIRFLOW_V_3_3_PLUS: | ||
| warnings.warn( | ||
| "`reattach_on_restart` is deprecated and will be removed in a future release. " | ||
| "Use `durable` instead.", | ||
| AirflowProviderDeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| durable = reattach_on_restart |
There was a problem hiding this comment.
I think we need also the handle the case of durable with Airflow<3.3
I think for that case we want to just make it work as reattach_on_restart so we want ask them to change parameter name but just handle this for them under the hood?
Was generative AI tooling used to co-author this PR?
Why?
KPO's existing
reattach_on_restartrelies on a label search on every retry, which can raiseFoundMoreThanOnePodFailurewhen more than one matching pod exists, and gives no way to reconnect to a specific pod unambiguously. On Airflow 3.3+, persisting the running pod's identity to task state store lets a retry reconnect directly to that exact pod instead, removing the ambiguity window entirely.reattach_on_restartis deprecated in favor of a new durable flag that supersedes it; existing configurations map onto durable with zero behavior change, and pre-3.3 environments keep today's label-search behavior unchanged.Summary
durableparameter toKubernetesPodOperator(defaultTrue), superseding thedeprecated
reattach_on_restartparameter.durable=Truepersists the running pod's identity (name, namespace, uid)to task state store before the operator waits on it. On retry, the operator reconnects
directly to that pod via a direct
read_namespaced_podlookup instead of a label search --removing the
FoundMoreThanOnePodFailureambiguity window a label search can hit when morethan one matching pod exists.
find_pod()) is retained as a one-time bootstrapfallback: a pod created by a pre-upgrade provider version (no persisted identity yet) is
still found via labels on the first retry after upgrading, and that retry starts persisting
state for every subsequent one. No in-flight task or existing pod breaks across an upgrade.
reattach_on_restartstill works, mapping its value ontodurablewith zero behaviorchange; passing it emits
AirflowProviderDeprecationWarningon Airflow 3.3+ only (below3.3,
durable/task state store don't functionally exist yet, so warning would bepremature).
durable=Falseopts out of task state store entirely, preserving today'sreattach_on_restart=Falsebehavior exactly, including its pre-existing incidental-cleanup quirk (an orphaned pod from
a killed prior attempt can still get found and deleted via unconditional
find_pod()refetch calls elsewhere in
execute_sync/execute_async-- unrelated to and unchanged bythis work).
store.
Testing
Using this dag:
Before my changes:
Worker killed:
But pod still exists:
Reconnected when worker came back up:
After my changes (changing to pass durable=True)
WOrker killed:
Task store persisted:
[Breeze:3.10.20] root@0014bf761b80:/opt/airflow$ cat /tmp/airflow_state/ti_run_pod/pod_identifier.json {"name": "try-kpo-vlap9a9c", "namespace": "default", "uid": "878b321f-fb21-4779-94c4-1811f7ced720"}[Breeze:3.10.20]Pod present and reconnected to via state store:
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.