BewareMyPower commented on issue #24497:
URL: https://github.com/apache/pulsar/issues/24497#issuecomment-3068611934

   The issue of partition 23 can be simulated by the following test:
   
   The following test can simulate the case of partition 23 that 
`readEntriesComplete` threw an exception.
   
   ```java
       @Test
       public void test() throws Exception {
           ManagedLedgerConfig config = new ManagedLedgerConfig();
           config.setMaximumRolloverTime(1, TimeUnit.SECONDS);
           final var ml = factory.open("test", config);
           final var cursor = ml.openCursor("dedup", InitialPosition.Earliest);
           for (int i = 0; i < 338; i++) {
               ml.addEntry(("msg-0-" + i).getBytes());
           }
           ml.rollCurrentLedgerIfFull();
           Thread.sleep(1000);
           for (int i = 0; i < 3; i++) {
               ml.addEntry(("msg-1-" + i).getBytes());
           }
   
           final var firstEntries = cursor.readEntries(299);
           cursor.markDelete(firstEntries.get(firstEntries.size() - 
1).getPosition());
           firstEntries.forEach(Entry::release);
   
           ml.close();
   
           final var ml2 = factory.open("test", config);
           final var cursor2 = ml2.openCursor("dedup", 
InitialPosition.Earliest);
           cursor2.setAlwaysInactive();
   
           final var future = new CompletableFuture<List<Entry>>();
           cursor2.asyncReadEntries(100, new ReadEntriesCallback() {
               @Override
               public void readEntriesComplete(List<Entry> entries, Object ctx) 
{
                   if (entries.size() > 1) {
                       throw new RuntimeException("fail");
                   }
                   future.complete(entries);
               }
   
               @Override
               public void readEntriesFailed(ManagedLedgerException exception, 
Object ctx) {
                   future.completeExceptionally(exception);
               }
           }, null, PositionFactory.LATEST);
           try {
               future.get(1, TimeUnit.SECONDS);
               fail();
           } catch (TimeoutException e) {
               System.out.println("Expected timeout");
           }
       }
   ```
   
   
https://github.com/apache/pulsar/blob/a40ac3c30e3202ccf992e84be481f6ece588ac62/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java#L179-L184
   
   From the heap dump, line 179 must have been executed because 
`pendingReadOps` is 0. There could be a case that line 183 threw an exception. 
In this case, `OpReadEntry#recycle` will be skipped, which means there must be 
an `OpReadEntry` object whose `cursor` is not a non-durable cursor and 
`nextReadPosition` is `861217:3` in the heap dump. However, I checked all 
`OpReadEntry` objects from the heap dump and didn't find such an `OpReadEntry`, 
which means it's not the case like the test above.
   
   P.S. `OpAddEntry` objects from the heap dump:
   - 319: recycled
   - 16: cursor is a `NonDurableCursorImpl`
   - 24: `nextReadPosition`'s ledger id is in the range from 861275 to 861414


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