Skip to content
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

Retry on Airflow Schedule DAG Run DB Deadlock #26347

Merged
merged 7 commits into from Oct 2, 2022

Conversation

anthonyp97
Copy link
Contributor

  • This resolves the following issue: Deadlock in Scheduler Loop when Updating Dag Run #25765
  • We have tested this on our most recent deployment and confirmed that we are retrying these deadlocks gracefully now with this change and the main scheduler loop no longer breaks with these deadlocks.

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added the area:Scheduler Scheduler or dag parsing Issues label Sep 12, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 12, 2022

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

LGTM. But I would love others (@ashb?) to take a look.

@potiuk
Copy link
Member

potiuk commented Sep 18, 2022

You also need to rebase @anthonyp97 to fix unrelated failures I think.


guard.commit()

return callback_tuples, callback_to_run
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you're including callback_to_run in the return statement here?? It seems cleaner to just return callback_tuples, especially because the last callback_to_run is going to be included in the last tuple of callback_tuples anyway.

The next line of code overwrites callback_to_run as well, so it just seems unnecessary to pass it back:

            callback_tuples, callback_to_run = self._schedule_all_dag_runs(guard, dag_runs, session)

        # ...
        for dag_run, callback_to_run in callback_tuples:  # <-- callback_to_run overwritten immediately

Also, would a dictionary be a better option to map dag runs to callbacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@blag yea definitely right that I should just be returning callback_tuples, will update this. For the second point I imagine it shouldn't really matter between list of tuples and a dict since we are just iterating through the data structure either way element by element but if you strongly prefer a dict I can update to use that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't strongly prefer a dict, that's just what makes more sense to me. But yeah, if a list works then go with that.

@anthonyp97
Copy link
Contributor Author

@potiuk @ashb just following up here, do you think this is good to merge now? Just hoping this can get in to the 2.4.1 release whenever that is planned to be, thank you!

@potiuk potiuk added this to the Airflow 2.4.2 milestone Sep 27, 2022
@potiuk
Copy link
Member

potiuk commented Sep 27, 2022

I think we are just about to release 2.4.1 I think it looks good to me, but we have just merged 2.4.1 branch to release it. I think it will go to 2.4.2.

@potiuk
Copy link
Member

potiuk commented Sep 27, 2022

I also think @ashb should take a look.

@potiuk potiuk merged commit 0da4993 into apache:main Oct 2, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 2, 2022

Awesome work, congrats on your first merged pull request!

@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Oct 18, 2022
ephraimbuddy pushed a commit that referenced this pull request Oct 18, 2022
Co-authored-by: Anthony Panat <anthonypanat@Anthonys-MacBook-Pro-2.local>
Co-authored-by: Anthony Panat <anthonypanat@anthonys-mbp-2.mynetworksettings.com>
(cherry picked from commit 0da4993)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Scheduler Scheduler or dag parsing Issues type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants