Skip to content

Reduce memory used when deleting queued asset events - #71917

Merged
pierrejeambrun merged 1 commit into
apache:mainfrom
ColtenOuO:fix-asset-queued-events-synchronize-session
Aug 21, 2026
Merged

pierrejeambrun merged 1 commit into
apache:mainfrom
ColtenOuO:fix-asset-queued-events-synchronize-session

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #71185: delete_asset_queued_events and delete_dag_asset_queued_event (airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py) still forced SQLAlchemy's "fetch" synchronize_session strategy on their AssetDagRunQueue deletes - the exact pattern #71185 removed from delete_dag.

"fetch" reads the primary key of every deleted row back from the database (via RETURNING on backends that support it, or an extra SELECT beforehand on those that don't) so it can update the ORM session's identity map. Neither endpoint loads any AssetDagRunQueue objects into the session before the delete, so those keys are matched against an empty map and discarded - transient Python heap allocated per deleted row for no reason. The sibling delete_dag_asset_queued_events endpoint already used the default "auto" strategy; this brings the other two in line with it.

Before / after

50,000 rows shaped like asset_dag_run_queue (composite (target_dag_id, asset_event_id) primary key, asset_id, created_at):

backend synchronize_session time peak heap statements
PostgreSQL 14 "fetch" (before) 0.750s 14.2 MiB 1 (DELETE … RETURNING …)
PostgreSQL 14 default (after) 0.045s 0.0 MiB 1 (DELETE)
SQLite "fetch" (before) 0.779s 14.2 MiB 1 (DELETE … RETURNING …)
SQLite default (after) 0.046s 0.0 MiB 1 (DELETE)

Changes

File Function Before After
assets.py delete_asset_queued_events synchronize_session="fetch" default ("auto")
assets.py delete_dag_asset_queued_event synchronize_session="fetch" default ("auto")

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5) for writing test

delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@pierrejeambrun pierrejeambrun added this to the Airflow 3.3.2 milestone Aug 21, 2026
@pierrejeambrun
pierrejeambrun merged commit 49c5d51 into apache:main Aug 21, 2026
79 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 21, 2026
…che#71917)

delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.
(cherry picked from commit 49c5d51)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Aug 21, 2026
…che#71917)

delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.
(cherry picked from commit 49c5d51)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
jason810496 pushed a commit that referenced this pull request Aug 22, 2026
) (#71937)

delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.
(cherry picked from commit 49c5d51)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Sep 7, 2026
) (#71937)

delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.
(cherry picked from commit 49c5d51)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
imrichardwu pushed a commit to imrichardwu/airflow that referenced this pull request Sep 11, 2026
delete_asset_queued_events and delete_dag_asset_queued_event forced
SQLAlchemy's "fetch" synchronize_session strategy on their
AssetDagRunQueue deletes. That strategy reads the primary key of every
deleted row back from the database to update the ORM session's
identity map, but neither endpoint loads any AssetDagRunQueue objects
into the session beforehand, so the read-back keys are matched against
an empty map and discarded.

The sibling delete_dag_asset_queued_events endpoint already used the
default "auto" strategy; the other two now match it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants