Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
onebox-li committed Nov 13, 2023
1 parent ec1e443 commit 71302cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class WorkerInfo(
var endpoint: RpcEndpointRef = null
// Cache the hash code for WorkerInfo
private var hash = 0
private var isZeroHash = false

def this(host: String, rpcPort: Int, pushPort: Int, fetchPort: Int, replicatePort: Int) {
this(
Expand Down Expand Up @@ -235,14 +236,18 @@ class WorkerInfo(

override def hashCode(): Int = {
var h = hash
if (h == 0) {
val state = Seq(host, rpcPort, pushPort, fetchPort, replicatePort)
if (h == 0 || isZeroHash) {
val state = Array(host, rpcPort, pushPort, fetchPort, replicatePort)
var i = 0
while (i < state.size) {
while (i < state.length) {
h = 31 * h + state(i).hashCode()
i = i + 1
}
hash = h
if (h == 0) {
isZeroHash = true
} else {
hash = h
}
}
h
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import org.apache.celeborn.benchmark.{Benchmark, BenchmarkBase}
* ComputeIfAbsent benchmark.
* To run this benchmark:
* {{{
* 1. build/sbt "common/test:runMain <this class>"
* 1. build/sbt "celeborn-common/test:runMain <this class>"
* 2. generate result:
* CELEBORN_GENERATE_BENCHMARK_FILES=1 build/sbt "common/test:runMain <this class>"
* CELEBORN_GENERATE_BENCHMARK_FILES=1 build/sbt "celeborn-common/test:runMain <this class>"
* Results will be written to "benchmarks/ComputeIfAbsentBenchmark-results.txt".
* }}}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ class WorkerInfoSuite extends CelebornFunSuite {

test("Test WorkerInfo hashcode") {
val host = generateRandomIPv4Address
val rpcPort = Random.nextInt(65535)
val pushPort = Random.nextInt(65535)
val fetchPort = Random.nextInt(65535)
val replicatePort = Random.nextInt(65535)
val rpcPort = Random.nextInt(65536)
val pushPort = Random.nextInt(65536)
val fetchPort = Random.nextInt(65536)
val replicatePort = Random.nextInt(65536)
val workerInfo = new WorkerInfo(host, rpcPort, pushPort, fetchPort, replicatePort)

// origin hashCode() logic
Expand Down

0 comments on commit 71302cb

Please sign in to comment.