Skip to content

Conversation

@hellostreaming
Copy link
Contributor

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.


try (Reader<byte[]> reader = pulsarClient.newReader().topic(topic)
.startMessageId(MessageId.earliest).create()) {
assertTrue(reader.hasMessageAvailable());
Copy link
Contributor

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().

@Override
public Position getLastConfirmedEntry() {
return lastConfirmedEntry;
PositionImpl lastMessagePosition = lastConfirmedEntry;
Copy link
Contributor

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().

Copy link
Contributor

@ivankelly ivankelly left a comment

Choose a reason for hiding this comment

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

lgtm +1

@sijie sijie merged commit 2de50a7 into apache:master 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants