diogosilva30 commented on issue #77237:
URL: https://github.com/apache/airflow/issues/77237#issuecomment-7103812853

   Seeing the same on 3.4.0 with MySQL 8.4 (Cloud SQL, 1 vCPU / 3.75 GB, 
`READ-COMMITTED`, about 7,500 task completions per hour), with a different plan 
and a different failure mode than the PostgreSQL write-up.
   
   **Plan on MySQL.** `EXPLAIN` of the cleanup `DELETE` shows a full scan of 
`rtif_v2` (access type `ALL`, about 2,200 rows at the time) with an `eq_ref` 
probe into `task_instance` by primary key for each row, so every task 
completion scans the whole table and X-locks the rows it matches.
   
   **Effect.** I polled `information_schema.processlist` for 45 s: 12,716 of 
13,600 samples of running statements (93.5%) were `DELETE FROM rtif_v2 WHERE 
EXISTS (...)`, and another 407 were its `SELECT rtif_v2.id ...` pre-select 
(`synchronize_session="fetch"`). The DB sat at 75-98% CPU (0.005% buffer-pool 
misses, so CPU-bound, not disk-bound). `PUT 
/execution/task-instances/{id}/rtif` calls were the slowest requests during 
each API stall, up to 12 s. The API server's liveness probe (5 s timeout) then 
failed and all three API pods were restarted together, which sent every worker 
retrying at once. This repeated every few minutes until the cleanup was turned 
off.
   
   **Deadlocks.** With `innodb_print_all_deadlocks` on, the baseline was about 
37 deadlocks per minute. During an `airflow db clean` run the deadlock lines 
went from 50-100 per minute to 484-650 per minute, and the statements in the 
reports were almost entirely `DELETE FROM rtif_v2` (2,014) and the legacy 
`DELETE FROM rtif_v1` (578) issued by the same call. The reports show a long 
scan holding about 2,900 row locks colliding with small deletes for other 
tasks. `@retry_db_transaction` hides these from the user, but each retry 
rescans and relocks, and the retries pile up under load.
   
   **Workaround and result.** Setting `[core] 
num_dag_runs_to_retain_rendered_fields = 0` makes `delete_old_records()` return 
early. After the pods rolled: `DELETE FROM rtif_v2` disappeared from the 
sampled statements (398 samples in 30 s instead of 13,600 in 45 s), deadlocks 
dropped from about 37 per minute to 0 in a 30 s count, and a manual `db clean` 
run that had stalled the API before ran clean (no failed tasks, no pod 
restarts). The cost is that rendered fields are kept until `db clean` removes 
the `task_instance` rows (they follow through the `ON DELETE CASCADE` foreign 
key).
   
   So on MySQL the problem looks like lock contention and CPU saturation from 
the scan, not read volume. A cleanup that only touches rows past the retention 
window, rather than evaluating a correlated `EXISTS` over every attempt of the 
task, would avoid both.
   
   (Analysis prepared with Claude Code.)
   


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