Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion core/src/main/scala/org/apache/spark/rpc/RpcAddress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import org.apache.spark.util.Utils
/**
* Address for an RPC environment, with hostname and port.
*/
private[spark] case class RpcAddress(host: String, port: Int) {
private[spark] case class RpcAddress(_host: String, port: Int) {

def host: String = Utils.addBracketsIfNeeded(_host)

def hostPort: String = host + ":" + port

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ private[spark] object Utils extends Logging {
addBracketsIfNeeded(customHostname.getOrElse(InetAddresses.toUriString(localIpAddress)))
}

private def addBracketsIfNeeded(addr: String): String = {
private[spark] def addBracketsIfNeeded(addr: String): String = {
if (addr.contains(":") && !addr.contains("[")) {
"[" + addr + "]"
} else {
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/scala/org/apache/spark/rpc/RpcAddressSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ class RpcAddressSuite extends SparkFunSuite {
val address = RpcAddress("1.2.3.4", 1234)
assert(address.toSparkURL == "spark://1.2.3.4:1234")
}

test("SPARK-39468: IPv6 hostPort") {
val address = RpcAddress("::1", 1234)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main use case of this PR.

assert(address.host == "[::1]")
assert(address.port == 1234)
assert(address.hostPort == "[::1]:1234")
}

test("SPARK-39468: IPv6 fromSparkURL") {
val address = RpcAddress.fromSparkURL("spark://[::1]:1234")
assert(address.host == "[::1]")
assert(address.port == 1234)
}

test("SPARK-39468: IPv6 toSparkURL") {
val address = RpcAddress("::1", 1234)
assert(address.toSparkURL == "spark://[::1]:1234")
}
}