shibd commented on code in PR #24730:
URL: https://github.com/apache/pulsar/pull/24730#discussion_r2343284025


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java:
##########
@@ -129,10 +124,25 @@ private synchronized CompletableFuture<Void> 
validateKeySharedMeta(Consumer cons
             return FutureUtil.failedFuture(new 
BrokerServiceException.ConsumerAssignException(
                     "Ranges for KeyShared policy must not be empty."));
         }
-        for (IntRange intRange : ranges) {
-            if (intRange.getStart() > intRange.getEnd()) {
+        List<IntRange> sortedRanges = new ArrayList<>(ranges);
+        sortedRanges.sort(Comparator.comparingInt(IntRange::getStart));
+        for (int i = 0; i < sortedRanges.size(); i++) {
+            IntRange currentRange = sortedRanges.get(i);
+            // 1. Validate: check if start > end for the current range
+            if (currentRange.getStart() > currentRange.getEnd()) {
                 return FutureUtil.failedFuture(
-                        new 
BrokerServiceException.ConsumerAssignException("Fixed hash range start > end"));
+                        new 
BrokerServiceException.ConsumerAssignException("Fixed hash range start > end 
for range: "
+                                + "[" + currentRange.getStart() + "," + 
currentRange.getEnd() + "]"));
+            }
+            // 2. Validate: check for overlaps with the next range in the 
sorted list
+            if (i < sortedRanges.size() - 1) {
+                IntRange nextRange = sortedRanges.get(i + 1);

Review Comment:
   > When i == 0 and sortedRanges.size == 1
   
   This case will not go this line.
   
   ```
   if (i < sortedRanges.size() - 1) {
   
   i = 0
   sortedRanges.size - 1 = 0
   ```
   



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