merlimat commented on code in PR #17264:
URL: https://github.com/apache/pulsar/pull/17264#discussion_r959005384


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -553,6 +505,66 @@ protected void recoverFromLedger(final ManagedCursorInfo 
info, final VoidCallbac
         }
     }
 
+    private void recoverCursorByLedgerEntry(long entryId, VoidCallback 
callback, ManagedCursorInfo info,
+                                            LedgerHandle 
recoveredFromCursorLedger){
+        recoveredFromCursorLedger.asyncReadEntries(entryId, entryId, (rc1, 
lh1, seq, ctx1) -> {
+            if (log.isDebugEnabled()) {
+                log.debug("[{}} readComplete rc={} entryId={}", 
ledger.getName(), rc1, lh1.getLastAddConfirmed());
+            }
+            boolean tryPreviousEntry = Code.NoSuchEntryException == rc1 && 
entryId > 0;
+            if (tryPreviousEntry) {
+                recoverCursorByLedgerEntry(entryId - 1, callback, info, 
recoveredFromCursorLedger);

Review Comment:
   If all the entries are not available, this might take a significant amount 
of time, since we're trying each and every entry. 
   
   Even if it's not perfect, it would be better to try a binary-search approach 
to find the highest entry that is readable.



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