Copilot commented on code in PR #74212:
URL: https://github.com/apache/airflow/pull/74212#discussion_r4743419626
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -1546,7 +1564,8 @@ def process_executor_events(
# row lock this entire set of taskinstances to make sure the scheduler
doesn't fail when we have
# multi-schedulers
locked_query = with_row_locks(query, of=TI, session=session,
skip_locked=True)
- tis: Iterator[TI] =
session.scalars(locked_query.execution_options(populate_existing=True))
+ tis: Sequence[TI] =
list(session.scalars(locked_query.execution_options(populate_existing=True)))
+ rescheduled_ti_ids = cls._find_rescheduled_ti_ids(tis, session=session)
Review Comment:
This lookup also runs for queued task instances whose executor event is
QUEUED or RUNNING, even though those events immediately continue below without
consulting `rescheduled_ti_ids`. That adds a database round trip under the
task-instance locks to ordinary task submission/start batches, including
non-sensors. Restrict the lookup candidates to SUCCESS events so the extra
query only runs when the new stale-success check can use it.
##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -1622,11 +1643,17 @@ def process_executor_events(
ti.queued_by_job_id != job_id # Another scheduler has queued
this task again
or executor.has_task(ti) # This scheduler has this task
already
or (
- # Resume-after-defer: trigger moved TI to scheduled or
queued (next_method set)
- # before we saw the executor success from the defer exit
for the same try_number.
ti.state in (TaskInstanceState.SCHEDULED,
TaskInstanceState.QUEUED)
and state == TaskInstanceState.SUCCESS
- and ti.next_method is not None
+ and (
+ # Resume-after-defer: trigger moved TI to scheduled or
queued (next_method set)
+ # before we saw the executor success from the defer
exit for the same try_number.
+ ti.next_method is not None
+ # Sensor in reschedule mode: the TI was put back for
its next poke before we saw
+ # the executor success from the previous poke. That
exit leaves next_method unset,
+ # so an existing task_reschedule row is what separates
it from an external kill.
+ or ti.id in rescheduled_ti_ids
Review Comment:
The new tests cover only SUCCESS events with a reschedule row. Please also
cover a FAILED executor event with that same row present and verify that normal
mismatch/failure handling still occurs. Existing failure tests have no
reschedule history, so they would not catch accidentally allowing this new
exception to suppress real executor failures.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]