Fix MySQL deadlock when queueing asset-triggered Dags#69944
Fix MySQL deadlock when queueing asset-triggered Dags#69944FrankYang0529 wants to merge 1 commit into
Conversation
Signed-off-by: PoAn Yang <payang@apache.org>
There was a problem hiding this comment.
Hello PoAn,
@retry_db_transaction retries the entire submit_event() method, but AssetManager.register_asset_change() performs non-transactional side effects before the queue insert that may deadlock.
In particular, it invokes on_asset_changed, on_asset_event_emitted, and incre asset.updates before calling _queue_dagruns(). If the queue insert raises a deadlock:
- the listeners and metric have already run.
- the database transaction is rolled back.
submit_event()is replayed.- the same listeners and metric run again for the eventually successful event.
Listener plugins may perform external, non-idempotent operations such as sending webhooks or publishing messages, so those effects cannot be rolled back with the database transaction. This can also replay listeners for earlier assets if a trigger is associated with multiple assets and a later asset fails.
The new retry test mocks AssetManager.register_asset_change() entirely, so it only verifies that the decorator retries and does not cover these duplicated side effects.
IMO, the retry boundary needs to exclude listener/metric emission, or those side effects need to be deferred until the database transaction has successfully committed. : D
|
@viiccwen Thanks for the review. You're right. The listener hooks and the Another path (task success → Execution API airflow/task-sdk/src/airflow/sdk/api/client.py Lines 1208 to 1215 in 6ba529e However, the deadlock error doesn't return 5xx. It only marks task as failed. I agree that we should remove Since issue author already created another PR #69977, I will close this one. |
Why
asset_dag_run_queuerows one by one (SAVEPOINT +merge()per row).setorder, so on MySQL it acquires index locks in opposite order and gets deadlock (errno 1213).How
INSERT ... ON DUPLICATE KEY UPDATE.dag_idon all backends, so concurrent fan-outs acquire row locks in a consistent order and cannot ABBA-deadlock each other.@retry_db_transactiontoTrigger.submit_event.Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.