NoahKusaba opened a new issue, #2915:
URL: https://github.com/apache/datafusion-ballista/issues/2915
**Describe the bug**
When a stage is split between tasks, a task can report more operator metrics
sets than the stage plan has. The scheduler then drops that task's metrics.
This happens for a `UNION ALL` stage with a branch whose input stage gave no
rows. In the example below, every task of the stage is dropped, so the stage
reports no metrics at all. Query results are not affected.
The scheduler restricts each task's copy of the stage plan to the task's
partitions. A leaf the task runs none of is replaced by `no_partitions`
(`ballista/scheduler/src/state/task_builder.rs:287`), a `DataSourceExec` over
an empty `MemorySourceConfig`. When that leaf is an `EmptyExec`, the adaptive
planner's stand-in for a stage that gave no rows, the swap adds a metrics set.
`EmptyExec` has no metrics, but `DataSourceExec` does. `collect_plan_metrics`
(`ballista/core/src/utils.rs:536`) counts only nodes that have metrics. So the
task reports one more set than `plan_metrics_len`
(`ballista/scheduler/src/state/execution_stage.rs:730`). `update_task_metrics`
(`execution_stage.rs:1039`) then refuses the task's metrics, as #2875 made it
do.
A `UNION ALL` places each branch's partitions after the previous branch's.
With one partition per task, each task owns partitions of only one branch, and
the other branch's `EmptyExec` is replaced. So every task is affected. Only the
first one is logged as a warning; the rest are logged at debug level.
**To Reproduce**
TPC-DS q23 at SF1, adaptive planner, on main (7faef6682):
```
tpcds --host 127.0.0.1 --port 50050 --path <sf1> --partitions 16 --verify
--query 23 \
-c datafusion.optimizer.prefer_hash_join=false \
-c ballista.scheduler.max_partitions_per_task=1
```
The query returns 0 rows and verifies against DataFusion. The scheduler logs:
```
WARN ballista_scheduler::state::execution_stage: Ignoring the metrics of
task 3 in stage 18 of job 038G64QY5T000: Internal Ballista error: Error
updating task metrics to stage 18, task 3 reported 4 operator metrics sets but
the stage plan has 3. Later skipped tasks of this stage are logged at debug
level
```
Both branches of q23's final `UNION ALL` are aggregates whose input stages
give no rows at SF1. Each becomes an `EmptyExec`, so stage 18's plan has 3
metrics sets: the shuffle writer, the TopK sort and the union. Each task
replaces one of the two `EmptyExec`s with the stand-in and reports 4.
**Expected behavior**
Restricting a stage plan to a task's partitions doesn't change how the
task's metrics line up with the stage plan. Every successful task's metrics are
merged into the stage's metrics, which the REST API and the job-metrics gRPC
endpoint serve.
**Additional context**
Possible fixes:
1. Have `collect_plan_metrics` return one set per node, with an empty set
for a node that has no metrics. The restriction only ever replaces a leaf with
another leaf, so the task's plan and the stage plan would always line up. The
code that displays stage metrics would need to pair nodes with sets the same
way.
2. Replace a leaf that has no metrics with a stand-in that has none. This
isn't straightforward for `EmptyExec`: DataFusion's codec decodes an
`EmptyExec` with zero partitions as one partition, and that is why
`no_partitions` doesn't use one.
The first fixes this whole class of mismatch rather than only the
`EmptyExec` case.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]