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 2022/08/30 23:09:05 UTC

[GitHub] [pulsar] merlimat commented on a diff in pull request #17264: [improve][broker]Recover as much cursor data as possible, even if entry is invalid

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

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