ashb commented on code in PR #75132:
URL: https://github.com/apache/airflow/pull/75132#discussion_r4323974118
##########
airflow-core/src/airflow/models/task_coordinates.py:
##########
@@ -243,10 +278,47 @@ def loop_context(
regions.update(
load_region_ancestry([ti.region_id], dag_id=ti.dag_id,
run_id=ti.run_id, session=self.session)
)
- position = loop_position(regions, ti.region_id, ti.region_index,
group.node_id)
- if position is None:
+ coordinate = DynamicRegion.find_physical_coordinate(
+ ti.region_id, ti.region_index, group.node_id, regions
+ )
+ if coordinate is None:
raise ValueError("Task coordinates do not belong to the pinned
loop")
- return group, position[1]
+ region_id, index = coordinate
+ region = regions[region_id]
+ is_fork = region.forked_from_region_id is not None
+ return LoopPosition(
+ group=group,
+ index=index,
+ region_id=region_id,
+ trajectory=get_trajectory(region, regions),
+ forked_from_region_id=region.forked_from_region_id,
+ resumes_from_index=region.resumes_from_index if is_fork else None,
+ )
+
+ def get_expanded_ti_count(
+ self, ti: TaskCoordinate, *, task: SerializedOperator | None = None
+ ) -> int | None:
+ """
+ Count the live instances of a mapped task in the expansion ``ti``
belongs to, None if not mapped.
+
+ This is what a worker gets as ``TIRunContext.expanded_ti_count``.
+ """
+ if ti.region_id == SENTINEL_REGION_ID:
+ return None
+ if task is None:
+ task = self.get_task(ti.dag_id, ti.run_id, ti.task_id,
dag_version_id=ti.dag_version_id)
+ if not task.get_needs_expansion():
+ return None
+ return self.session.scalar(
+ select(func.count()).where(
Review Comment:
AIP-104 might mean that this value is incomplete/inaccurate (as it would
only say how much has been expanded so far. Note that is unlikely to land in
3.4, so just an FYI.
Yes, as long as it's it's indexed, yes this extra query is fine, and we only
run the query for mapped tasks.
--
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]