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

Change TaskInstance and TaskReschedule PK from execution_date to run_id #17719

Merged
merged 98 commits into from
Sep 7, 2021

Conversation

ashb
Copy link
Member

@ashb ashb commented Aug 19, 2021

Since TaskReschedule had an existing FK to TaskInstance we had to move
change both of these at the same time.

This puts an explicit FK constraint between TaskInstance and DagRun,
meaning that we can remove a lot of "find TIs without DagRun" code in
the scheduler too, as that is no longer a possible situation.

Since there is now an explicit foreign key between TaskInstance and
DagRun, we can remove a lot of the "cleanup" code in the scheduler that
was dealing with this.

This PR is, sadly, unavoidably large as it changes a fundamental part of the Airflow system, the primary key of the TaskInstance table :(

Closes #17046

Related #16302, #17030


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.

@boring-cyborg boring-cyborg bot added area:CLI area:providers area:Scheduler Scheduler or dag parsing Issues area:webserver Webserver related Issues kind:documentation provider:google Google (including GCP) related issues labels Aug 19, 2021
@ashb ashb requested a review from uranusjr August 19, 2021 11:23
@ashb ashb added AIP-39 Timetables and removed provider:google Google (including GCP) related issues area:webserver Webserver related Issues area:CLI area:providers kind:documentation labels Aug 19, 2021
@ashb ashb added this to In progress in AIP-39 Pluggable schedule_interval via automation Aug 19, 2021
@ashb ashb moved this from In progress to Review in progress in AIP-39 Pluggable schedule_interval Aug 19, 2021
@ashb ashb force-pushed the delegate-exec-date-to-dagrun branch from 94e0cb2 to 1a1cd01 Compare August 19, 2021 11:26
Copy link
Contributor

@ephraimbuddy ephraimbuddy left a comment

Choose a reason for hiding this comment

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

I'm wondering if

airflow/airflow/www/views.py

Lines 1485 to 1486 in 4da4c18

ti = models.TaskInstance(task=task, execution_date=execution_date)
ti.refresh_from_db()
need a change too?

@ashb
Copy link
Member Author

ashb commented Aug 19, 2021

I'm wondering if

airflow/airflow/www/views.py

Lines 1485 to 1486 in 4da4c18

ti = models.TaskInstance(task=task, execution_date=execution_date)
ti.refresh_from_db()
need a change too?

Yes it should. It'll still work as it is but that relies on the compat shims

@ashb ashb force-pushed the delegate-exec-date-to-dagrun branch from 1a1cd01 to 27c58db Compare August 19, 2021 20:52
@ashb
Copy link
Member Author

ashb commented Aug 19, 2021

I'm not quite expecting all tests to pass on this yet, but I'd like a review on this, so I'm marking it ready while I work on fixing up the remaining tests

@ashb ashb marked this pull request as ready for review August 19, 2021 20:53
@@ -314,64 +330,12 @@ def test_task_get_template(self):
assert value == expected_value
assert [str(m.message) for m in recorder] == [message]

def test_local_task_job(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests are duplicating what was already in test_local_task_job -- we don't need them again.

@@ -189,80 +189,6 @@ def is_alive(self, grace_multiplier: Optional[float] = None) -> bool:
and (timezone.utcnow() - self.latest_heartbeat).total_seconds() < scheduler_health_check_threshold
)

@provide_session
def _change_state_for_tis_without_dagrun(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is deleted, as the DB won't let us have TIs without Dagruns anymore :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Huge, can clear the issue of tasks getting stuck!

Copy link
Contributor

Choose a reason for hiding this comment

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

Since tasks will no longer exist without dagrun, obviously the dag will fail or succeed and tis won't be stuck. I think we should remove these lines.:

self.log.info('Setting task instance %s state to %s as reported by executor', ti, state)
ti.set_state(state)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this can happen if (for example) there is a crash in the worker early on in the "boot" process, so it can't report it's own status in the DB.

airflow/jobs/scheduler_job.py Outdated Show resolved Hide resolved
Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Only read about 1/5 (probably less) of the patch. Generally seems fine to me but some thoughts on the implementation.

airflow/cli/commands/task_command.py Outdated Show resolved Hide resolved
airflow/cli/commands/task_command.py Outdated Show resolved Hide resolved
airflow/jobs/backfill_job.py Show resolved Hide resolved
airflow/jobs/backfill_job.py Show resolved Hide resolved
airflow/models/baseoperator.py Outdated Show resolved Hide resolved
airflow/models/dagrun.py Outdated Show resolved Hide resolved
airflow/models/skipmixin.py Outdated Show resolved Hide resolved
airflow/models/skipmixin.py Show resolved Hide resolved
@ashb ashb removed the request for review from ryanahamilton August 20, 2021 08:21
@ashb ashb force-pushed the delegate-exec-date-to-dagrun branch from 178ce9e to 8dd8622 Compare September 6, 2021 19:45
Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Nervously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AIP-39 Timetables area:Scheduler Scheduler or dag parsing Issues full tests needed We need to run full set of tests for this PR to merge
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Ensure all tests that create TaskInstances in DB also create DagRuns
5 participants