Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ private[spark] object TaskLocation {

/**
* Create a TaskLocation from a string returned by getPreferredLocations.
* These strings have the form [hostname] or hdfs_cache_[hostname], depending on whether the
* location is cached.
* These strings have the form executor_[hostname]_[executorid], [hostname], or
* hdfs_cache_[hostname], depending on whether the location is cached.
*/
def apply(str: String): TaskLocation = {
val hstr = str.stripPrefix(inMemoryLocationTag)
if (hstr.equals(str)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to your change, but this method could be further clarified, like by just checking upfront whether the string starts with inMemoryLocationTag and returning that case straight away. Not required here. The logic looks sound now that the comments are updated.

if (str.startsWith(executorLocationTag)) {
val splits = str.split("_")
if (splits.length != 3) {
throw new IllegalArgumentException("Illegal executor location format: " + str)
}
new ExecutorCacheTaskLocation(splits(1), splits(2))
val hostAndExecutorId = str.stripPrefix(executorLocationTag)
val splits = hostAndExecutorId.split("_", 2)
require(splits.length == 2, "Illegal executor location format: " + str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use string interpolation here but not worth changing if that's the only thing left

val Array(host, executorId) = splits
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's usually better to just do splits(0) and splits(1) rather than using pattern matching here.

new ExecutorCacheTaskLocation(host, executorId)
} else {
new HostTaskLocation(str)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ class TaskSetManagerSuite extends SparkFunSuite with LocalSparkContext with Logg
assert(TaskLocation("host1") === HostTaskLocation("host1"))
assert(TaskLocation("hdfs_cache_host1") === HDFSCacheTaskLocation("host1"))
assert(TaskLocation("executor_host1_3") === ExecutorCacheTaskLocation("host1", "3"))
assert(TaskLocation("executor_some.host1_executor_task_3") ===
ExecutorCacheTaskLocation("some.host1", "executor_task_3"))
}

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