eolivelli commented on code in PR #17753:
URL: https://github.com/apache/pulsar/pull/17753#discussion_r979401626


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImpl.java:
##########
@@ -94,6 +94,14 @@ public PositionImpl getNext() {
         }
     }
 
+    public PositionImpl getPositionAfterEntries(int entryNum) {
+        if (entryId < 0) {

Review Comment:
   This is not correct 



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java:
##########
@@ -100,8 +100,8 @@ public void readEntriesFailed(ManagedLedgerException 
exception, Object ctx) {
         } else if (cursor.config.isAutoSkipNonRecoverableData() && exception 
instanceof NonRecoverableLedgerException) {
             log.warn("[{}][{}] read failed from ledger at position:{} : {}", 
cursor.ledger.getName(), cursor.getName(),
                     readPosition, exception.getMessage());
-            // try to find and move to next valid ledger
-            final Position nexReadPosition = 
cursor.getNextLedgerPosition(readPosition.getLedgerId());
+            // Skip this read operation
+            PositionImpl nexReadPosition = 
cursor.ledger.getValidPositionAfterSkippedEntries(readPosition, count);

Review Comment:
   Please do not access a field, use a getter



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3445,6 +3445,32 @@ public PositionImpl getNextValidPosition(final 
PositionImpl position) {
         return next;
     }
 
+    public PositionImpl getValidPositionAfterSkippedEntries(final PositionImpl 
position, int skippedEntryNum) {
+        PositionImpl skippedPosition;
+        try {
+            skippedPosition = getValidPositionInternal(position, 
skippedEntryNum);
+        } catch (NullPointerException e) {
+            skippedPosition = lastConfirmedEntry.getNext();
+            if (log.isDebugEnabled()) {
+                log.debug("[{}] Can't find valid position : {}, fall back to 
the next position of the last "
+                        + "position : {}.", position, name, skippedPosition, 
e);
+            }
+        }
+        return skippedPosition;
+    }
+
+    public PositionImpl getValidPositionInternal(final PositionImpl position, 
int skippedEntryNum) {
+        PositionImpl toPosition = 
position.getPositionAfterEntries(skippedEntryNum);
+        while (!isValidPosition(toPosition)) {
+            Long nextLedgerId = ledgers.ceilingKey(toPosition.getLedgerId() + 
1);
+            if (nextLedgerId == null) {
+                throw new NullPointerException();

Review Comment:
   Throwing NPE is bad practice.
   Please throw a new checked exception.
   This way we have full control over what we are catching 



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java:
##########
@@ -100,8 +100,8 @@ public void readEntriesFailed(ManagedLedgerException 
exception, Object ctx) {
         } else if (cursor.config.isAutoSkipNonRecoverableData() && exception 
instanceof NonRecoverableLedgerException) {
             log.warn("[{}][{}] read failed from ledger at position:{} : {}", 
cursor.ledger.getName(), cursor.getName(),
                     readPosition, exception.getMessage());
-            // try to find and move to next valid ledger
-            final Position nexReadPosition = 
cursor.getNextLedgerPosition(readPosition.getLedgerId());

Review Comment:
   Why are you dropping 'final' ?



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3445,6 +3445,32 @@ public PositionImpl getNextValidPosition(final 
PositionImpl position) {
         return next;
     }
 
+    public PositionImpl getValidPositionAfterSkippedEntries(final PositionImpl 
position, int skippedEntryNum) {
+        PositionImpl skippedPosition;
+        try {
+            skippedPosition = getValidPositionInternal(position, 
skippedEntryNum);
+        } catch (NullPointerException e) {

Review Comment:
   Catching NPE is always a bad practice in Java 
   
   Please verify the cause of the NPE and add a null check



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