Issue #1517: make getLastConfirmedEntry in ManagedLedgerImpl return real LAC - #1550
Merged
Conversation
hellostreaming
force-pushed
the
issue_1517
branch
from
April 11, 2018 12:47
288806d to
5b78bb2
Compare
ivankelly
reviewed
Apr 11, 2018
|
|
||
| try (Reader<byte[]> reader = pulsarClient.newReader().topic(topic) | ||
| .startMessageId(MessageId.earliest).create()) { | ||
| assertTrue(reader.hasMessageAvailable()); |
Contributor
There was a problem hiding this comment.
Should assert that the returned id matches the id returned from send().
| @Override | ||
| public Position getLastConfirmedEntry() { | ||
| return lastConfirmedEntry; | ||
| PositionImpl lastMessagePosition = lastConfirmedEntry; |
Contributor
There was a problem hiding this comment.
This could be done in initialize(), as once the last ledger has been loaded, you can set lastConfirmedEntry. lastConfirmedEntry only gets set with entry id as -1 in initializeBookKeeper() now. This could be removed if you do it in inititalize().
sijie
approved these changes
Apr 12, 2018
merlimat
approved these changes
Apr 12, 2018
sijie
pushed a commit
that referenced
this pull request
Oct 4, 2018
For a topic with metadata similar to #2673, IllegalArgumentException may occur in the following line: https://github.com/apache/pulsar/blob/b2484d92d5068d4f0699eb9c3d31640cb48f9dd0/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L655 This is the broker log when the exception has occurred: [invalid_range_error.txt](https://github.com/apache/pulsar/files/2442924/invalid_range_error.txt) It is because `readPosition` is ahead of `ledger.getLastPosition().getNext()`, so `ManagedCursorImpl#getNumberOfEntries()` should return 0 as the number of entries to read in that case. I think this issue and #2673 are the result of that `ledger.getLastPosition()` is no longer the real last of the managed ledger because of #1550.
Open
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In ManagedLedgerImpl, getLastConfirmedEntry() uses lastConfirmedEntry, which is set to :-1, when a new new ledger is created (as happens on restart). This will cause reader.hasMessageAvailable working working wrongly.
Modifications
In ManagedLedgerImpl, change getLastConfirmedEntry to bypass empty ledgers, and find last ledger with Message, if possible.
Result
getLastConfirmedEntry working fine. Ut in TopicReaderTest pass.