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

Conversation

lordcheng10
Copy link
Contributor

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)

@lordcheng10 lordcheng10 changed the title Skip numOfEntriesToRead entries instead of skipping a ledger [improve][broker]Skip numOfEntriesToRead entries instead of skipping a ledger Sep 20, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 20, 2022
@lordcheng10 lordcheng10 force-pushed the only_skip_not_exist_entrys branch from 425205e to 4a4f0a5 Compare September 21, 2022 14:12
PositionImpl skippedPosition;
try {
skippedPosition = getValidPositionInternal(position, skippedEntryNum);
} catch (NullPointerException e) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK , I will fix

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! PTAL,thanks! @eolivelli

while (!isValidPosition(toPosition)) {
Long nextLedgerId = ledgers.ceilingKey(toPosition.getLedgerId() + 1);
if (nextLedgerId == null) {
throw new NullPointerException();
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will fix

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! PTAL,thanks! @eolivelli

// 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);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK , I will fixed!

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

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! PTAL,thanks! @eolivelli

@lordcheng10
Copy link
Contributor Author

@codelipenghui @eolivelli @Jason918 @JipeiWang PTAL,thanks!

@lordcheng10
Copy link
Contributor Author

CI all passed: lordcheng10#15

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Lgtm

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10 lordcheng10 force-pushed the only_skip_not_exist_entrys branch from 6004b0e to c1b1e5d Compare October 4, 2022 01:42
@lordcheng10 lordcheng10 requested a review from Jason918 October 4, 2022 01:42

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

@lordcheng10 lordcheng10 requested a review from Jason918 October 5, 2022 09:09
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

Copy link
Contributor

@Jason918 Jason918 left a comment

Choose a reason for hiding this comment

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

Great work!

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@Jason918 Jason918 merged commit 08f5766 into apache:master Oct 8, 2022
@Technoboy- Technoboy- added this to the 2.12.0 milestone Oct 10, 2022
@Technoboy- Technoboy- added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants