fix: optimize migration 0094 upgrade to use SQL instead of Python deserialization#63628
Open
YoannAbriel wants to merge 1 commit intoapache:mainfrom
Open
fix: optimize migration 0094 upgrade to use SQL instead of Python deserialization#63628YoannAbriel wants to merge 1 commit intoapache:mainfrom
YoannAbriel wants to merge 1 commit intoapache:mainfrom
Conversation
…erialization Replace row-by-row Python serde deserialization with pure SQL JSON manipulation for PostgreSQL (writable CTE with gen_random_uuid() and jsonb operations). For MySQL/SQLite, use batched approach with Python UUID generation but direct JSON dict access instead of importing and invoking serde.deserialize(). This eliminates the Python object instantiation bottleneck that caused ~33 minute migration times for 10M deadline rows. Also removes runtime module imports (airflow.serialization.serde, airflow.models.callback, airflow.models.deadline) from the upgrade path, hardcoding the constant values instead. This follows the migration best practice of avoiding ORM/runtime imports. Closes: apache#63532
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migration 0094 (
replace_deadline_inline_callback_with_fkey) processes every deadline row through Python'sserde.deserialize()during upgrade, instantiating Python objects for each row. At scale (10M rows), this takes ~33 minutes.The callback JSON format prior to 3.2.0 is predictable (always
AsyncCallbackwith a fixed serde wrapper structure), so the transformation can be done entirely in SQL.PostgreSQL: single writable CTE with
gen_random_uuid()andjsonb_build_object()— handles INSERT intocallbackand UPDATE ofdeadlinein one statement. No Python loop, no batching.MySQL/SQLite: batched approach with Python UUID generation but direct JSON dict access instead of
serde.deserialize()round-trip.Also removes runtime module imports (
airflow.serialization.serde,airflow.models.callback,airflow.models.deadline) from the upgrade path, hardcoding constant values instead.Closes: #63532
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4, claude-opus-4-6) following the guidelines