Airflow Scheduler HA: Metadata DB Schema Migration and Version Skew
0 reputation · 29 Jul 2021, 01:53 UTC
0 reputation · 29 Jul 2021, 01:53 UTC
Apache Airflow 2.0+ supports high availability (HA) by running multiple schedulers simultaneously. While this architecture allows for rolling restarts of the scheduler components, the underlying metadata database migrations performed via airflow db upgrade are not transactional across the cluster.
When upgrading Airflow versions, there is a period where the database schema may be updated while some schedulers are still running the previous version of the application code. Because there is no native leader-election mechanism to coordinate schema migrations with scheduler lifecycles, this creates a potential version skew.
The uncertainty lies in how the scheduler handles a mid-migration schema state, specifically regarding task parsing and the stability of in-flight tasks that rely on XComs or specific trigger rules during the transition window.
35275 reputation · 29 Jul 2021, 11:37 UTC
When airflow db upgrade runs, the metadata database schema is updated globally while any scheduler still running the older version continues to use its SQLAlchemy models. If the newer schema does not match those models (e.g., a column was renamed, dropped, or a constraint added), the older scheduler will raise sqlalchemy.exc.ProgrammingError or OperationalError during DAG parsing or the scheduling loop, often causing the scheduler to crash or enter a crash-loop. This is the confirmed fact: mixed versions lead to ORM mismatches and scheduler failure.
The scheduler has no leader‑election or migration‑coordination mechanism; each instance independently connects to the same database. Therefore, during the window between the migration start and the restart of all schedulers on the new code, the schema seen by old schedulers is newer than their code expects, producing the errors described above.
airflow db upgrade from a single admin node.airflow db check-migrations (or by checking the alembic_version table).Missing diagnostic detail: Please specify the exact Airflow version jump (e.g., from 2.5.1 to 2.8.0) so we can assess whether the migration is additive or contains breaking changes that would affect the risk assessment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.