Add fast-path heartbeat UPDATE to avoid row lock in the common case#65029
Merged
ephraimbuddy merged 5 commits intoapache:mainfrom Apr 13, 2026
Merged
Add fast-path heartbeat UPDATE to avoid row lock in the common case#65029ephraimbuddy merged 5 commits intoapache:mainfrom
ephraimbuddy merged 5 commits intoapache:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR optimizes the ti_heartbeat endpoint by attempting a guarded UPDATE first (matching id, state, hostname, pid) to avoid SELECT ... FOR UPDATE row locking in the common “still running on same worker” case.
Changes:
- Add a fast-path guarded
UPDATEfor heartbeat updates and return early if it affects a row. - Log and fall back to the existing
SELECT ... FOR UPDATEdiagnostic/validation path when the fast path doesn’t match. - Add unit tests covering both the fast-path success case and the fast-path miss → fallback case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py | Adds fast-path guarded heartbeat UPDATE and fallback behavior. |
| airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py | Adds tests to validate fast-path behavior and fallback on miss. |
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
Outdated
Show resolved
Hide resolved
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
Outdated
Show resolved
Hide resolved
628a53c to
2928caf
Compare
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
Outdated
Show resolved
Hide resolved
The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
c196e03 to
b7e5820
Compare
eladkal
approved these changes
Apr 13, 2026
github-actions bot
pushed a commit
that referenced
this pull request
Apr 13, 2026
…ommon case (#65029) * Add fast-path heartbeat UPDATE to avoid row lock in the common case The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls. * fixup! Add fast-path heartbeat UPDATE to avoid row lock in the common case * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix static checks * fixup! Fix static checks --------- (cherry picked from commit c97d1a5) Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Backport successfully created: v3-2-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
ephraimbuddy
added a commit
that referenced
this pull request
Apr 14, 2026
…ommon case (#65029) * Add fast-path heartbeat UPDATE to avoid row lock in the common case The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls. * fixup! Add fast-path heartbeat UPDATE to avoid row lock in the common case * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix static checks * fixup! Fix static checks --------- (cherry picked from commit c97d1a5) Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ephraimbuddy
added a commit
that referenced
this pull request
Apr 14, 2026
…ommon case (#65029) * Add fast-path heartbeat UPDATE to avoid row lock in the common case The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls. * fixup! Add fast-path heartbeat UPDATE to avoid row lock in the common case * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix static checks * fixup! Fix static checks --------- (cherry picked from commit c97d1a5) Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ephraimbuddy
added a commit
that referenced
this pull request
Apr 14, 2026
…ommon case (#65029) * Add fast-path heartbeat UPDATE to avoid row lock in the common case The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls. * fixup! Add fast-path heartbeat UPDATE to avoid row lock in the common case * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix static checks * fixup! Fix static checks --------- (cherry picked from commit c97d1a5) Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
vatsrahul1001
added a commit
that referenced
this pull request
Apr 15, 2026
…ommon case (#65029) (#65137) * Add fast-path heartbeat UPDATE to avoid row lock in the common case The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls. * fixup! Add fast-path heartbeat UPDATE to avoid row lock in the common case * Apply suggestions from code review * Fix static checks * fixup! Fix static checks --------- (cherry picked from commit c97d1a5) Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>
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.
The ti_heartbeat endpoint now attempts a single guarded UPDATE (matching id, state, hostname, and pid) before falling back to the existing SELECT FOR UPDATE path. When the task is still running on the expected host this returns immediately, eliminating the row lock and a round trip for the vast majority of heartbeat calls.