shaealh opened a new pull request, #65920: URL: https://github.com/apache/airflow/pull/65920
closes: #65818 related: #65836 This changes the scheduler trigger-timeout path and trigger cleanup path to lock candidate `task_instance` rows in deterministic primary-key order before updating them. On MySQL/InnoDB, the previous bulk updates could reach overlapping `task_instance` rows through different indexes, allowing the scheduler and triggerer to acquire row/gap locks in different orders. With HA schedulers and deferrable tasks, that can deadlock. The new flow is: 1. Select matching `task_instance.id` rows ordered by primary key. 2. Lock those rows with `FOR UPDATE SKIP LOCKED`. 3. Update only the selected IDs. 4. Repeat in bounded batches. This keeps the existing predicates and update values intact while making lock acquisition consistent across the scheduler and triggerer writers. Tests added: - scheduler timeout path processes more than one batch - trigger cleanup path clears trigger IDs across more than one batch Tests run: - `ruff check airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/src/airflow/models/trigger.py airflow-core/tests/unit/jobs/test_scheduler_job.py airflow-core/tests/unit/models/test_trigger.py` - `python -m compileall -q airflow-core/src/airflow/jobs/scheduler_job_runner.py airflow-core/src/airflow/models/trigger.py airflow-core/tests/unit/jobs/test_scheduler_job.py airflow-core/tests/unit/models/test_trigger.py` - `AIRFLOW_HOME=/tmp/airflow-65818-test-home PATH=/tmp/airflow-test-bin:$PATH .venv/bin/python -m pytest airflow-core/tests/unit/models/test_trigger.py -k 'clean_unused' --with-db-init` - `AIRFLOW_HOME=/tmp/airflow-65818-test-home PATH=/tmp/airflow-test-bin:$PATH .venv/bin/python -m pytest airflow-core/tests/unit/jobs/test_scheduler_job.py -k 'timeout_triggers' --with-db-init` -- 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]
