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

Fix incorrect returned last message ID while the lastConfirmedEntry with negative entry ID #12277

Conversation

codelipenghui
Copy link
Contributor

When recovering a ManagedLedger, if the ManagedLedgers does not contain any ledgers,
the ManagedLedger will use the current Ledger ID and -1 to generate the lastConfirmedEntry.
For more details to see:

lastConfirmedEntry = new PositionImpl(lh.getId(), -1);

But for the compacted topic, all the data might be compacted and move to the compacted Ledger,
In this case, the broker will return X:-1 as the last message ID of the topic to the consumer,
the consumer will treat the negative entry ID as no data in this topic,
so hasMoreMessages method will return false, but there is compacted data in the topic.

The fix is as #12161 does to return the last message ID from the compacted Ledger if lastConfirmedEntry of the ManagedLedger with negative entry ID.

Improved the testLastMessageIdForCompactedLedger test to cover the new changes.

… with negative entry ID.

Which recover a ManagedLedger, if the ManagedLedgers does not contain any ledgers,
the ManagedLedger will use the current Ledger ID and -1 to generate the `lastConfirmedEntry`.
For more details to see: https://github.com/apache/pulsar/blob/4bc3c405a565b1c756b9b70ff02a63ea06c32c0d/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L477

But for compacted topic, all the data might be compacted and move to the compacted Ledger,
In this case, the broker will return X:-1 as the last message ID of the topic to the consumer,
the consumer will treat the negative entry ID as no data in this topic,
so hasMoreMessages will return false, but there is compacted data in the topic.

The fix is as apache#12161 does to return the last message ID from the compacted Ledger if `lastConfirmedEntry` of the ManagedLedger with negative entry ID.

Improved the `testLastMessageIdForCompactedLedger` test to cover the new changes.
@codelipenghui codelipenghui self-assigned this Oct 5, 2021
@codelipenghui codelipenghui added this to the 2.9.0 milestone Oct 5, 2021
@codelipenghui codelipenghui added release/2.8.2 doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug labels Oct 5, 2021
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

@merlimat merlimat merged commit 65fb6c6 into apache:master Oct 6, 2021
@codelipenghui codelipenghui deleted the penghui/fix-last-message-id-with-negative-entry-id branch October 6, 2021 03:03
codelipenghui added a commit that referenced this pull request Oct 6, 2021
… with negative entry ID. (#12277)

Which recover a ManagedLedger, if the ManagedLedgers does not contain any ledgers,
the ManagedLedger will use the current Ledger ID and -1 to generate the `lastConfirmedEntry`.
For more details to see: https://github.com/apache/pulsar/blob/4bc3c405a565b1c756b9b70ff02a63ea06c32c0d/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L477

But for compacted topic, all the data might be compacted and move to the compacted Ledger,
In this case, the broker will return X:-1 as the last message ID of the topic to the consumer,
the consumer will treat the negative entry ID as no data in this topic,
so hasMoreMessages will return false, but there is compacted data in the topic.

The fix is as #12161 does to return the last message ID from the compacted Ledger if `lastConfirmedEntry` of the ManagedLedger with negative entry ID.

Improved the `testLastMessageIdForCompactedLedger` test to cover the new changes.

(cherry picked from commit 65fb6c6)
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Oct 6, 2021
@hicolour
Copy link

hicolour commented Oct 7, 2021

g8 job, thank you @codelipenghui

eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Feb 25, 2022
… with negative entry ID. (apache#12277)

Which recover a ManagedLedger, if the ManagedLedgers does not contain any ledgers,
the ManagedLedger will use the current Ledger ID and -1 to generate the `lastConfirmedEntry`.
For more details to see: https://github.com/apache/pulsar/blob/4bc3c405a565b1c756b9b70ff02a63ea06c32c0d/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L477

But for compacted topic, all the data might be compacted and move to the compacted Ledger,
In this case, the broker will return X:-1 as the last message ID of the topic to the consumer,
the consumer will treat the negative entry ID as no data in this topic,
so hasMoreMessages will return false, but there is compacted data in the topic.

The fix is as apache#12161 does to return the last message ID from the compacted Ledger if `lastConfirmedEntry` of the ManagedLedger with negative entry ID.

Improved the `testLastMessageIdForCompactedLedger` test to cover the new changes.

(cherry picked from commit 65fb6c6)
(cherry picked from commit 2e7088d)
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
… with negative entry ID. (apache#12277)

Which recover a ManagedLedger, if the ManagedLedgers does not contain any ledgers,
the ManagedLedger will use the current Ledger ID and -1 to generate the `lastConfirmedEntry`.
For more details to see: https://github.com/apache/pulsar/blob/4bc3c405a565b1c756b9b70ff02a63ea06c32c0d/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L477

But for compacted topic, all the data might be compacted and move to the compacted Ledger,
In this case, the broker will return X:-1 as the last message ID of the topic to the consumer,
the consumer will treat the negative entry ID as no data in this topic,
so hasMoreMessages will return false, but there is compacted data in the topic.

The fix is as apache#12161 does to return the last message ID from the compacted Ledger if `lastConfirmedEntry` of the ManagedLedger with negative entry ID.

Improved the `testLastMessageIdForCompactedLedger` test to cover the new changes.
@codelipenghui codelipenghui restored the penghui/fix-last-message-id-with-negative-entry-id branch May 17, 2022 01:23
@codelipenghui codelipenghui deleted the penghui/fix-last-message-id-with-negative-entry-id branch May 17, 2022 01:29
@Technoboy- Technoboy- added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/compaction cherry-picked/branch-2.7 Archived: 2.7 is end of life cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.7.5 release/2.8.2 release/2.9.0 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants