Uh oh!
There was an error while loading. Please reload this page.
Add on_kill to Databricks Workflow Operator - #42115
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
70f8c96 to
c3f1e9bComparec3f1e9b to
b80e162Compare8a86b3b to
ac988bbCompareac988bb to
532feb3CompareR7L208
commented
Oct 1, 2024
hey @pankajkoti - Any ETA on when you'd be able to review this PR? 🙏 |
pankajkoti
left a comment
There was a problem hiding this comment.
hi @R7L208 Apologies, I missed reviewing it so far.
I am happy to review the changes for databricks_workflow.py but not so comfortable yet reviewing the changes in databricks_sql.py (operators & hooks) as I do not have enough expertise on the changes made there. Would you please to separate out the two changes(move out databricks_sql.py related changes to another PR) and then we can invite some expert to review the other PR?
532feb3 to
10ceb61CompareR7L208
commented
Oct 2, 2024
Opened #42668 @pankajkoti@eladkal - can you please assign someone to review? |
on_kill or equivalent to Databricks Operators/Hooks to cancel timed out querieson_kill to Databricks Workflow Operator to cancel timed out queriesd45c9d9 to
bf5237aComparepankajkoti
commented
Oct 2, 2024
@R7L208 Can you please update the PR description based on the altered scope of this PR? |
on_kill to Databricks Workflow Operator to cancel timed out querieson_kill to Databricks Workflow OperatorR7L208
commented
Oct 2, 2024
@pankajkoti - it's been updated |
bf5237a to
bf0555bCompare
@R7L208 it's not. It mentions about DatabricksSqlHook queries ("SQL queries submitted by DatabricksSqlHook") & using threading ("uses threading to cancel SQL queries submitted by DatabricksSqlHook.run()") which we no longer have in this PR. Could you please re-read the description and update to what's limited to the scope of this PR. Also, _CreateDatabricksWorkflowOperator does not rely on DatabricksSqlHook, but leverages DatabricksHook just in case you missed checking that :) |
R7L208
commented
Oct 2, 2024
@pankajkoti - Apologies! I read PR title instead of PR description 🤦 PR description is now updated |
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
* add on_kill override to databricks workflow operator * on_kill equivalent for DatabricksSqlOperator * add tests for create_timeout_thread * add note for on_kill in DatabricksCopyIntoOperator * chore: static checks * remove changes for databricks_sql.py for PR isolated to databricks_workflows.py --------- Co-authored-by: Lorin <lorin@databricks.com>
* add on_kill override to databricks workflow operator * on_kill equivalent for DatabricksSqlOperator * add tests for create_timeout_thread * add note for on_kill in DatabricksCopyIntoOperator * chore: static checks * remove changes for databricks_sql.py for PR isolated to databricks_workflows.py --------- Co-authored-by: Lorin <lorin@databricks.com>
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed. DatabricksTaskBaseOperator — used by DatabricksTaskOperator and DatabricksNotebookOperator — is missing the same implementation, so Databricks jobs continue running after the Airflow task is killed, orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. Uses self.databricks_run_id which is initialised to None in __init__ and set by _launch_job() the moment the run is submitted.
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, and workflow-member regression (parent run_id=1, child run_id=999, asserts cancel_run(999)).
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, and workflow-member regression (parent run_id=1, child run_id=999, asserts cancel_run(999)).
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
…ll (#69442) DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in #42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
…ll (apache#69442) DatabricksSubmitRunOperator and DatabricksRunNowOperator both implement on_kill() to cancel the Databricks run when an Airflow task is killed (SIGTERM or execution_timeout). DatabricksTaskBaseOperator — the base for DatabricksTaskOperator and DatabricksNotebookOperator — was missing the same implementation, leaving Databricks jobs running after the Airflow task was killed and orphaning compute resources. DatabricksWorkflowTaskGroup received on_kill() in apache#42115; this PR closes the remaining gap for standalone task operators. For workflow members self.databricks_run_id is the shared parent run ID; cancelling it would stop all sibling tasks. on_kill() therefore calls _get_current_databricks_task()["run_id"] to target only the current task's own child run, mirroring monitor_databricks_job. Standalone operators continue to cancel via self.databricks_run_id directly. If resolving the child run_id fails (API error, task_key mismatch), on_kill logs the exception and returns without cancelling anything — falling back to the parent run_id would stop sibling tasks, defeating the purpose. Unit tests cover: cancel called for standalone operator, no-op when databricks_run_id is None, workflow-member cancels child run (parent=1, child=999, asserts cancel_run(999)), and workflow-member where _get_current_databricks_task raises asserts cancel_run not called.
The Databricks Provider did not implement
on_killto cancel tasks generated by_CreateDatabricksWorkflowOperator. This led to data quality issues, where Airflow would report a cancellation due to timeout; however, the corresponding workflow task would continue to run on Databricks.This PR implements
on_killfor_CreateDatabricksWorkflowOperator.^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.