tjiuming commented on PR #16909:
URL: https://github.com/apache/pulsar/pull/16909#issuecomment-1201983074

   > I also met this problem before. Could you explain why it causes NPE here?
   
   I believe there existing null element in the `entries`, but I don't think it 
caused by multi-threads adding. 
   ```
       private void asyncReadEntry0(ReadHandle lh, PositionImpl position, final 
ReadEntryCallback callback,
               final Object ctx) {
           if (log.isDebugEnabled()) {
               log.debug("[{}] Reading entry ledger {}: {}", ml.getName(), 
lh.getId(), position.getEntryId());
           }
           EntryImpl entry = entries.get(position);
           if (entry != null) {
               EntryImpl cachedEntry = EntryImpl.create(entry);
               entry.release();
               manager.mlFactoryMBean.recordCacheHit(cachedEntry.getLength());
               callback.readEntryComplete(cachedEntry, ctx);
           } else {
               lh.readAsync(position.getEntryId(), 
position.getEntryId()).thenAcceptAsync(
                       ledgerEntries -> {
                           try {
                               Iterator<LedgerEntry> iterator = 
ledgerEntries.iterator();
                               if (iterator.hasNext()) {
                                   LedgerEntry ledgerEntry = iterator.next();
                                   EntryImpl returnEntry = 
RangeEntryCacheManagerImpl.create(ledgerEntry, interceptor);
   
                                   manager.mlFactoryMBean.recordCacheMiss(1, 
returnEntry.getLength());
                                   ml.getMbean().addReadEntriesSample(1, 
returnEntry.getLength());
                                   callback.readEntryComplete(returnEntry, ctx);
                               } else {
                                   // got an empty sequence
                                   callback.readEntryFailed(new 
ManagedLedgerException("Could not read given position"),
                                                            ctx);
                               }
                           } finally {
                               ledgerEntries.close();
                           }
                       }, 
ml.getExecutor().chooseThread(ml.getName())).exceptionally(exception -> {
                           ml.invalidateLedgerHandle(lh);
                           
callback.readEntryFailed(createManagedLedgerException(exception), ctx);
                           return null;
               });
           }
       }
   ```
   `ml.getExecutor().chooseThread(ml.getName())` a ManagedLedger always use the 
same SingleThreadExecutor.


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