You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/08/10 14:40:36 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #11621: fix getPreviousPosition npe

codelipenghui commented on a change in pull request #11621:
URL: https://github.com/apache/pulsar/pull/11621#discussion_r686085678



##########
File path: managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java
##########
@@ -3202,8 +3203,9 @@ public PositionImpl getPreviousPosition(PositionImpl position) {
             return PositionImpl.get(position.getLedgerId(), position.getEntryId() - 1);
         }
 
+        final NavigableMap<Long, LedgerInfo> ledgersCopied = new TreeMap<>(ledgers);
         // The previous position will be the last position of an earlier ledgers
-        NavigableMap<Long, LedgerInfo> headMap = ledgers.headMap(position.getLedgerId(), false);
+        NavigableMap<Long, LedgerInfo> headMap = ledgersCopied.headMap(position.getLedgerId(), false);

Review comment:
       We may have many ledgers if users keep long-term data, copy here might be expensive here, as you can see we have many places that uses the `getPreviousPosition` method, can we catch the NPE and retry the execution?




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org