shubhamsrkdev commented on code in PR #15585:
URL: https://github.com/apache/lucene/pull/15585#discussion_r2721591904


##########
lucene/core/src/java/org/apache/lucene/store/MemorySegmentIndexInput.java:
##########
@@ -74,12 +75,28 @@ public static MemorySegmentIndexInput newInstance(
       boolean confined,
       Function<IOContext, ReadAdvice> toReadAdvice) {
     assert 
Arrays.stream(segments).map(MemorySegment::scope).allMatch(arena.scope()::equals);
+    AtomicInteger sharedPrefetchCounter = new AtomicInteger();

Review Comment:
   >Is this creating one AtomicInteger per actually originally opened files? 
And then each clone shares that same original AtomicInteger?
   
   Yes!
   
   >Hmm what happens when we overflow the int? What does incrementAndGet do 
then? Silently overflow/wraparound to negative?
   
   It does wraparound after `Integer.MAX_VALUE` to `Integer.MIN_VALUE` and 
subsequent negative values. But it would just cause an extra prefetch because 
of `isZeroOrPowerOfTwo` ?`isZeroOrPowerOfTwo(Integer.MIN_VALUE)` would give 
true but subsequent increments would just give false as expected. For example:
   
   ```
   import java.util.concurrent.atomic.AtomicInteger;
   
    class Main {
       public static void main(String[] args) {
           AtomicInteger counter = new AtomicInteger(Integer.MAX_VALUE);
   
           while(counter.incrementAndGet() < 0)
           {
               System.out.println(isZeroOrPowerOfTwo(counter.get()));
           }
       }
       
        
       public static boolean isZeroOrPowerOfTwo(int x) {
       return (x & (x - 1)) == 0;
     }
   }
   ```
   
   This would give:
   
   ```
   true
   false
   false
   false
   false
   false
   false
   false
   false
   false
   false
   .
   .
   .
   .
   .
   .
   .
   .
   .
   ```



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