-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't mistakenly take a lock on DagRun via ti.refresh_from_fb #25312
Merged
Conversation
This file contains 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
/cc @potiuk Even if this doesn't fix the deadlock it's probably worth doing |
@RNHTTR Can you see if this change does anything for the deadlock you are able to reproduce? |
potiuk
reviewed
Jul 26, 2022
potiuk
approved these changes
Jul 26, 2022
ashb
force-pushed
the
possible-deadlock-fix
branch
from
July 27, 2022 14:40
87ab6b6
to
2073e1a
Compare
potiuk
approved these changes
Jul 27, 2022
In 2.2.0 we made TI.dag_run be automatically join-loaded, which is fine for most cases, but for `refresh_from_db` we don't need that (we don't access anything under ti.dag_run) and it's possible that when `lock_for_update=True` is passed we are locking more than we want to and _might_ cause deadlocks. Even if it doesn't, selecting more than we need is wasteful.
ashb
force-pushed
the
possible-deadlock-fix
branch
from
July 28, 2022 10:56
2073e1a
to
0984660
Compare
2 tasks
jedcunningham
approved these changes
Jul 28, 2022
Co-authored-by: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com>
ephraimbuddy
pushed a commit
that referenced
this pull request
Aug 15, 2022
In 2.2.0 we made TI.dag_run be automatically join-loaded, which is fine for most cases, but for `refresh_from_db` we don't need that (we don't access anything under ti.dag_run) and it's possible that when `lock_for_update=True` is passed we are locking more than we want to and _might_ cause deadlocks. Even if it doesn't, selecting more than we need is wasteful. (cherry picked from commit be2b53e)
ephraimbuddy
added a commit
that referenced
this pull request
Aug 19, 2022
53 tasks
2 tasks
Closed
2 tasks
dstandish
added a commit
to astronomer/airflow
that referenced
this pull request
Mar 30, 2024
Fundamentally what's going on here is we need a TaskInstance object instead of a Row object when sending over the wire in RPC call. But the full story on this one is actually somewhat complicated. It was back in 2.2.0 in apache#25312 when we converted to query with the column attrs instead of the TI object (apache#28900 only refactored this logic into a function). The reason was to avoid locking the dag_run table since TI newly had a dag_run relationship attr. Now, this causes a problem with AIP-44 because the RPC api does not know how to serialize a Row object. This PR switches back to querying a TaskInstance object, but avoids locking dag_run by using lazy_load option. Meanwhile, since try_number is a horrible attribute (which gives you a different answer depending on the state), we have to switch it back to look at the underlying private attr instead of the public accesor.
dstandish
added a commit
that referenced
this pull request
Apr 2, 2024
Fundamentally what's going on here is we need a TaskInstance object instead of a Row object when sending over the wire in RPC call. But the full story on this one is actually somewhat complicated. It was back in 2.2.0 in #25312 when we converted to query with the column attrs instead of the TI object (#28900 only refactored this logic into a function). The reason was to avoid locking the dag_run table since TI newly had a dag_run relationship attr. Now, this causes a problem with AIP-44 because the RPC api does not know how to serialize a Row object. This PR switches back to querying a TaskInstance object, but avoids locking dag_run by using lazy_load option. Meanwhile, since try_number is a horrible attribute (which gives you a different answer depending on the state), we have to switch it back to look at the underlying private attr instead of the public accesor.
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.
In 2.2.0 we made TI.dag_run be automatically join-loaded, which is fine
for most cases, but for
refresh_from_db
we don't need that (we don'taccess anything under ti.dag_run) and it's possible that when
lock_for_update=True
is passed we are locking more than we want to andmight cause deadlocks.
Even if it doesn't, selecting more than we need is wasteful.
Idea inspired by @dstaple, except rather than not locking it changed to not even select against the DagRun table in the first place.
Might fix #23361