This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new c211ae09ed retry commit on MySQL deadlocks during backfill (#22696)
c211ae09ed is described below

commit c211ae09ed0e4c680d4a91e4036975497f933aa1
Author: QP Hou <[email protected]>
AuthorDate: Mon Apr 4 05:51:20 2022 -0700

    retry commit on MySQL deadlocks during backfill (#22696)
---
 airflow/jobs/backfill_job.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/airflow/jobs/backfill_job.py b/airflow/jobs/backfill_job.py
index d5a5761abe..5d8434647d 100644
--- a/airflow/jobs/backfill_job.py
+++ b/airflow/jobs/backfill_job.py
@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, Any, Dict, Iterable, 
Iterator, List, Optional,
 
 import attr
 import pendulum
+from sqlalchemy.exc import OperationalError
 from sqlalchemy.orm.session import Session, make_transient
 from tabulate import tabulate
 
@@ -488,6 +489,13 @@ class BackfillJob(BaseJob):
                         ti.queued_by_job_id = self.id
                         ti.queued_dttm = timezone.utcnow()
                         session.merge(ti)
+                        try:
+                            session.commit()
+                        except OperationalError:
+                            self.log.exception("Failed to commit task state 
change due to operational error")
+                            session.rollback()
+                            # early exit so the outer loop can retry
+                            return
 
                         cfg_path = None
                         if self.executor_class in (
@@ -507,7 +515,6 @@ class BackfillJob(BaseJob):
                         )
                         ti_status.running[key] = ti
                         ti_status.to_run.pop(key)
-                    session.commit()
                     return
 
                 if ti.state == TaskInstanceState.UPSTREAM_FAILED:

Reply via email to