{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/24229185","id":24229185,"diff_hunk":"@@ -17,33 +17,86 @@\n \n package org.apache.spark\n \n-import akka.actor.Actor\n+import scala.concurrent.duration._\n+import scala.collection.mutable\n+\n+import akka.actor.{Actor, Cancellable}\n+\n import org.apache.spark.executor.TaskMetrics\n import org.apache.spark.storage.BlockManagerId\n-import org.apache.spark.scheduler.TaskScheduler\n+import org.apache.spark.scheduler.{SlaveLost, TaskScheduler}\n import org.apache.spark.util.ActorLogReceive\n \n /**\n  * A heartbeat from executors to the driver. This is a shared message used by several internal\n- * components to convey liveness or execution information for in-progress tasks.\n+ * components to convey liveness or execution information for in-progress tasks. It will also \n+ * expire the hosts that have not heartbeated for more than spark.driver.executorTimeoutMs.\n  */\n private[spark] case class Heartbeat(\n     executorId: String,\n     taskMetrics: Array[(Long, TaskMetrics)], // taskId -> TaskMetrics\n     blockManagerId: BlockManagerId)\n \n+private[spark] case object ExpireDeadHosts \n+    \n private[spark] case class HeartbeatResponse(reregisterBlockManager: Boolean)\n \n /**\n  * Lives in the driver to receive heartbeats from executors..\n  */\n-private[spark] class HeartbeatReceiver(scheduler: TaskScheduler)\n+private[spark] class HeartbeatReceiver(sc: SparkContext, scheduler: TaskScheduler)\n   extends Actor with ActorLogReceive with Logging {\n \n+  val executorLastSeen = new mutable.HashMap[String, Long]\n+  \n+  val executorTimeout = sc.conf.getLong(\"spark.driver.executorTimeoutMs\", \n+    sc.conf.getLong(\"spark.storage.blockManagerSlaveTimeoutMs\", 120 * 1000))\n+  \n+  val checkTimeoutInterval = sc.conf.getLong(\"spark.driver.executorTimeoutIntervalMs\",\n+    sc.conf.getLong(\"spark.storage.blockManagerTimeoutIntervalMs\", 60000))\n+  \n+  var timeoutCheckingTask: Cancellable = null\n+  \n+  override def preStart(): Unit = {\n+    import context.dispatcher\n+    timeoutCheckingTask = context.system.scheduler.schedule(0.seconds,\n+      checkTimeoutInterval.milliseconds, self, ExpireDeadHosts)\n+    super.preStart\n+  }\n+  \n   override def receiveWithLogging = {\n     case Heartbeat(executorId, taskMetrics, blockManagerId) =>\n       val response = HeartbeatResponse(\n         !scheduler.executorHeartbeatReceived(executorId, taskMetrics, blockManagerId))\n+      heartbeatReceived(executorId)\n       sender ! response\n+    case ExpireDeadHosts =>\n+      expireDeadHosts()\n+  }\n+  \n+  private def heartbeatReceived(executorId: String): Unit = {\n+    executorLastSeen(executorId) = System.currentTimeMillis()\n+  }\n+  \n+  private def expireDeadHosts(): Unit = {\n+    logTrace(\"Checking for hosts with no recent heart beats in HeartbeatReceiver.\")\n+    val now = System.currentTimeMillis()\n+    val minSeenTime = now - executorTimeout\n+    for ((executorId, lastSeenMs) <- executorLastSeen) {\n+      if (lastSeenMs < minSeenTime) {\n+        logWarning(\"Removing Executor \" + executorId + \" with no recent heartbeats: \"\n+          + (now - lastSeenMs) + \" ms exceeds \" + executorTimeout + \"ms\")\n+        scheduler.executorLost(executorId, SlaveLost())\n+        sc.killExecutor(executorId)\n+        executorLastSeen.remove(executorId)\n+      }\n+    }\n+  }\n+  \n+  override def postStop(): Unit = {\n+    if (timeoutCheckingTask != null) {\n+      timeoutCheckingTask.cancel()\n+    }\n+    super.postStop","path":"core/src/main/scala/org/apache/spark/HeartbeatReceiver.scala","position":88,"original_position":88,"commit_id":"6bab7aafb2824d935302be2a57e82559499491a9","original_commit_id":"6bab7aafb2824d935302be2a57e82559499491a9","user":{"login":"sryza","id":654855,"avatar_url":"https://avatars.githubusercontent.com/u/654855?v=3","gravatar_id":"","url":"https://api.github.com/users/sryza","html_url":"https://github.com/sryza","followers_url":"https://api.github.com/users/sryza/followers","following_url":"https://api.github.com/users/sryza/following{/other_user}","gists_url":"https://api.github.com/users/sryza/gists{/gist_id}","starred_url":"https://api.github.com/users/sryza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sryza/subscriptions","organizations_url":"https://api.github.com/users/sryza/orgs","repos_url":"https://api.github.com/users/sryza/repos","events_url":"https://api.github.com/users/sryza/events{/privacy}","received_events_url":"https://api.github.com/users/sryza/received_events","type":"User","site_admin":false},"body":"This invocation should include parentheses because it mutates state.","created_at":"2015-02-06T09:06:27Z","updated_at":"2015-02-06T09:06:27Z","html_url":"https://github.com/apache/spark/pull/4363#discussion_r24229185","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/4363","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/24229185"},"html":{"href":"https://github.com/apache/spark/pull/4363#discussion_r24229185"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/4363"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/4363","id":28624694,"html_url":"https://github.com/apache/spark/pull/4363","diff_url":"https://github.com/apache/spark/pull/4363.diff","patch_url":"https://github.com/apache/spark/pull/4363.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/4363","number":4363,"state":"open","locked":false,"title":" [SPARK-5529][CORE]Add expireDeadHosts in HeartbeatReceiver","user":{"login":"shenh062326","id":9527867,"avatar_url":"https://avatars.githubusercontent.com/u/9527867?v=3","gravatar_id":"","url":"https://api.github.com/users/shenh062326","html_url":"https://github.com/shenh062326","followers_url":"https://api.github.com/users/shenh062326/followers","following_url":"https://api.github.com/users/shenh062326/following{/other_user}","gists_url":"https://api.github.com/users/shenh062326/gists{/gist_id}","starred_url":"https://api.github.com/users/shenh062326/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shenh062326/subscriptions","organizations_url":"https://api.github.com/users/shenh062326/orgs","repos_url":"https://api.github.com/users/shenh062326/repos","events_url":"https://api.github.com/users/shenh062326/events{/privacy}","received_events_url":"https://api.github.com/users/shenh062326/received_events","type":"User","site_admin":false},"body":"If a blockManager has not send heartBeat more than 120s, BlockManagerMasterActor will remove it. But coarseGrainedSchedulerBackend can only remove executor after an DisassociatedEvent.  We should expireDeadHosts at HeartbeatReceiver.","created_at":"2015-02-04T09:45:21Z","updated_at":"2015-02-06T09:06:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f1a239a244a7014a1e662688dae4f7227ddc724","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/4363/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/4363/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments/{number}","comments_url":"https://api.github.com/repos/apache/spark/issues/4363/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/6bab7aafb2824d935302be2a57e82559499491a9","head":{"label":"shenh062326:my_change3","ref":"my_change3","sha":"6bab7aafb2824d935302be2a57e82559499491a9","user":{"login":"shenh062326","id":9527867,"avatar_url":"https://avatars.githubusercontent.com/u/9527867?v=3","gravatar_id":"","url":"https://api.github.com/users/shenh062326","html_url":"https://github.com/shenh062326","followers_url":"https://api.github.com/users/shenh062326/followers","following_url":"https://api.github.com/users/shenh062326/following{/other_user}","gists_url":"https://api.github.com/users/shenh062326/gists{/gist_id}","starred_url":"https://api.github.com/users/shenh062326/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shenh062326/subscriptions","organizations_url":"https://api.github.com/users/shenh062326/orgs","repos_url":"https://api.github.com/users/shenh062326/repos","events_url":"https://api.github.com/users/shenh062326/events{/privacy}","received_events_url":"https://api.github.com/users/shenh062326/received_events","type":"User","site_admin":false},"repo":{"id":26584906,"name":"spark","full_name":"shenh062326/spark","owner":{"login":"shenh062326","id":9527867,"avatar_url":"https://avatars.githubusercontent.com/u/9527867?v=3","gravatar_id":"","url":"https://api.github.com/users/shenh062326","html_url":"https://github.com/shenh062326","followers_url":"https://api.github.com/users/shenh062326/followers","following_url":"https://api.github.com/users/shenh062326/following{/other_user}","gists_url":"https://api.github.com/users/shenh062326/gists{/gist_id}","starred_url":"https://api.github.com/users/shenh062326/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shenh062326/subscriptions","organizations_url":"https://api.github.com/users/shenh062326/orgs","repos_url":"https://api.github.com/users/shenh062326/repos","events_url":"https://api.github.com/users/shenh062326/events{/privacy}","received_events_url":"https://api.github.com/users/shenh062326/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shenh062326/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/shenh062326/spark","forks_url":"https://api.github.com/repos/shenh062326/spark/forks","keys_url":"https://api.github.com/repos/shenh062326/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shenh062326/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shenh062326/spark/teams","hooks_url":"https://api.github.com/repos/shenh062326/spark/hooks","issue_events_url":"https://api.github.com/repos/shenh062326/spark/issues/events{/number}","events_url":"https://api.github.com/repos/shenh062326/spark/events","assignees_url":"https://api.github.com/repos/shenh062326/spark/assignees{/user}","branches_url":"https://api.github.com/repos/shenh062326/spark/branches{/branch}","tags_url":"https://api.github.com/repos/shenh062326/spark/tags","blobs_url":"https://api.github.com/repos/shenh062326/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shenh062326/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shenh062326/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/shenh062326/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shenh062326/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/shenh062326/spark/languages","stargazers_url":"https://api.github.com/repos/shenh062326/spark/stargazers","contributors_url":"https://api.github.com/repos/shenh062326/spark/contributors","subscribers_url":"https://api.github.com/repos/shenh062326/spark/subscribers","subscription_url":"https://api.github.com/repos/shenh062326/spark/subscription","commits_url":"https://api.github.com/repos/shenh062326/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/shenh062326/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/shenh062326/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/shenh062326/spark/issues/comments/{number}","contents_url":"https://api.github.com/repos/shenh062326/spark/contents/{+path}","compare_url":"https://api.github.com/repos/shenh062326/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shenh062326/spark/merges","archive_url":"https://api.github.com/repos/shenh062326/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shenh062326/spark/downloads","issues_url":"https://api.github.com/repos/shenh062326/spark/issues{/number}","pulls_url":"https://api.github.com/repos/shenh062326/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/shenh062326/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/shenh062326/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shenh062326/spark/labels{/name}","releases_url":"https://api.github.com/repos/shenh062326/spark/releases{/id}","created_at":"2014-11-13T11:34:17Z","updated_at":"2014-11-13T11:34:30Z","pushed_at":"2015-02-06T01:38:22Z","git_url":"git://github.com/shenh062326/spark.git","ssh_url":"git@github.com:shenh062326/spark.git","clone_url":"https://github.com/shenh062326/spark.git","svn_url":"https://github.com/shenh062326/spark","homepage":null,"size":89224,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"5aa0f219d1f8e8d3bb083dd547532ebb72ba7a15","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments/{number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-02-06T09:02:16Z","pushed_at":"2015-02-06T09:02:16Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1232109,"stargazers_count":2797,"watchers_count":2797,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2448,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":307,"forks":2448,"open_issues":307,"watchers":2797,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/4363"},"html":{"href":"https://github.com/apache/spark/pull/4363"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/4363"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/4363/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/4363/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/4363/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/6bab7aafb2824d935302be2a57e82559499491a9"}}}}