Skip to content

Commit 0aed80a

Browse files
committed
Refactored code and added test case.
In response to @srowen and @zsxwing's comments.
1 parent c2f0a2c commit 0aed80a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

core/src/main/scala/org/apache/spark/scheduler/TaskLocation.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,21 @@ private[spark] object TaskLocation {
6464

6565
/**
6666
* Create a TaskLocation from a string returned by getPreferredLocations.
67-
* These strings have the form [executorLocationTag][hostname][executorid], [hostname], or
67+
* These strings have the form executor_[hostname]_[executorid], [hostname], or
6868
* hdfs_cache_[hostname], depending on whether the location is cached.
6969
*/
7070
def apply(str: String): TaskLocation = {
7171
val hstr = str.stripPrefix(inMemoryLocationTag)
7272
if (hstr.equals(str)) {
7373
if (str.startsWith(executorLocationTag)) {
74-
val splits = str.split("_", 3)
75-
if (splits.length != 3) {
74+
val hostAndExecutorId = str.stripPrefix(executorLocationTag)
75+
val splits = hostAndExecutorId.split("_", 2)
76+
if (splits.length != 2) {
7677
throw new IllegalArgumentException("Illegal executor location format: " + str)
7778
}
78-
new ExecutorCacheTaskLocation(splits(1), splits(2))
79+
val host = splits(0)
80+
val executorId = splits(1)
81+
new ExecutorCacheTaskLocation(host, executorId)
7982
} else {
8083
new HostTaskLocation(str)
8184
}

core/src/test/scala/org/apache/spark/scheduler/TaskSetManagerSuite.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ class TaskSetManagerSuite extends SparkFunSuite with LocalSparkContext with Logg
789789
assert(TaskLocation("host1") === HostTaskLocation("host1"))
790790
assert(TaskLocation("hdfs_cache_host1") === HDFSCacheTaskLocation("host1"))
791791
assert(TaskLocation("executor_host1_3") === ExecutorCacheTaskLocation("host1", "3"))
792+
assert(TaskLocation("executor_some.host1_executor_task_3") ===
793+
ExecutorCacheTaskLocation("some.host1", "executor_task_3"))
792794
}
793795

794796
test("Kill other task attempts when one attempt belonging to the same task succeeds") {

0 commit comments

Comments
 (0)