Copilot commented on code in PR #62065:
URL: https://github.com/apache/doris/pull/62065#discussion_r3028453268


##########
fe/fe-core/src/main/java/org/apache/doris/qe/JournalObservable.java:
##########
@@ -63,23 +63,20 @@ public void waitOn(Long expectedJournalVersion, int 
timeoutMs) throws DdlExcepti
         }
     }
 
-    // return min pos which is bigger than value
+    // Return the number of elements whose targetJournalVersion <= value.
+    // This is the standard upper_bound pattern: returns the index of the 
first element > value.
     public static int upperBound(Object[] array, int size, Long value) {
         int left = 0;
-        int right = size - 1;
+        int right = size;
         while (left < right) {
             int middle = left + ((right - left) >> 1);
-            if (value >= ((JournalObserver) 
array[middle]).getTargetJournalVersion()) {
+            if (((JournalObserver) array[middle]).getTargetJournalVersion() <= 
value) {
                 left = middle + 1;
             } else {
-                right = middle - 1;
+                right = middle;
             }

Review Comment:
   Inside the loop, the cast and virtual call are embedded directly in the 
condition. Consider assigning `(JournalObserver) array[middle]` (and/or its 
`targetJournalVersion`) to a local variable for slightly clearer code and to 
avoid repeating complex expressions in hot paths.



##########
fe/fe-core/src/main/java/org/apache/doris/qe/JournalObservable.java:
##########
@@ -63,23 +63,20 @@ public void waitOn(Long expectedJournalVersion, int 
timeoutMs) throws DdlExcepti
         }
     }
 
-    // return min pos which is bigger than value
+    // Return the number of elements whose targetJournalVersion <= value.
+    // This is the standard upper_bound pattern: returns the index of the 
first element > value.

Review Comment:
   The updated comment explains the return semantics, but the method still 
relies on important preconditions that aren’t stated: (1) `array[0..size)` must 
be sorted ascending by `targetJournalVersion`, and (2) the first `size` entries 
must be non-null `JournalObserver`s. Adding these assumptions to the 
comment/Javadoc would make the method safer to reuse and easier to reason about.
   ```suggestion
       // Return the number of elements in array[0..size) whose 
targetJournalVersion <= value.
       // This is the standard upper_bound pattern: returns the index of the 
first element > value.
       // Preconditions:
       //   - The first 'size' elements of 'array' are non-null JournalObserver 
instances.
       //   - array[0..size) is sorted in ascending order by 
getTargetJournalVersion().
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/qe/JournalObservable.java:
##########
@@ -63,23 +63,20 @@ public void waitOn(Long expectedJournalVersion, int 
timeoutMs) throws DdlExcepti
         }
     }
 
-    // return min pos which is bigger than value
+    // Return the number of elements whose targetJournalVersion <= value.
+    // This is the standard upper_bound pattern: returns the index of the 
first element > value.
     public static int upperBound(Object[] array, int size, Long value) {

Review Comment:
   The parameter name `value` is ambiguous for this domain (it represents a 
journal version threshold). Renaming it to something like `journalVersion` / 
`targetJournalVersion` would improve readability without affecting the method 
signature for callers.



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