{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/24065627","id":24065627,"diff_hunk":"@@ -506,13 +506,59 @@ private[spark] class TaskSetManager(\n    * Get the level we can launch tasks according to delay scheduling, based on current wait time.\n    */\n   private def getAllowedLocalityLevel(curTime: Long): TaskLocality.TaskLocality = {\n-    while (curTime - lastLaunchTime >= localityWaits(currentLocalityIndex) &&\n-        currentLocalityIndex < myLocalityLevels.length - 1)\n-    {\n-      // Jump to the next locality level, and remove our waiting time for the current one since\n-      // we don't want to count it again on the next one\n-      lastLaunchTime += localityWaits(currentLocalityIndex)\n-      currentLocalityIndex += 1\n+    // Remove the scheduled or finished tasks lazily\n+    def hasNotScheduledTasks(taskIndexes: ArrayBuffer[Int]): Boolean = {\n+      var indexOffset = taskIndexes.size\n+      while (indexOffset > 0) {\n+        indexOffset -= 1\n+        val index = taskIndexes(indexOffset)\n+        if (copiesRunning(index) == 0 && !successful(index)) {\n+          return true\n+        } else {\n+          taskIndexes.remove(indexOffset)\n+        }\n+      }\n+      false\n+    }\n+    // It removes the empty lists after check\n+    def hasMoreTasks(pendingTasks: HashMap[String, ArrayBuffer[Int]]): Boolean = {\n+      val emptyKeys = new ArrayBuffer[String]\n+      val hasTasks = pendingTasks.exists{\n+        case (id: String, tasks: ArrayBuffer[Int]) =>\n+          if (hasNotScheduledTasks(tasks)) {\n+            true\n+          } else {\n+            emptyKeys += id\n+            false\n+          }\n+      }\n+      emptyKeys.foreach(x => pendingTasks.remove(x))\n+      hasTasks\n+    }\n+\n+    while (currentLocalityIndex < myLocalityLevels.length - 1) {\n+      val moreTasks = myLocalityLevels(currentLocalityIndex) match {\n+        case TaskLocality.PROCESS_LOCAL => hasMoreTasks(pendingTasksForExecutor)\n+        case TaskLocality.NODE_LOCAL => hasMoreTasks(pendingTasksForHost)\n+        case TaskLocality.NO_PREF => pendingTasksWithNoPrefs.isEmpty","path":"core/src/main/scala/org/apache/spark/scheduler/TaskSetManager.scala","position":45,"original_position":45,"commit_id":"6b13824badb6f47b102accd93742e7ce5b36364b","original_commit_id":"6b13824badb6f47b102accd93742e7ce5b36364b","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"The tasks with NO_PREF should not be in other lists, so do not need to remove them lazily, just check the whole list is empty or not.\r\n\r\nI will add a comment.","created_at":"2015-02-04T06:51:25Z","updated_at":"2015-02-04T06:51:25Z","html_url":"https://github.com/apache/spark/pull/3779#discussion_r24065627","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/3779","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/24065627"},"html":{"href":"https://github.com/apache/spark/pull/3779#discussion_r24065627"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/3779"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/3779","id":26529421,"html_url":"https://github.com/apache/spark/pull/3779","diff_url":"https://github.com/apache/spark/pull/3779.diff","patch_url":"https://github.com/apache/spark/pull/3779.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/3779","number":3779,"state":"open","locked":false,"title":"[SPARK-4939] move to next locality when no pending tasks","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"Currently, if there are different locality in a task set, the tasks with NODE_LOCAL only get scheduled after all the PROCESS_LOCAL tasks are scheduled and timeout with spark.locality.wait.process (3 seconds by default). In local mode, the LocalScheduler will never call resourceOffer() again once it failed to get a task with same locality, then all the NODE_LOCAL tasks will be never scheduled.\r\n\r\nThis bug could be reproduced by run example python/streaming/stateful_network_wordcount.py, it will hang after finished a batch with some data.\r\n\r\nThis patch will check whether there is task for current locality level, if not, it will change to next locality level without waiting for `spark.locality.wait.process` seconds. It works for all locality levels.\r\n\r\nBecause the list of pending tasks are updated lazily, the check can be false-positive, it means it will not move to next locality level even there is no valid pending tasks, it will wait for timeout.","created_at":"2014-12-23T20:04:14Z","updated_at":"2015-02-04T06:51:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"01e95580d938ffbaecc8ab9505f008846e48588e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/3779/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/3779/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments/{number}","comments_url":"https://api.github.com/repos/apache/spark/issues/3779/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/6b13824badb6f47b102accd93742e7ce5b36364b","head":{"label":"davies:local_streaming","ref":"local_streaming","sha":"6b13824badb6f47b102accd93742e7ce5b36364b","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"repo":{"id":21724875,"name":"spark","full_name":"davies/spark","owner":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davies/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/davies/spark","forks_url":"https://api.github.com/repos/davies/spark/forks","keys_url":"https://api.github.com/repos/davies/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davies/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davies/spark/teams","hooks_url":"https://api.github.com/repos/davies/spark/hooks","issue_events_url":"https://api.github.com/repos/davies/spark/issues/events{/number}","events_url":"https://api.github.com/repos/davies/spark/events","assignees_url":"https://api.github.com/repos/davies/spark/assignees{/user}","branches_url":"https://api.github.com/repos/davies/spark/branches{/branch}","tags_url":"https://api.github.com/repos/davies/spark/tags","blobs_url":"https://api.github.com/repos/davies/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davies/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davies/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/davies/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davies/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/davies/spark/languages","stargazers_url":"https://api.github.com/repos/davies/spark/stargazers","contributors_url":"https://api.github.com/repos/davies/spark/contributors","subscribers_url":"https://api.github.com/repos/davies/spark/subscribers","subscription_url":"https://api.github.com/repos/davies/spark/subscription","commits_url":"https://api.github.com/repos/davies/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/davies/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/davies/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/davies/spark/issues/comments/{number}","contents_url":"https://api.github.com/repos/davies/spark/contents/{+path}","compare_url":"https://api.github.com/repos/davies/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davies/spark/merges","archive_url":"https://api.github.com/repos/davies/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davies/spark/downloads","issues_url":"https://api.github.com/repos/davies/spark/issues{/number}","pulls_url":"https://api.github.com/repos/davies/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/davies/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/davies/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davies/spark/labels{/name}","releases_url":"https://api.github.com/repos/davies/spark/releases{/id}","created_at":"2014-07-11T06:39:41Z","updated_at":"2014-12-29T19:21:03Z","pushed_at":"2015-02-04T06:38:38Z","git_url":"git://github.com/davies/spark.git","ssh_url":"git@github.com:davies/spark.git","clone_url":"https://github.com/davies/spark.git","svn_url":"https://github.com/davies/spark","homepage":null,"size":90977,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"c306555f491e45ef870f58938af397f9ec5f166a","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-04T03:57:46Z","pushed_at":"2015-02-04T01:03:10Z","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":1198338,"stargazers_count":2758,"watchers_count":2758,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2424,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":298,"forks":2424,"open_issues":298,"watchers":2758,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/3779"},"html":{"href":"https://github.com/apache/spark/pull/3779"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/3779"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/3779/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/3779/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/3779/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/6b13824badb6f47b102accd93742e7ce5b36364b"}}}}