Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker]Skip numOfEntriesToRead entries instead of skipping a ledger #17753

Merged
merged 8 commits into from
Oct 8, 2022
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 @@ -3461,19 +3461,19 @@ public Long getNextValidLedger(long ledgerId) {
}

public PositionImpl getNextValidPosition(final PositionImpl position) {
PositionImpl next;
try {
next = getNextValidPositionInternal(position);
} catch (NullPointerException e) {
next = lastConfirmedEntry.getNext();
if (log.isDebugEnabled()) {
log.debug("[{}] Can't find next valid position : {}, fall back to the next position of the last "
+ "position : {}.", position, name, next, e);
return getValidPositionAfterSkippedEntries(position, 1);
}
public PositionImpl getValidPositionAfterSkippedEntries(final PositionImpl position, int skippedEntryNum) {
PositionImpl skippedPosition = position.getPositionAfterEntries(skippedEntryNum);
while (!isValidPosition(skippedPosition)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this same as getNextValidPosition(skippedPostion)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!
use getValidPositionAfterSkippedEntries for getNextValidPosition: @Jason918 PTAL,thanks!
image

Long nextLedgerId = ledgers.ceilingKey(skippedPosition.getLedgerId() + 1);
if (nextLedgerId == null) {
return lastConfirmedEntry.getNext();
}
skippedPosition = PositionImpl.get(nextLedgerId, 0);
}
return next;
return skippedPosition;
}

public PositionImpl getNextValidPositionInternal(final PositionImpl position) {
PositionImpl nextPosition = position.getNext();
while (!isValidPosition(nextPosition)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ 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());
final ManagedLedgerImpl ledger = (ManagedLedgerImpl) cursor.getManagedLedger();
Position nexReadPosition;
if (exception instanceof ManagedLedgerException.LedgerNotExistException) {
// try to find and move to next valid ledger
nexReadPosition = cursor.getNextLedgerPosition(readPosition.getLedgerId());
} else {
// Skip this read operation
nexReadPosition = ledger.getValidPositionAfterSkippedEntries(readPosition, count);
}
// fail callback if it couldn't find next valid ledger
if (nexReadPosition == null) {
callback.readEntriesFailed(exception, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public PositionImpl getNext() {
}
}

/**
* Position after moving entryNum messages,
* if entryNum < 1, then return the current position.
* */
public PositionImpl getPositionAfterEntries(int entryNum) {
if (entryNum < 1) {
return this;
}
if (entryId < 0) {
return PositionImpl.get(ledgerId, entryNum - 1);
} else {
return PositionImpl.get(ledgerId, entryId + entryNum);
}
}

/**
* String representation of virtual cursor - LedgerId:EntryId.
*/
Expand Down