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
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) {

val host: String = Utils.addBracketsIfNeeded(_host)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be a lazy val instead of val ?
We end up almost doubling the size of the serialized instance of this object otherwise.

Copy link
Member Author

@dongjoon-hyun dongjoon-hyun Jun 15, 2022

Choose a reason for hiding this comment

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

Ya, of course, we can. Thank you for review, @mridulm .

Actually, at the first commit, I used def host first to save the size . Later I switched to val in the second commit.

If the memory consumption of RpcAddress instances matter, we can revert back def host instead of lazy val.

Among three options, which one do you prefer, @mridulm and @cloud-fan ?

  1. def host (Initial commit)
  2. lazy val host (New alternative)
  3. val host (AS-IS)

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer lazy val - it keeps the serialized size the same, while making the runtime cost of accessing host is almost the same as before (which is increased by def host).

Copy link
Member Author

Choose a reason for hiding this comment

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


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")
}
}