geniusjoe opened a new pull request, #4731:
URL: https://github.com/apache/bookkeeper/pull/4731

   Fix #2422
   
   Related PR: #2457
   
   ### Motivation
   
   The `SyncLedgerIterator.hasNext()` method in `BookKeeper.java` has a logic 
bug that causes it to stop iterating prematurely when ledgers span across 
multiple ZooKeeper ranges.
   
   ZooKeeper stores ledgers in a hierarchical tree structure (e.g. 
`/ledgers/00/0000/...`). Each range (znode) holds at most 10,000 leaf-level 
ledger IDs.
   The 10,000 limit is determined by the 4-digit last level (0000-9999) as 
defined in `LegacyHierarchicalLedgerManager` (2-4-4 split) and 
`LongHierarchicalLedgerManager` (3-4-4-4-4 split). When the number of ledgers 
exceeds 10,000, they are distributed across multiple ranges.
   
   The original `hasNext()` implementation had the following logic:
   ```Java
   @Override
   public boolean hasNext() throws IOException {
       parent.checkClosed();
       if (currentRange != null) {
           if (currentRange.hasNext()) {
               return true;
           }
       } else if (iterator.hasNext()) {
           return true;
       }
       return false;
   }
   ```
   When `currentRange` is non-null but exhausted (no more elements), it falls 
through to `return false` **without** checking `iterator.hasNext()` for more 
ranges.
   
   
   ### Changes
   
   1. Fix `SyncLedgerIterator.hasNext()` in `BookKeeper.java`:
   Simplified the conditional logic to properly fall through to 
`iterator.hasNext()` when the current range is exhausted
   2. Add `testListLedgersLargeScale()` test in `LedgerMetadataTest.java`
   Added a new test case with `numOfLedgers = 10010` (> 10,000 per-range limit) 
to verify cross-range iteration works correctly.
   
   
   
     


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