-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-10058][Core][Tests]Fix the flaky tests in HeartbeatReceiverSuite #8946
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,13 @@ package org.apache.spark | |
| import java.util.concurrent.{ScheduledFuture, TimeUnit} | ||
|
|
||
| import scala.collection.mutable | ||
| import scala.concurrent.Future | ||
|
|
||
| import org.apache.spark.executor.TaskMetrics | ||
| import org.apache.spark.rpc.{ThreadSafeRpcEndpoint, RpcEnv, RpcCallContext} | ||
| import org.apache.spark.storage.BlockManagerId | ||
| import org.apache.spark.scheduler._ | ||
| import org.apache.spark.util.{Clock, SystemClock, ThreadUtils, Utils} | ||
| import org.apache.spark.util._ | ||
|
|
||
| /** | ||
| * A heartbeat from executors to the driver. This is a shared message used by several internal | ||
|
|
@@ -61,7 +62,12 @@ private[spark] class HeartbeatReceiver(sc: SparkContext, clock: Clock) | |
| this(sc, new SystemClock) | ||
| } | ||
|
|
||
| sc.addSparkListener(this) | ||
| if (clock.isInstanceOf[SystemClock]) { | ||
| sc.addSparkListener(this) | ||
| } else { | ||
| // We are in HeartbeatReceiverSuite. So don't add HeartbeatReceiver to SparkContext to avoid | ||
| // receiving undesired events (SPARK-10058). | ||
| } | ||
|
|
||
| override val rpcEnv: RpcEnv = sc.env.rpcEnv | ||
|
|
||
|
|
@@ -147,11 +153,31 @@ private[spark] class HeartbeatReceiver(sc: SparkContext, clock: Clock) | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Send ExecutorRegistered to the event loop to add a new executor. Only for test. | ||
| * | ||
| * @return if HeartbeatReceiver is stopped, return None. Otherwise, return a Some(Future) that | ||
| * indicate if this operation is successful. | ||
| */ | ||
| def addExecutor(executorId: String): Option[Future[Boolean]] = { | ||
| Option(self).map(_.ask[Boolean](ExecutorRegistered(executorId))) | ||
| } | ||
|
|
||
| /** | ||
| * If the heartbeat receiver is not stopped, notify it of executor registrations. | ||
| */ | ||
| override def onExecutorAdded(executorAdded: SparkListenerExecutorAdded): Unit = { | ||
| Option(self).foreach(_.ask[Boolean](ExecutorRegistered(executorAdded.executorId))) | ||
| addExecutor(executorAdded.executorId) | ||
| } | ||
|
|
||
| /** | ||
| * Send ExecutorRemoved to the event loop to remove a executor. Only for test. | ||
| * | ||
| * @return if HeartbeatReceiver is stopped, return None. Otherwise, return a Some(Future) that | ||
| * indicate if this operation is successful. | ||
| */ | ||
| def removeExecutor(executorId: String): Option[Future[Boolean]] = { | ||
|
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. It doesn't seem like this and
Member
Author
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. I need to use the
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. Ah, I missed the future. Nevermind then. |
||
| Option(self).map(_.ask[Boolean](ExecutorRemoved(executorId))) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -165,7 +191,7 @@ private[spark] class HeartbeatReceiver(sc: SparkContext, clock: Clock) | |
| * and expire it with loud error messages. | ||
| */ | ||
| override def onExecutorRemoved(executorRemoved: SparkListenerExecutorRemoved): Unit = { | ||
| Option(self).foreach(_.ask[Boolean](ExecutorRemoved(executorRemoved.executorId))) | ||
| removeExecutor(executorRemoved.executorId) | ||
| } | ||
|
|
||
| private def expireDeadHosts(): Unit = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of a weird check; I'd favor either some explicit "testMode" boolean parameter to the constructor, or, my preferred, making the test ignore executors that match
SparkContext.DRIVER_IDENTIFIER.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great. I will update it.