-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28560][SQL] Optimize shuffle reader to local shuffle reader when smj converted to bhj in adaptive execution #25295
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf6b6ad
change the shuffle read to local shuffle read when the sort merge joi…
JkSelf 3b3d6ce
fix the can't zip rdd with unequal numbers of partitions and resolve …
JkSelf bdce1c3
move the rule of converting the shuffle reader to local shuffle reade…
JkSelf e5f3c9a
resolve comments
JkSelf d21c99f
small rebase fix
JkSelf bb10b18
java doc style
JkSelf 72ce82e
resolve the comments
JkSelf f0ffff6
code style
JkSelf f10e5b2
resolve the comments
JkSelf 37111ff
resolve the small comments
JkSelf 9c1dc55
resolve the conflicts
JkSelf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,18 +36,33 @@ private[spark] class BlockStoreShuffleReader[K, C]( | |
| readMetrics: ShuffleReadMetricsReporter, | ||
| serializerManager: SerializerManager = SparkEnv.get.serializerManager, | ||
| blockManager: BlockManager = SparkEnv.get.blockManager, | ||
| mapOutputTracker: MapOutputTracker = SparkEnv.get.mapOutputTracker) | ||
| mapOutputTracker: MapOutputTracker = SparkEnv.get.mapOutputTracker, | ||
| mapId: Option[Int] = None) | ||
| extends ShuffleReader[K, C] with Logging { | ||
|
|
||
| private val dep = handle.dependency | ||
|
|
||
| /** Read the combined key-values for this reduce task */ | ||
| override def read(): Iterator[Product2[K, C]] = { | ||
| val blocksByAddress = mapId match { | ||
| case (Some(mapId)) => mapOutputTracker.getMapSizesByExecutorId( | ||
| handle.shuffleId, | ||
| startPartition, | ||
| endPartition, | ||
| mapId) | ||
| case (None) => mapOutputTracker.getMapSizesByExecutorId( | ||
| handle.shuffleId, | ||
| startPartition, | ||
| endPartition) | ||
| case (_) => throw new IllegalArgumentException( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| "mapId should be both set or unset") | ||
| } | ||
|
|
||
| val wrappedStreams = new ShuffleBlockFetcherIterator( | ||
| context, | ||
| blockManager.blockStoreClient, | ||
| blockManager, | ||
| mapOutputTracker.getMapSizesByExecutorId(handle.shuffleId, startPartition, endPartition), | ||
| blocksByAddress, | ||
| serializerManager.wrapStream, | ||
| // Note: we use getSizeAsMb when no suffix is provided for backwards compatibility | ||
| SparkEnv.get.conf.get(config.REDUCER_MAX_SIZE_IN_FLIGHT) * 1024 * 1024, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/LocalShuffledRowRDD.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.execution.adaptive | ||
|
|
||
| import org.apache.spark._ | ||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.execution.metric.{SQLMetric, SQLShuffleReadMetricsReporter} | ||
|
|
||
|
|
||
| /** | ||
| * The [[Partition]] used by [[LocalShuffledRowRDD]]. A pre-shuffle partition | ||
| * (identified by `preShufflePartitionIndex`) contains a range of post-shuffle partitions | ||
| * (`startPostShufflePartitionIndex` to `endPostShufflePartitionIndex - 1`, inclusive). | ||
| */ | ||
| private final class LocalShuffleRowRDDPartition( | ||
|
||
| val preShufflePartitionIndex: Int) extends Partition { | ||
| override val index: Int = preShufflePartitionIndex | ||
| } | ||
|
|
||
| /** | ||
| * This is a specialized version of [[org.apache.spark.sql.execution.ShuffledRowRDD]]. This is used | ||
| * in Spark SQL adaptive execution when a shuffle join is converted to broadcast join at runtime | ||
| * because the map output of one input table is small enough for broadcast. This RDD represents the | ||
| * data of another input table of the join that reads from shuffle. Each partition of the RDD reads | ||
| * the whole data from just one mapper output locally. So actually there is no data transferred | ||
| * from the network. | ||
|
|
||
| * This RDD takes a [[ShuffleDependency]] (`dependency`). | ||
| * | ||
| * The `dependency` has the parent RDD of this RDD, which represents the dataset before shuffle | ||
| * (i.e. map output). Elements of this RDD are (partitionId, Row) pairs. | ||
| * Partition ids should be in the range [0, numPartitions - 1]. | ||
| * `dependency.partitioner.numPartitions` is the number of pre-shuffle partitions. (i.e. the number | ||
| * of partitions of the map output). The post-shuffle partition number is the same to the parent | ||
| * RDD's partition number. | ||
| */ | ||
| class LocalShuffledRowRDD( | ||
| var dependency: ShuffleDependency[Int, InternalRow, InternalRow], | ||
| metrics: Map[String, SQLMetric]) | ||
| extends RDD[InternalRow](dependency.rdd.context, Nil) { | ||
|
|
||
| private[this] val numReducers = dependency.partitioner.numPartitions | ||
| private[this] val numMappers = dependency.rdd.partitions.length | ||
|
|
||
| override def getDependencies: Seq[Dependency[_]] = List(dependency) | ||
|
|
||
| override def getPartitions: Array[Partition] = { | ||
|
|
||
| Array.tabulate[Partition](numMappers) { i => | ||
| new LocalShuffleRowRDDPartition(i) | ||
| } | ||
| } | ||
|
|
||
| override def getPreferredLocations(partition: Partition): Seq[String] = { | ||
| val tracker = SparkEnv.get.mapOutputTracker.asInstanceOf[MapOutputTrackerMaster] | ||
| tracker.getMapLocation(dependency, partition.index) | ||
| } | ||
|
|
||
| override def compute(split: Partition, context: TaskContext): Iterator[InternalRow] = { | ||
| val localRowPartition = split.asInstanceOf[LocalShuffleRowRDDPartition] | ||
| val mapId = localRowPartition.index | ||
| val tempMetrics = context.taskMetrics().createTempShuffleReadMetrics() | ||
| // `SQLShuffleReadMetricsReporter` will update its own metrics for SQL exchange operator, | ||
| // as well as the `tempMetrics` for basic shuffle metrics. | ||
| val sqlMetricsReporter = new SQLShuffleReadMetricsReporter(tempMetrics, metrics) | ||
|
|
||
| val reader = SparkEnv.get.shuffleManager.getMapReader( | ||
| dependency.shuffleHandle, | ||
| 0, | ||
| numReducers, | ||
| context, | ||
| sqlMetricsReporter, | ||
| mapId) | ||
| reader.read().asInstanceOf[Iterator[Product2[Int, InternalRow]]].map(_._2) | ||
| } | ||
|
|
||
| override def clearDependencies() { | ||
| super.clearDependencies() | ||
| dependency = null | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.