Skip to content

Fix assignment of unassigned triggers#21770

Merged
dstandish merged 3 commits into
apache:mainfrom
jkramer-ginkgo:fix-trigger-assignment
Feb 26, 2022
Merged

Fix assignment of unassigned triggers#21770
dstandish merged 3 commits into
apache:mainfrom
jkramer-ginkgo:fix-trigger-assignment

Conversation

@jkramer-ginkgo

@jkramer-ginkgo jkramer-ginkgo commented Feb 23, 2022

Copy link
Copy Markdown
Contributor

Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

Closes: #21616

Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616
@boring-cyborg

boring-cyborg Bot commented Feb 23, 2022

Copy link
Copy Markdown

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

@dstandish dstandish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like a great fix, and nice work with the test

Comment thread airflow/models/trigger.py Outdated
trigger_ids_query = (
session.query(cls.id).filter(cls.triggerer_id.notin_(alive_triggerer_ids)).limit(capacity).all()
session.query(cls.id)
.filter(or_(cls.triggerer_id.notin_(alive_triggerer_ids), cls.triggerer_id == None)) # noqa: E711

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the triggerer_id == None, then wouldn't it already be true that it's not in alive_triggerer_ids?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, unfortunately that's a quirk with sqlalchemy's notin_ (test fails when that's removed). I'll add a comment to that effect

@dstandish dstandish Feb 23, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok makes sense.

small thing but can i also suggest in that case, put the cls.triggerer_id.is_(None) first in the OR

then it reads more like "not assigned OR on a dead triggerer"
compared with "on a dead triggerer OR not assigned"

"not assigned" is by far the more common / standard / expected case i think so seems like it would be more intuitive to put it first. and, it sort of avoids that issue where first condition looks like it should cover second.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make sense to me

session.commit()
assert session.query(Trigger).count() == 3
Trigger.assign_unassigned(new_triggerer.id, 100, session=session)
session.expire_all()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not commit instead? genuine question -- still learning sqlalchemy here. but from the doc it indicates that when you commit, then everything gets expired anyway. and committing seems like a more intuitive thing to do here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

had a bunch of trouble here (and I suspect it's because of the synchronize_session=False in Trigger.assign_unassigned). at some point I did try various combinations of session.flush(), session.commit(), but this is what worked in getting the state synced. I'm no sqlalchemy expert either!

Comment thread airflow/models/trigger.py Outdated

@dstandish dstandish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, i may try it locally before merging, and it's core so should have second set of eyes.

@github-actions github-actions Bot added the full tests needed We need to run full set of tests for this PR to merge label Feb 23, 2022
@github-actions

Copy link
Copy Markdown
Contributor

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@jkramer-ginkgo

Copy link
Copy Markdown
Contributor Author

Cool thanks @dstandish

@potiuk

potiuk commented Feb 26, 2022

Copy link
Copy Markdown
Member

LGTM as well .

@potiuk

potiuk commented Feb 26, 2022

Copy link
Copy Markdown
Member

Feel free to merge @dstandish

@dstandish dstandish merged commit b26d4d8 into apache:main Feb 26, 2022
@boring-cyborg

boring-cyborg Bot commented Feb 26, 2022

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request!

@jkramer-ginkgo jkramer-ginkgo deleted the fix-trigger-assignment branch February 28, 2022 14:19
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Feb 28, 2022
@jedcunningham jedcunningham added this to the Airflow 2.2.5 milestone Feb 28, 2022
ephraimbuddy pushed a commit that referenced this pull request Mar 16, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 20, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 22, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 22, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 22, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 22, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 24, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
ephraimbuddy pushed a commit that referenced this pull request Mar 26, 2022
Previously, the query returned no alive triggerers which resulted
in all triggers to be assigned to the current triggerer. This works
fine, despite the logic bug, in the case where there's a single
triggerer. But with multiple triggerers, concurrent iterations of
the TriggerJob loop would bounce trigger ownership to whichever
loop ran last.

Addresses #21616

(cherry picked from commit b26d4d8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full tests needed We need to run full set of tests for this PR to merge type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deferred tasks being ran on every triggerer instance

4 participants