pjfanning commented on PR #3270: URL: https://github.com/apache/pekko/pull/3270#issuecomment-4854423168
Problem Analysis The test is failing at line 84: Code Actor[pekko://[email protected]:252525/system/fake/regionA] did not equal Actor[pekko://[email protected]:252525/system/fake/regionB] This indicates the consistent hashing is returning regionB when the test expects regionC for shard "0". Root Cause Looking at the test setup in ConsistentHashingShardAllocationStrategySpec: Scala val memberA = newUpMember("127.0.0.1") val memberB = newUpMember("127.0.0.2") val memberC = newUpMember("127.0.0.3") val regionA = newFakeRegion("regionA", memberA) val regionB = newFakeRegion("regionB", memberB) val regionC = newFakeRegion("regionC", memberC) private def strategy(rebalanceLimit: Int = 0) = new ConsistentHashingShardAllocationStrategy(rebalanceLimit) { override protected def clusterState: CurrentClusterState = CurrentClusterState(SortedSet(memberA, memberB, memberC)) ... } "allocate to regions" in { val allocationStrategy = strategy() val allocations = emptyAllocationsABC allocationStrategy.allocateShard(regionA, "0", allocations).futureValue should ===(regionC) The issue is in how the consistent hash is computed. In ConsistentHashingShardAllocationStrategy.scala: Scala private def nodesForRegions(...): Vector[Address] = { currentShardAllocations.keysIterator.map(nodeForRegion).toVector } private def updateHashing(nodes: Vector[Address]): Unit = { val sortedNodes = nodes.sorted // ← This is the issue ... consistentHashing = ConsistentHash(sortedNodes, virtualNodesFactor) } The problem is that nodes.sorted returns the nodes in an unpredictable order when passed to the consistent hash, and it depends on the Address ordering. The test expectations were written based on specific hash behavior that isn't guaranteed by the current implementation. Solution The ConsistentHash should be initialized with nodes in a deterministic order. The nodes should be sorted by their Address in a consistent way. Looking at the code, it uses Address.addressOrdering, but the sorted call without an explicit ordering may not be using it correctly. The fix is to ensure the nodes are sorted using the same ordering consistently: Scala private def updateHashing(nodes: Vector[Address]): Unit = { val sortedNodes = nodes.sorted(Address.addressOrdering) // Explicit ordering if (sortedNodes != hashedByNodes) { ... However, there may be a deeper issue: the test expectations themselves may need to be adjusted to match the actual consistent hash output for these node IPs and shard IDs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
