Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public static class ManagedLedgerNotFoundException extends ManagedLedgerExceptio
public ManagedLedgerNotFoundException(Exception e) {
super(e);
}

public ManagedLedgerNotFoundException(String message) {
super(message);
}
}

public static class ManagedLedgerTerminatedException extends ManagedLedgerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1790,8 +1790,13 @@ void updateCursor(ManagedCursorImpl cursor, PositionImpl newPosition) {
}
}

PositionImpl startReadOperationOnLedger(PositionImpl position) {
long ledgerId = ledgers.ceilingKey(position.getLedgerId());
PositionImpl startReadOperationOnLedger(PositionImpl position, OpReadEntry opReadEntry) {
Long ledgerId = ledgers.ceilingKey(position.getLedgerId());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change maybe not fix npe, it will cause new npe problem.
see this pr line_1800. if ledgerId is null, unbox will cause npe. And opReadEntry callback didn't put ctx, the callback process need use it, npe again.

if (null == ledgerId) {
opReadEntry.readEntriesFailed(new ManagedLedgerException.NoMoreEntriesToReadException("The ceilingKey(K key) method is used to return the " +
"least key greater than or equal to the given key, or null if there is no such key"), null);
}

if (ledgerId != position.getLedgerId()) {
// The ledger pointed by this position does not exist anymore. It was deleted because it was empty. We need
// to skip on the next available ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OpReadEntry implements ReadEntriesCallback {
public static OpReadEntry create(ManagedCursorImpl cursor, PositionImpl readPositionRef, int count,
ReadEntriesCallback callback, Object ctx) {
OpReadEntry op = RECYCLER.get();
op.readPosition = cursor.ledger.startReadOperationOnLedger(readPositionRef);
op.readPosition = cursor.ledger.startReadOperationOnLedger(readPositionRef, op);
op.cursor = cursor;
op.count = count;
op.callback = callback;
Expand Down Expand Up @@ -128,12 +128,12 @@ void checkReadCompletion() {
if (entries.size() < count && cursor.hasMoreEntries()) {
// We still have more entries to read from the next ledger, schedule a new async operation
if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) {
cursor.ledger.startReadOperationOnLedger(nextReadPosition);
cursor.ledger.startReadOperationOnLedger(nextReadPosition, OpReadEntry.this);
}

// Schedule next read in a different thread
cursor.ledger.getExecutor().execute(safeRun(() -> {
readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition);
readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition, OpReadEntry.this);
cursor.ledger.asyncReadEntries(OpReadEntry.this);
}));
} else {
Expand Down