mattisonchao commented on code in PR #19502:
URL: https://github.com/apache/pulsar/pull/19502#discussion_r1104736757


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherSingleActiveConsumer.java:
##########
@@ -136,6 +139,24 @@ protected boolean pickAndScheduleActiveConsumer() {
         }
     }
 
+    private int peekConsumerIndexFromHashRing(NavigableMap<Integer, Integer> 
hashRing) {
+        int hash = Murmur3Hash32.getInstance().makeHash(topicName);
+        Map.Entry<Integer, Integer> ceilingEntry = hashRing.ceilingEntry(hash);
+        return ceilingEntry != null ? ceilingEntry.getValue() : 
hashRing.firstEntry().getValue();
+    }
+
+    private NavigableMap<Integer, Integer> makeHashRing(int consumerSize) {
+        NavigableMap<Integer, Integer> hashRing = new TreeMap<>();
+        for (int i = 0; i < consumerSize; i++) {
+            for (int j = 0; j < CONSUMER_CONSISTENT_HASH_REPLICAS; j++) {
+                String key = consumers.get(i).consumerName() + j;

Review Comment:
   We need to look at or do some testing to verify if there is more impact in 
bad conditions (many failover consumers). Maybe it's not a critical problem in 
the real use case.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractDispatcherSingleActiveConsumer.java:
##########
@@ -136,6 +139,24 @@ protected boolean pickAndScheduleActiveConsumer() {
         }
     }
 
+    private int peekConsumerIndexFromHashRing(NavigableMap<Integer, Integer> 
hashRing) {
+        int hash = Murmur3Hash32.getInstance().makeHash(topicName);
+        Map.Entry<Integer, Integer> ceilingEntry = hashRing.ceilingEntry(hash);
+        return ceilingEntry != null ? ceilingEntry.getValue() : 
hashRing.firstEntry().getValue();
+    }
+
+    private NavigableMap<Integer, Integer> makeHashRing(int consumerSize) {
+        NavigableMap<Integer, Integer> hashRing = new TreeMap<>();
+        for (int i = 0; i < consumerSize; i++) {
+            for (int j = 0; j < CONSUMER_CONSISTENT_HASH_REPLICAS; j++) {
+                String key = consumers.get(i).consumerName() + j;

Review Comment:
   I think we need to look at or do some testing to verify if there is more 
impact in bad conditions (many failover consumers). Maybe it's not a critical 
problem in the real use case.



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

Reply via email to