dheerajturaga commented on code in PR #73763:
URL: https://github.com/apache/airflow/pull/73763#discussion_r4166654074


##########
airflow-core/src/airflow/models/dag.py:
##########
@@ -509,6 +509,24 @@ def set_scheduling_state(self, state: DagSchedulingState) 
-> None:
         self.is_paused = state == DagSchedulingState.PAUSED
         self.is_draining = state == DagSchedulingState.DRAINING
 
+    @classmethod
+    def start_drain(cls, dag_id: str, *, session: Session) -> None:
+        """
+        Put the Dag into the draining state.
+
+        Call this in the transaction that creates the explicit run the drain 
is started for,
+        before the run is inserted. The row lock keeps 
``_finalize_draining_dags`` from
+        pausing the Dag before that run is committed. Taking it after the 
insert could
+        deadlock on MySQL, where the insert's foreign-key check already holds 
a shared lock
+        on the Dag row that concurrent triggers would both try to upgrade.

Review Comment:
   Removed the MySQL foreign-key lock claim and the finalizer guarantee. The 
docstring now describes the Dag row lock and transaction atomicity. The 
already-draining finalizer race remains a separate follow-up, as you suggested.
   
   ---
   Drafted-by: Codex (GPT-6); reviewed by @dheerajturaga before posting



-- 
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]

Reply via email to