amoghrajesh opened a new pull request, #76295:
URL: https://github.com/apache/airflow/pull/76295
<!-- SPDX-License-Identifier: Apache-2.0
https://www.apache.org/licenses/LICENSE-2.0 -->
<!--
Thank you for contributing!
Please provide above a brief description of the changes made in this pull
request.
Write a good git commit message following this guide:
https://chris.beams.io/posts/git-commit/
Please make sure that your code changes are covered with tests.
And in case of new features or big changes remember to adjust the
documentation.
For user-facing UI changes, please attach before/after screenshots (or a
short
screen recording) so reviewers can assess the visual impact.
Feel free to ping (in general) for the review if you do not see reaction for
a few days
(72 Hours is the minimum reaction time you can expect from volunteers) - we
sometimes miss notifications.
In case of an existing issue, reference it using one of the following:
* closes: #ISSUE
* related: #ISSUE
-->
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR,
please
change below checkbox to `[X]` followed by the name of the tool, uncomment
the "Generated-by".
-->
- [ ] Yes (please specify the tool below)
<!--
Generated-by: [Tool Name] following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
-->
`DatabricksNotebookOperator` and `DatabricksTaskOperator` now reconnect to a
run they already submitted instead of submitting a new one after a worker crash.
Before this change, a worker that died during the poll loop left the
Databricks run executing with no Airflow task watching it, and the retry called
`runs/submit` again. Two runs, two bills, one of them orphaned.
`DatabricksSubmitRunOperator` and `DatabricksRunNowOperator` already guard
against this through `ResumableJobMixin`; these two did not.
`DatabricksTaskBaseOperator` now mixes in `ResumableJobMixin` and implements
the six hooks it needs. The run id goes to the task state store before polling
starts, so on retry the operator asks Databricks about the stored
run and either reconnects to it, returns early if it already succeeded, or
submits fresh if it failed terminally.
### Scope
Only the standalone path. Inside a `DatabricksWorkflowTaskGroup` the run is
submitted by the `.launch` task and the run id reaches each leaf through xcom,
so a retry already reconnects to the shared run. That branch of `execute()`
keeps its existing behaviour, and a test pins it.
Two sentences in `notebook.rst` and `task.rst` claimed that "each retry
submits a new Databricks run" for a standalone operator. Both now describe what
the operator does.
### Compatibility
`durable` defaults to `True`, so existing Dags pick up reconnection with no
change. Pass `durable=False` to keep submitting a new run on every retry.
On Airflow below 3.3 the `common.compat` stand-in takes over and the
operators behave as they did before, since the task state store does not exist
there. The provider already imports the mixin through `common.compat.sdk`, so
nothing new enters the dependency surface.
### Testing
Using this Dag:
```python
from __future__ import annotations
from datetime import datetime, timedelta
from airflow.providers.databricks.operators.databricks import (
DatabricksNotebookOperator,
DatabricksTaskOperator,
)
from airflow.sdk import DAG
CONN_ID = "databricks_default"
NOTEBOOK_PATH = "/Users/[email protected]/sleepy"
with DAG(
dag_id="databricks_durable_manual",
schedule=None,
start_date=datetime(2024, 1, 1),
catchup=False,
default_args={"retries": 2, "retry_delay": timedelta(seconds=30)},
tags=["manual", "durable"],
):
DatabricksNotebookOperator(
task_id="notebook",
databricks_conn_id=CONN_ID,
notebook_path=NOTEBOOK_PATH,
source="WORKSPACE",
polling_period_seconds=10,
)
DatabricksTaskOperator(
task_id="task",
databricks_conn_id=CONN_ID,
task_config={"notebook_task": {"notebook_path": NOTEBOOK_PATH,
"source": "WORKSPACE"}},
polling_period_seconds=10,
)
```
For both the tasks try 1:
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/b8aa044b-513c-4681-80dd-f37ae3513d5a"
/>
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/7a1d8f3b-6521-47f7-a66b-bdac0c607559"
/>
Killed the worker right after
State store for both:
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/2898cee0-904f-480e-99b9-cceb7e6af206"
/>
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/245c7826-dac5-4d6b-a2ff-93828f001ca2"
/>
Try 2 for both
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/736e0d04-26b0-4d05-b6d6-670e7a661b4b"
/>
<img width="2555" height="1159" alt="image"
src="https://github.com/user-attachments/assets/a8640b9c-4593-46c3-8b03-dfe601934fba"
/>
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information. Note: commit author/co-author name and email in commits
become permanently public when merged.
* For fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]