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

Double-check TaskInstance state if it differs from the Executor state. #43063

Merged
merged 10 commits into from
Dec 9, 2024

Conversation

antonysouthworth-halter
Copy link

@antonysouthworth-halter antonysouthworth-halter commented Oct 16, 2024

closes: #42991 (discussion)

In the course of investigating #42991 I am a bit suspicious that there is a race condition between the DB fetch on line 285 and the executor state check on line 312.

Basically my suspicion is that the following order of operations is sometimes happening:

  • (backfill_job_runner.py) TI returned from the DB contains the old state (queued)
  • (celery worker) Worker dequeue the task and change state to running.
  • (celery worker) Worker complete the task and change state to success.
  • (backfill_job_runner.py) Executor state changes to success (celery async future thing)
  • (backfill_job_runner.py) Fail state comparison ("The executor reported that the task instance finished with state success, but the task instance's state attribute is queued.")

More details on my situation in the above linked discussion, but important to know is in my case the worker is completing the task in about 300 milliseconds.

Therefore, I propose that the backfill job should "double-check" the task instance state if it is different from executor state by refreshing from DB. If the state is still different then fall back to the old logic of assuming that the task state has changed externally.

I am not sure if I've picked the right base for this PR. The backfill stuff is being totally re-written for Airflow 3 as part of AIP-78 so I wouldn't know where to make this change or even if the same bug exists there.

Update 2024-10-17

#42991 (comment) I patched the change into my deployment and am seeing the added log line being emitted, and not followed by the The executor reported that the task instance finished with state success, but the task instance's state attribute is queued message. This tells me that the refresh is probably necessary under such circumstances.


^ 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 including HA (high availability) scheduler label Oct 16, 2024
Copy link

boring-cyborg bot commented Oct 16, 2024

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 Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, 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.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    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

@potiuk
Copy link
Member

potiuk commented Oct 16, 2024

cc: @dstandish -> maybe with your recent backfll experience you can comment on that - that seems like a good candidate to fix for 2.10 if it solves the issue (regardless from the fact that in Airflow 3 backfill is going to be differently).

@eladkal eladkal added this to the Airflow 2.10.4 milestone Dec 1, 2024
@eladkal eladkal added the type:bug-fix Changelog: Bug Fixes label Dec 1, 2024
@utkarsharma2
Copy link
Contributor

@potiuk / @eladkal / @kaxil Do we need this for 2.10.4?

@dstandish
Copy link
Contributor

cc: @dstandish -> maybe with your recent backfll experience you can comment on that - that seems like a good candidate to fix for 2.10 if it solves the issue (regardless from the fact that in Airflow 3 backfill is going to be differently).

lemme see

@dstandish dstandish added area:backfill Specifically for backfill related and removed area:Scheduler including HA (high availability) scheduler labels Dec 4, 2024
Copy link
Contributor

@dstandish dstandish left a comment

Choose a reason for hiding this comment

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

no concerns with this change

@utkarsharma2 utkarsharma2 merged commit 90d6332 into apache:v2-10-test Dec 9, 2024
48 checks passed
Copy link

boring-cyborg bot commented Dec 9, 2024

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

utkarsharma2 pushed a commit that referenced this pull request Dec 9, 2024
#43063)

* Double-check TaskInstance state if it differs from Executor.

* Update airflow/jobs/backfill_job_runner.py

* Update airflow/jobs/backfill_job_runner.py

* Update airflow/jobs/backfill_job_runner.py

* Update airflow/jobs/backfill_job_runner.py

* Update airflow/jobs/backfill_job_runner.py

* Update airflow/jobs/backfill_job_runner.py

---------

Co-authored-by: Utkarsh Sharma <utkarsharma2@gmail.com>
(cherry picked from commit 90d6332)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:backfill Specifically for backfill related type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants