-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][broker]Skip numOfEntriesToRead entries instead of skipping a ledger #17753
Conversation
425205e
to
4a4f0a5
Compare
PositionImpl skippedPosition; | ||
try { | ||
skippedPosition = getValidPositionInternal(position, skippedEntryNum); | ||
} catch (NullPointerException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching NPE is always a bad practice in Java
Please verify the cause of the NPE and add a null check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK , I will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! PTAL,thanks! @eolivelli
while (!isValidPosition(toPosition)) { | ||
Long nextLedgerId = ledgers.ceilingKey(toPosition.getLedgerId() + 1); | ||
if (nextLedgerId == null) { | ||
throw new NullPointerException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing NPE is bad practice.
Please throw a new checked exception.
This way we have full control over what we are catching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! PTAL,thanks! @eolivelli
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java
Show resolved
Hide resolved
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not access a field, use a getter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK , I will fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! PTAL,thanks! @eolivelli
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImpl.java
Show resolved
Hide resolved
@codelipenghui @eolivelli @Jason918 @JipeiWang PTAL,thanks! |
CI all passed: lordcheng10#15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
/pulsarbot run-failure-checks |
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java
Show resolved
Hide resolved
6004b0e
to
c1b1e5d
Compare
|
||
public PositionImpl getValidPositionAfterSkippedEntries(final PositionImpl position, int skippedEntryNum) { | ||
PositionImpl skippedPosition = position.getPositionAfterEntries(skippedEntryNum); | ||
while (!isValidPosition(skippedPosition)) { |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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!
/pulsarbot run-failure-checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
/pulsarbot run-failure-checks |
Motivation
Skip numOfEntriesToRead entries instead of skipping a ledger.
When isAutoSkipNonRecoverableData=true, if a NonRecoverableLedgerException exception occurs when reading data, readPosition will automatically adjust to the next ledger to continue reading, which will result in a lot of existing data that cannot be read.
Modifications
Therefore, the entry skip logic is modified to: only skip numOfEntriesToRead entries instead of skipping a ledger
Documentation
doc-required
(Your PR needs to update docs and you will update later)
doc-not-needed
(Please explain why)
doc
(Your PR contains doc changes)
doc-complete
(Docs have been already added)