Repository navigation
Conversation
There was a problem hiding this comment.
Thanks for the PR, @rekbun!
GroupedPartitionCoalescer no longer ships its groups to executors. It also changes how a group picks its preferred location, so a group of one partition names none and ties between hosts are spread across groups. The @transient half is sound, since only the driver calls coalesce, and the first new test fails without the change. The location half reads only parent.preferredLocations, though. So over a scan, the main input of GroupPartitionsExec, it changes nothing (finding 1). And in a zipped storage-partitioned join, a single-partition side now drops out of the task's locations (finding 2).
Non-blocking
- 1. The new location rules do not reach scans. A scan's mapped RDD reports no locations. Resolving them through the lineage with
getPreferredLocs, asDefaultPartitionCoalescerdoes, makes a group of h2, h1, h1 prefer h1. With that change, only the test that pins the old fallback fails. inline:GroupPartitionsExec.scala:889 - 2. A single-partition group drops out of zipped locations.
ZippedPartitionsBaseRDDreads each side's own locations. With the other side on h3, the zipped locations go from h2, h3 to h3 alone. inline:GroupPartitionsExec.scala:888 - 3. A null location now throws in the tie-break. The base returned
Some(null). No in-tree parent reports one, and filtering nulls fixes it. inline:GroupPartitionsExec.scala:889
Minor
- 4. The vote counts location entries, not partitions as the comment says. inline:
GroupPartitionsExec.scala:885
There was a problem hiding this comment.
Re-checked through 4d1dbdf. Findings 3 and 4 are resolved, and 1 and 2 are done as I asked. Measured against master, though, the lineage lookup I asked for in finding 1 and the host for a group of one I asked for in finding 2 cost locality that master had. Finding 5 has a fix that keeps the vote for larger groups, which PackScanPartitionsExec in #59522 needs.
Blocking
- 5. A group fixes one host when the partitions are computed, which loses locality master had (new): Over a mapped parent master named no host, so the scheduler resolved the inputs' locations itself at each stage. I measured three regressions against master: over cached data a group prefers the source's host instead of the executor that holds the block, an executor or HDFS-cache location shrinks to its host, and a group of one gets one replica instead of all of them. Leaving those cases to the scheduler and keeping the full location string fixes all three. inline
Non-blocking
- 6. The lineage walk runs once per group entry (new):
REPLICATED_FOR_JOINslots repeat the same inputs, and each walk calls the connector'spreferredLocations()again. Memoizing per input index removes the repeats. inline
Alternatives
- 7. Vote when the scheduler asks (new): A
CoalescedRDDsubclass that runs the vote ingetPreferredLocationswould see fresh and full locations, and could offer every tied host. It needs aSortedMergeCoalescedRDDsubclass too, and the vote then runs at every stage submission. inline
There was a problem hiding this comment.
Re-checked through 5053efb. Findings 5 and 6 are resolved. All four rows of finding 5 now give master's locations, and each input is looked up once.
Blocking
- 8. A tie names one host (late catch): Most groups of two inputs have no host ahead, and there the vote narrows master's offer of the first input's replicas to one host. Its tie-break by name also sends about a third of the preferences to the first tenth of the hosts. Naming a host only when one is strictly ahead gives master's offer back. inline
- 9. The persisted test does not reach the lineage walk (new): Its parent is the cached RDD itself, so all six new tests pass with the walk in
persistedLineagedisabled. Coalescingcached.map(identity), as over anInMemoryTableScanExec, pins it. inline
Non-blocking
- 10. In a join, the other side's host wins over a persisted side (new): The zip copies each side's own location, so with a cached side on the left the tasks move from the executor that holds the block to the scan's host. The description should name this cost next to the group-of-one case, and a test could pin it. inline
Alternatives
- 7. Vote when the scheduler asks (round 2): Still open in its thread. Finding 8's fix gets master's result for ties without it. It would not fix finding 10, since the zip copies the locations either way.
Minor
- 11.
persistedLineagecan reuseRDD.getNarrowAncestors, and run only for groups of several (new). inline
|
Thanks for the second round, @peter-toth. 5053efb, on top of 4d1dbdf, takes your fixes for findings 5 and 6:
|
|
Thanks, @peter-toth. 114d73e takes findings 8 to 11. It also changes one more thing: groups that share partitions, as the slots of a split key do under |
There was a problem hiding this comment.
Re-checked through 114d73e. Findings 8 to 11 are resolved, and the groups that share partitions give master's locations in both zip orders. On finding 7, a follow-up works for me, as you suggested in r4601387113.
Non-blocking
- 12. The vote now runs before the group's partitions are read (new): the first group that votes then computes the parent's partitions inside
DAGScheduler.getCacheLocs, under the scheduler-widecacheLocslock. That takes the ancestors' locks in the reverse of the documented order.5053efbread the partitions first, and doing so again fixes it. inline:GroupPartitionsExec.scala:900
Minor
- 13. The scaladoc's tie reason, like my finding 8, holds only when the first input that has locations names a tied host (new). inline:
GroupPartitionsExec.scala:911 - 14. The scaladoc puts the persisted check per group, but one persisted RDD in the parent's lineage stops every group from voting (late catch). inline:
GroupPartitionsExec.scala:871
|
Thanks, @peter-toth. e082743 takes findings 12 to 14, and finding 7 stays for the follow-up. If nothing else blocks, could you take another look for approval? |
There was a problem hiding this comment.
Re-checked through e082743. Findings 12, 13 and 14 are resolved. With the reorder, my finding 12 probe computes the parent's partitions outside cacheLocs. Finding 7 stays for the follow-up, as agreed.
Non-blocking
- 15. A host on every input becomes the only location of every group (late catch): when one host holds a replica of every input, every group of several partitions names that host alone. Master offered each task its first input's replicas. Please state this cost in the description, as you did for the zip case. The follow-up for finding 7 can return several locations, which would remove it. inline:
GroupPartitionsExec.scala:923
…ks and improve its location choice GroupedPartitionCoalescer, which GroupPartitionsExec uses to coalesce partitions for storage-partitioned operations, shipped its groups in every task binary, although only getPartitions on the driver reads them. They are now @transient. The coalescer also checks that it is asked for as many partitions as it has groups. Each group still prefers the host that most of its partitions prefer, but: - A partition's hosts are the ones the scheduler would use for it, found through the parent's lineage, as in DefaultPartitionCoalescer. Over a scan, GroupPartitionsExec coalesces the scan's mapped RDD, which reports no locations of its own, so no group named one, and the scheduler took all the locations of the group's first input that had any. Such a group now prefers the host that most of its inputs report. - A partition counts once for each host, however often it lists it, and a null host is ignored. - Ties are spread across groups instead of all going to one host.
… to the scheduler A group got one host when the coalesced RDD's partitions were computed, which lost locality that master had: - Over persisted data, a group preferred the source's host instead of the executor that holds the cached block, since the scheduler looks cached blocks up only when it submits each stage. - An executor or HDFS-cache location shrank to its host. - A group of one partition got one of its input's hosts instead of all of them. Now a group of one partition names no location, and neither does any group when the parent's narrow lineage is persisted, so the scheduler finds the locations itself, as on master. A group of several partitions keeps the executor or HDFS-cache location when every input on the chosen host names it. Each input's locations are looked up once, even when groups share inputs, as the slots of a key do under REPLICATED_FOR_JOIN.
…red groups A group whose inputs tie on hosts named one of them, by assigned count and then by name. That narrowed the scheduler's offer of the first input's locations to one host, and the name order sent more groups to the lowest-sorting hosts. A group now names a host only when more of its inputs prefer it than any other host. Groups that share inputs, as the slots of a key do under REPLICATED_FOR_JOIN, all named the same host when one was ahead, and a zip copied it into every task of the key. Such groups now leave their locations to the scheduler, which gives each task master's locations: its own split's when the split side comes first in the zip, and every location of the first replicated input otherwise. No input is then looked up twice, so the lookup memo goes away. The persisted-lineage check now uses RDD.getNarrowAncestors. It and the shared-input check are computed at most once, and only when a group of several partitions needs them. The tests cover a persisted parent and one two maps down, a cached side in a zip against a side that names a host, executor and HDFS-cache locations next to inputs on other hosts, a host named in two forms, a host ahead without a majority, shared and unshared groups side by side in both zip orders, and the group-count check in both directions.
The vote looked locations up before the group's partitions were read, so the first group that voted made the scheduler compute the parent's partitions while it held its cache-location map, against the lock order DAGScheduler documents. The partitions are read first again. The scaladoc now says that one persisted RDD in the parent's narrow lineage stops every group from voting, and that naming a tied host would mostly, not always, narrow the scheduler's offer.
|
Merge Summary:
Posted by |
|
Thanks @peter-toth! I opened the 4.x backport in #60721 (the only conflict was the SPARK-60541 test helper, which branch-4.x doesn't have) and rebased #59522 on master. It's now based only on #60453. |
…f tasks and improve its location choice ### Differences from #60256 This is a backport of #60256 to `branch-4.x`. The cherry-pick of `05055e0c41c` conflicted only in `GroupPartitionsExecSuite`: on master the file ends with `InterpretedYears`, a test helper from SPARK-60541 (#59866), which `branch-4.x` doesn't have, so this PR adds only the `LocationCountingRDD` helper. `GroupedPartitionCoalescer` is the same as on master. On `branch-4.x`, with JDK 21: `GroupPartitionsExecSuite`, `KeyGroupedPartitioningSuite` and its three runtime-filter variants, `EnsureRequirementsSuite`, the six `DynamicPartitionPruningV2*` suites and the `DataSourceV2FileSourceDPPSuite` variants passed (713 tests, 9 ignored when AQE is on), and SQL scalastyle passed. ### What changes were proposed in this pull request? This PR changes `GroupedPartitionCoalescer`, which `GroupPartitionsExec` uses to coalesce partitions for storage-partitioned operations: - It marks its groups `transient`. `CoalescedRDD`, and `SortedMergeCoalescedRDD` for a k-way merge, keep the coalescer, so its groups were serialized into every task binary, although only `getPartitions` on the driver reads them. - It checks, with a message, that it is asked for as many partitions as it has groups, since a caller sizes the coalesced RDD by its groups. - A group of several partitions prefers a host only when more of its partitions prefer it than any other host. It finds each partition's locations through the parent's lineage with `SparkContext.getPreferredLocs`, as `DefaultPartitionCoalescer` does. Before, it read only the parent's own `preferredLocations` and took the most common entry, the first in a hash map's order on a tie. Over a scan, `GroupPartitionsExec` coalesces the scan's mapped RDD, which reports no locations of its own, so no group named one. - A partition counts once for each host, however often and in whatever form it names that host, and a null host is ignored. - When the only location that the group's partitions name on the chosen host is an executor or an HDFS cache, the group keeps that location instead of the host. - Other groups name no location: a group of one partition, a group with no host ahead, a group that shares partitions with another group, as the slots of a key do under `REPLICATED_FOR_JOIN`, and any group when the parent, or an RDD that its narrow dependencies reach, is persisted. The scheduler then finds the locations itself when it submits each stage, as it did on master over a scan. It offers every location of a group of one's partition, the locations of a group's first partition that has any, and the executor that holds a cached block. ### Why are the changes needed? Large groupings no longer add to the task binary of every task. Groups of several partitions over a scan, where more of the inputs prefer one host than any other, now prefer that host. Before, they named none, and the scheduler offered the locations of the group's first input that had any. A group gets one location, once, when the coalesced RDD's partitions are computed, while the scheduler looks cached blocks up at each stage submission and can offer several locations. So the coalescer leaves the choice to the scheduler where its one location would be worse: - over persisted data, where only the scheduler sees the cached blocks; - for a group of one, where the scheduler offers every location of its partition; - where no host is ahead, since naming one tied host would mostly narrow the scheduler's offer of the first input's locations; - for groups that share partitions, since a zip would copy their one host into every task of the key in a partially clustered join. Left to the scheduler, each task gets master's locations: its own split's when the split side comes first in the zip, and every location of the first replicated input otherwise. SPARK-60265 (#59522) reuses this coalescer for V2 scan partition packing. ### Does this PR introduce _any_ user-facing change? There is no API change. Storage-partitioned groups of several partitions over a scan, where more of the inputs prefer one host than any other, now prefer one location: that host, or the only location that the group's inputs name on it, such as an executor. Before, no group named a location. Over a parent that reports locations of its own, a group named its partitions' most common location before, and it now follows the same rules. As with `DefaultPartitionCoalescer`, a group gets its location when the coalesced RDD's partitions are computed, and the partitions of a group that votes have their locations looked up once more for that. Otherwise the scheduler finds the locations itself, as on master over a scan: - for a group of one partition; - for a group with no host ahead; - for groups that share partitions, as the slots of a key do in a partially clustered join; - for groups whose parent's narrow lineage is persisted, such as a `GroupPartitionsExec` over an `InMemoryTableScanExec`; - where no input reports a location, as with the in-memory test connectors. The exception is a join that zips the grouped RDDs directly: a row-based `GroupPartitionsExec` right under a shuffled hash join, or under a sort-merge join that needs no sort. `ZippedPartitionsRDD` copies each side's own location when it computes its partitions. So when one side's group names a location, the other side adds none if its group names none, as a group of one, a group with no host ahead or a group over cached data does, and the task prefers that one location. Over cached data, the task then reads the block remotely. On master over a scan, such a task got the locations of the first input that had any on the zip's first side (the streamed side under whole-stage codegen), or the executor that holds that side's cached block. Where a `ColumnarToRowExec` or a `SortExec` sits between the grouping and the join, as over a vectorized scan, the zip has no locations of its own, and the scheduler finds them as on master. A host that holds a replica of every input also narrows the offer. That happens when a single writer on a datanode loaded the table, since HDFS puts the first replica of each block on the writer's node. The host is then ahead in every group of several partitions, so each of those groups names it alone and their tasks all prefer it. The tasks that do not fit there wait for the locality timeout and then read remotely, where on master they could start node-local to their first input on another replica. A weak plurality narrows a single group the same way: with ten inputs where one host holds two and every other host one, the group names that host, where master offered its first input's replicas. Returning several locations for a group, such as the leading host plus the first input's replicas, would remove this; that is left for the follow-up on an alternative design. ### How was this patch tested? Six tests in `GroupPartitionsExecSuite`: - A group names no location when no host is ahead, and the scheduler then offers its first input's locations. A group of one names none either. It also covers the partition-count check in both directions, a host ahead with and without a majority, a host counted once per partition however it is named, null hosts, and that tasks do not carry the groups. - Groups over a mapped parent, as over a scan, prefer the hosts found through its lineage. The scheduler finds a group of one's location through the lineage, and a group names none when nothing in the lineage has a host. - In a zip, a side over a map, as over a scan, whose group names a host decides the task's location, both against a group of one and against a group over cached data, for which the scheduler alone would offer the executor that holds the block. - Groups over a persisted parent, and over one two maps down, as over an `InMemoryTableScanExec`, name no location, so once the data is cached the scheduler offers the executor that holds the block. - A group of several partitions keeps an executor or HDFS-cache location that is the only one its inputs name on the host, also next to an input on another host, and gets the host otherwise. For groups of one, the scheduler offers an executor location, an HDFS-cache location, and all three hosts of a replicated input. - Groups that share partitions, as the slots of a split key in a partially clustered join, name no location and look none up, while an unshared group next to them still votes, looking each input up once. Zipped with the split side's groups of one, the tasks get master's locations in both zip orders: their own split's when the split side comes first, and every location of the first replicated input otherwise. Locally, with JDK 21: - `GroupPartitionsExecSuite`, `KeyGroupedPartitioningSuite` and its three runtime-filter variants, `EnsureRequirementsSuite`, the six `DynamicPartitionPruningV2*` suites and the `DataSourceV2FileSourceDPPSuite` variants: 711 tests in 14 suites passed (9 ignored when AQE is on, as on master). - SQL scalastyle (main and test) and `sql/mimaReportBinaryIssues` passed. ```bash build/sbt \ 'sql/testOnly org.apache.spark.sql.execution.datasources.v2.GroupPartitionsExecSuite org.apache.spark.sql.connector.KeyGroupedPartitioning* org.apache.spark.sql.execution.exchange.EnsureRequirementsSuite org.apache.spark.sql.DynamicPartitionPruningV2* org.apache.spark.sql.connector.DataSourceV2FileSourceDPPSuite*' \ 'sql/scalastyle' 'sql/Test/scalastyle' 'sql/mimaReportBinaryIssues' ``` ### Was this patch authored or co-authored using generative AI tooling? Co-authored with Claude Code. Closes #60721 from rekbun/SPARK-61279-4.x. Authored-by: Rakesh <rkchoudhary0208@gmail.com> Signed-off-by: Peter Toth <peter.toth@gmail.com> skip-checks: true
What changes were proposed in this pull request?
This PR changes
GroupedPartitionCoalescer, whichGroupPartitionsExecuses to coalesce partitions for storage-partitioned operations:@transient.CoalescedRDD, andSortedMergeCoalescedRDDfor a k-way merge, keep the coalescer, so its groups were serialized into every task binary, although onlygetPartitionson the driver reads them.SparkContext.getPreferredLocs, asDefaultPartitionCoalescerdoes. Before, it read only the parent's ownpreferredLocationsand took the most common entry, the first in a hash map's order on a tie. Over a scan,GroupPartitionsExeccoalesces the scan's mapped RDD, which reports no locations of its own, so no group named one.REPLICATED_FOR_JOIN, and any group when the parent, or an RDD that its narrow dependencies reach, is persisted. The scheduler then finds the locations itself when it submits each stage, as it did on master over a scan. It offers every location of a group of one's partition, the locations of a group's first partition that has any, and the executor that holds a cached block.Why are the changes needed?
Large groupings no longer add to the task binary of every task. Groups of several partitions over a scan, where more of the inputs prefer one host than any other, now prefer that host. Before, they named none, and the scheduler offered the locations of the group's first input that had any.
A group gets one location, once, when the coalesced RDD's partitions are computed, while the scheduler looks cached blocks up at each stage submission and can offer several locations. So the coalescer leaves the choice to the scheduler where its one location would be worse:
SPARK-60265 (#59522) reuses this coalescer for V2 scan partition packing.
Does this PR introduce any user-facing change?
There is no API change.
Storage-partitioned groups of several partitions over a scan, where more of the inputs prefer one host than any other, now prefer one location: that host, or the only location that the group's inputs name on it, such as an executor. Before, no group named a location. Over a parent that reports locations of its own, a group named its partitions' most common location before, and it now follows the same rules.
As with
DefaultPartitionCoalescer, a group gets its location when the coalesced RDD's partitions are computed, and the partitions of a group that votes have their locations looked up once more for that.Otherwise the scheduler finds the locations itself, as on master over a scan:
GroupPartitionsExecover anInMemoryTableScanExec;The exception is a join that zips the grouped RDDs directly: a row-based
GroupPartitionsExecright under a shuffled hash join, or under a sort-merge join that needs no sort.ZippedPartitionsRDDcopies each side's own location when it computes its partitions. So when one side's group names a location, the other side adds none if its group names none, as a group of one, a group with no host ahead or a group over cached data does, and the task prefers that one location. Over cached data, the task then reads the block remotely. On master over a scan, such a task got the locations of the first input that had any on the zip's first side (the streamed side under whole-stage codegen), or the executor that holds that side's cached block. Where aColumnarToRowExecor aSortExecsits between the grouping and the join, as over a vectorized scan, the zip has no locations of its own, and the scheduler finds them as on master.A host that holds a replica of every input also narrows the offer. That happens when a single writer on a datanode loaded the table, since HDFS puts the first replica of each block on the writer's node. The host is then ahead in every group of several partitions, so each of those groups names it alone and their tasks all prefer it. The tasks that do not fit there wait for the locality timeout and then read remotely, where on master they could start node-local to their first input on another replica. A weak plurality narrows a single group the same way: with ten inputs where one host holds two and every other host one, the group names that host, where master offered its first input's replicas. Returning several locations for a group, such as the leading host plus the first input's replicas, would remove this; that is left for the follow-up on an alternative design.
How was this patch tested?
Six tests in
GroupPartitionsExecSuite:InMemoryTableScanExec, name no location, so once the data is cached the scheduler offers the executor that holds the block.Locally, with JDK 21:
GroupPartitionsExecSuite,KeyGroupedPartitioningSuiteand its three runtime-filter variants,EnsureRequirementsSuite, the sixDynamicPartitionPruningV2*suites and theDataSourceV2FileSourceDPPSuitevariants: 711 tests in 14 suites passed (9 ignored when AQE is on, as on master).sql/mimaReportBinaryIssuespassed.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)