codelipenghui opened a new pull request #14449:
URL: https://github.com/apache/pulsar/pull/14449
Fix can't read the latest message of the compacted topic
### Motivation
If the reader enabled read compacted and all the data of topic has been
compacted
to the compacted ledger, the original topic does not have any data. In this
case,
the reader is not able to read the latest message of the compacted topic.
```java
Reader<byte[]> reader = pulsarClient.newReader()
.topic(topic)
.startMessageId(MessageId.latest)
.startMessageIdInclusive()
.readCompacted(true)
.create();
```
The root cause is if the `startMessageIdInclusive` is true
and the `startMessageId` is `latest`, the reader will get the
last message ID from the broker and then seek to the last message.
But, the seek method did not consider if there are messages in the
compacted ledger, so not able to seek to last message of the compacted
ledger.
### Modification
Add force reset option for the managed cursor, if the seek
position < compaction horizon, we should force reset the cursor
to the given position, so that the reader is able to start reading from
the compacted ledger.
### Verification
A new test added for verifying the read the latest message from the
compacted ledger.
### Documentation
Check the box below or label this PR directly (if you have committer
privilege).
Need to update docs?
- [ ] `doc-required`
(If you need help on updating docs, create a doc issue)
- [x] `no-need-doc`
(Please explain why)
- [ ] `doc`
(If this PR contains doc changes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]