Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonHxy committed Sep 27, 2022
1 parent 5481896 commit 36ee4d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.bookkeeper.mledger;

import org.apache.bookkeeper.client.BKException;
import org.apache.bookkeeper.common.annotation.InterfaceAudience;
import org.apache.bookkeeper.common.annotation.InterfaceStability;

Expand Down Expand Up @@ -152,8 +153,17 @@ public NonRecoverableLedgerException(String msg, Integer bkErrorCode) {
this.bkErrorCode = bkErrorCode;
}

public Integer getBkErrorCode() {
return bkErrorCode;
public boolean isLedgerNotExistException() {
if (bkErrorCode == null) {
return true;
}
switch (bkErrorCode) {
case BKException.Code.NoSuchLedgerExistsException:
case BKException.Code.NoSuchLedgerExistsOnMetadataServerException:
return true;
default:
return false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.LongAdder;
import org.apache.bookkeeper.client.BKException;
import org.apache.bookkeeper.mledger.AsyncCallbacks.FindEntryCallback;
import org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback;
import org.apache.bookkeeper.mledger.ManagedCursor;
Expand Down Expand Up @@ -192,7 +191,7 @@ public void findEntryFailed(ManagedLedgerException exception, Optional<Position>
&& (exception instanceof NonRecoverableLedgerException)) {
log.warn("[{}][{}] read failed from ledger at position:{} : {}", topicName, subName, failedReadPosition,
exception.getMessage());
if (isLedgerNotExistException(((NonRecoverableLedgerException) exception).getBkErrorCode())) {
if ((((NonRecoverableLedgerException) exception).isLedgerNotExistException())) {
try {
long failedLedgerId = failedReadPosition.get().getLedgerId();
Position lastPositionInLedger = PositionImpl.get(failedLedgerId,
Expand All @@ -212,18 +211,4 @@ public void findEntryFailed(ManagedLedgerException exception, Optional<Position>
expirationCheckInProgress = FALSE;
updateRates();
}

private boolean isLedgerNotExistException(Integer bkErrorCode) {
if (bkErrorCode == null) {
return true;
}
switch (bkErrorCode) {
case BKException.Code.NoSuchLedgerExistsException:
case BKException.Code.NoSuchLedgerExistsOnMetadataServerException:
return true;

default:
return false;
}
}
}

0 comments on commit 36ee4d7

Please sign in to comment.