vatsrahul1001 opened a new issue, #63532:
URL: https://github.com/apache/airflow/issues/63532

   ### Apache Airflow version
   
   main (development)
   
   ### If "Other Airflow 3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   Migration 0094_3_2_0_replace_deadline_inline_callback_with_fkey processes 
every row in the deadline table through Python's serde.deserialize() during 
upgrade. For each row it deserializes the JSON callback, instantiates the 
Python object, re-serializes it into the new format, then writes to the 
callback table.
   With a large number of deadline rows this becomes very slow because the 
bottleneck is Python-side object instantiation — not the database I/O. The 
migration processes rows in batches of 1000, but within each batch every row 
goes through:
   ```
   
   callback_data = deserialize(deadline.callback).serialize() | {
       "prefix": CALLBACK_METRICS_PREFIX,
       "dag_id": deadline.dag_id,
   }
   ```
   
   This round-trip through Python deserialization/serialization is unnecessary 
given that the callback JSON format is predictable. Prior to 3.2.0 the only 
supported callback type was AsyncCallback, which has a fixed structure
   ```
   
   {
     "__data__": {"path": "...", "kwargs": {...}},
     "__classname__": "airflow.sdk.definitions.deadline.AsyncCallback",
     "__version__": 0
   }
   ```
   
   The transformation could be done entirely in SQL by extracting path and 
kwargs from the existing JSON and constructing the new callback row format 
without ever touching Python.
   
   Observed impact:
   10M deadline rows: ~33 minutes
   
   The migration holds a transaction open for the entire duration
   Proportional to deadline row count — 1M rows would still take ~3 minutes
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   **Steps to reproduce:**
   
   1. Start Airflow 3.1.8 with PostgreSQL backend
   2. Create a significant number of DAG runs with deadlines (or insert 
synthetic data into the deadline table with valid serde-formatted callback JSON)
   3. Upgrade to 3.2.0 (airflow db migrate)
   4. Observe that migration 0094 takes several minutes per million deadline 
rows
   
   ### Operating System
   
   Mac
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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