Jackie-Jiang commented on code in PR #19915:
URL: https://github.com/apache/pinot/pull/19915#discussion_r4532649965


##########
pinot-broker/src/test/java/org/apache/pinot/broker/routing/instanceselector/SegmentGroupsBuilderHashStrategyTest.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.broker.routing.instanceselector;
+
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+
+public class SegmentGroupsBuilderHashStrategyTest {
+
+  @Test
+  public void testEqualSetsWithDifferentIterationOrders() {
+    Set<String> first = new LinkedHashSet<>(List.of("server1", "server2", 
"server3"));
+    Set<String> reordered = new LinkedHashSet<>(List.of("server3", "server1", 
"server2"));
+
+    assertEquals(first, reordered);
+    assertEquals(SegmentGroupsBuilder.INSTANCE_SET_STRATEGY.hashCode(first),
+        SegmentGroupsBuilder.INSTANCE_SET_STRATEGY.hashCode(reordered));
+
+    Map<Set<String>, String> map =
+        new 
Object2ObjectOpenCustomHashMap<>(SegmentGroupsBuilder.INSTANCE_SET_STRATEGY);
+
+    map.put(first, "unavailable");
+    assertEquals(map.get(reordered), "unavailable");
+  }
+
+  @Test
+  public void testReducedCollisionsForDifferentInstanceSets() {
+    Set<String> first = Set.of("a", "d");

Review Comment:
   Consider restoring the representative hash-distribution regression using the 
numeric server-name combinations from #19852. This test proves that one pair of 
sets no longer collides, but the original issue involved many distinct groups 
collapsing into a small number of hashes. The earlier 100,000-combination test 
is absent from the current head, although the PR description still claims that 
coverage. The existing `ContentHasher` test exercises a different hash 
implementation. A distribution test for `INSTANCE_SET_STRATEGY` would preserve 
coverage of the actual performance failure as this algorithm evolves.



##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/SegmentGroupsBuilder.java:
##########
@@ -227,7 +258,8 @@ SegmentGroups build() {
   /// Returns the instances unavailable for any old segment, keyed by the 
instances in the ideal state of the segment:
   /// the instances that are not online for routing in both the ideal state 
and the external view.
   private Map<Set<String>, Set<String>> 
computeUnavailableInstancesMap(List<InstanceStateMaps> instanceStateMapsList) {
-    Map<Set<String>, Set<String>> unavailableInstancesMap = new HashMap<>();
+    Map<Set<String>, Set<String>> unavailableInstancesMap =
+        new Object2ObjectOpenCustomHashMap<>(INSTANCE_SET_STRATEGY);

Review Comment:
   Minor performance suggestion: declare this local variable as 
`Object2ObjectMap<Set<String>, Set<String>>` or 
`Object2ObjectOpenCustomHashMap<Set<String>, Set<String>>`. With the current 
`Map` type, the lambda at `computeIfAbsent` selects Java's `Function` overload, 
whose default implementation calls `get` and then `put` on a miss. That hashes 
and probes twice for each newly inserted instance set. Fastutil's 
`Object2ObjectFunction` overload uses a single `find`, avoiding the second 
traversal of all instance names and the duplicate probe. The method's return 
type can remain `Map`.



-- 
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]

Reply via email to