-
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
Issue #1517: make getLastConfirmedEntry in ManagedLedgerImpl return real LAC #1550
Conversation
|
||
try (Reader<byte[]> reader = pulsarClient.newReader().topic(topic) | ||
.startMessageId(MessageId.earliest).create()) { | ||
assertTrue(reader.hasMessageAvailable()); |
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.
Should assert that the returned id matches the id returned from send().
@@ -2222,7 +2222,19 @@ public int getPendingAddEntriesCount() { | |||
|
|||
@Override | |||
public Position getLastConfirmedEntry() { | |||
return lastConfirmedEntry; | |||
PositionImpl lastMessagePosition = lastConfirmedEntry; |
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.
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().
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 +1
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.
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.