-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-31344][CORE] Polish implementation of barrier() and allGather() #28117
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
5 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -17,20 +17,13 @@ | |
|
|
||
| package org.apache.spark | ||
|
|
||
| import java.nio.charset.StandardCharsets.UTF_8 | ||
| import java.util.{Properties, Timer, TimerTask} | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.collection.mutable.ArrayBuffer | ||
| import scala.concurrent.TimeoutException | ||
| import scala.concurrent.duration._ | ||
| import scala.language.postfixOps | ||
|
|
||
| import org.json4s.DefaultFormats | ||
| import org.json4s.JsonAST._ | ||
| import org.json4s.JsonDSL._ | ||
| import org.json4s.jackson.JsonMethods.parse | ||
|
|
||
| import org.apache.spark.annotation.{Experimental, Since} | ||
| import org.apache.spark.executor.TaskMetrics | ||
| import org.apache.spark.internal.Logging | ||
|
|
@@ -67,31 +60,7 @@ class BarrierTaskContext private[spark] ( | |
| // from different tasks within the same barrier stage attempt to succeed. | ||
| private lazy val numTasks = getTaskInfos().size | ||
|
|
||
| private def getRequestToSync( | ||
| numTasks: Int, | ||
| stageId: Int, | ||
| stageAttemptNumber: Int, | ||
| taskAttemptId: Long, | ||
| barrierEpoch: Int, | ||
| partitionId: Int, | ||
| requestMethod: RequestMethod.Value, | ||
| allGatherMessage: String | ||
| ): RequestToSync = { | ||
| requestMethod match { | ||
| case RequestMethod.BARRIER => | ||
| BarrierRequestToSync(numTasks, stageId, stageAttemptNumber, taskAttemptId, | ||
| barrierEpoch, partitionId, requestMethod) | ||
| case RequestMethod.ALL_GATHER => | ||
| AllGatherRequestToSync(numTasks, stageId, stageAttemptNumber, taskAttemptId, | ||
| barrierEpoch, partitionId, requestMethod, allGatherMessage) | ||
| } | ||
| } | ||
|
|
||
| private def runBarrier( | ||
| requestMethod: RequestMethod.Value, | ||
| allGatherMessage: String = "" | ||
| ): String = { | ||
|
|
||
| private def runBarrier(message: String, requestMethod: RequestMethod.Value): Array[String] = { | ||
| logInfo(s"Task $taskAttemptId from Stage $stageId(Attempt $stageAttemptNumber) has entered " + | ||
| s"the global sync, current barrier epoch is $barrierEpoch.") | ||
| logTrace("Current callSite: " + Utils.getCallSite()) | ||
|
|
@@ -108,24 +77,24 @@ class BarrierTaskContext private[spark] ( | |
| // Log the update of global sync every 60 seconds. | ||
| timer.schedule(timerTask, 60000, 60000) | ||
|
|
||
| var json: String = "" | ||
|
|
||
| try { | ||
| val abortableRpcFuture = barrierCoordinator.askAbortable[String]( | ||
| message = getRequestToSync(numTasks, stageId, stageAttemptNumber, | ||
| taskAttemptId, barrierEpoch, partitionId, requestMethod, allGatherMessage), | ||
| val abortableRpcFuture = barrierCoordinator.askAbortable[Array[String]]( | ||
| message = RequestToSync(numTasks, stageId, stageAttemptNumber, taskAttemptId, | ||
| barrierEpoch, partitionId, message, requestMethod), | ||
| // Set a fixed timeout for RPC here, so users shall get a SparkException thrown by | ||
| // BarrierCoordinator on timeout, instead of RPCTimeoutException from the RPC framework. | ||
| timeout = new RpcTimeout(365.days, "barrierTimeout")) | ||
|
|
||
| // messages which consist of all barrier tasks' messages | ||
| var messages: Array[String] = null | ||
| // Wait the RPC future to be completed, but every 1 second it will jump out waiting | ||
| // and check whether current spark task is killed. If killed, then throw | ||
| // a `TaskKilledException`, otherwise continue wait RPC until it completes. | ||
| try { | ||
| while (!abortableRpcFuture.toFuture.isCompleted) { | ||
| // wait RPC future for at most 1 second | ||
| try { | ||
| json = ThreadUtils.awaitResult(abortableRpcFuture.toFuture, 1.second) | ||
| messages = ThreadUtils.awaitResult(abortableRpcFuture.toFuture, 1.second) | ||
| } catch { | ||
| case _: TimeoutException | _: InterruptedException => | ||
| // If `TimeoutException` thrown, waiting RPC future reach 1 second. | ||
|
|
@@ -144,6 +113,7 @@ class BarrierTaskContext private[spark] ( | |
| "global sync successfully, waited for " + | ||
| s"${MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)} seconds, " + | ||
| s"current barrier epoch is $barrierEpoch.") | ||
| messages | ||
| } catch { | ||
| case e: SparkException => | ||
| logInfo(s"Task $taskAttemptId from Stage $stageId(Attempt $stageAttemptNumber) failed " + | ||
|
|
@@ -155,7 +125,6 @@ class BarrierTaskContext private[spark] ( | |
| timerTask.cancel() | ||
| timer.purge() | ||
| } | ||
| json | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -200,10 +169,7 @@ class BarrierTaskContext private[spark] ( | |
| */ | ||
| @Experimental | ||
| @Since("2.4.0") | ||
| def barrier(): Unit = { | ||
| runBarrier(RequestMethod.BARRIER) | ||
| () | ||
| } | ||
| def barrier(): Unit = runBarrier("", RequestMethod.BARRIER) | ||
|
|
||
|
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: extra line |
||
| /** | ||
| * :: Experimental :: | ||
|
|
@@ -217,12 +183,7 @@ class BarrierTaskContext private[spark] ( | |
| */ | ||
| @Experimental | ||
| @Since("3.0.0") | ||
| def allGather(message: String): Array[String] = { | ||
| val json = runBarrier(RequestMethod.ALL_GATHER, message) | ||
| val jsonArray = parse(json) | ||
| implicit val formats = DefaultFormats | ||
| jsonArray.extract[Array[String]] | ||
| } | ||
| def allGather(message: String): Array[String] = runBarrier(message, RequestMethod.ALL_GATHER) | ||
|
|
||
| /** | ||
| * :: Experimental :: | ||
|
|
||
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
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.