Fix hasMessageAvailable incorrectly returns true when read to latest after seeking by timestamp#498
Merged
BewareMyPower merged 2 commits intoapache:mainfrom Aug 21, 2025
Conversation
…after seeking by timestamp
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where hasMessageAvailable incorrectly returns true when reading to the latest message after seeking by timestamp. The fix involves correcting the logic for determining when to compare mark delete positions and properly resetting the start message ID when seeking by timestamp.
Key changes:
- Modified
compareMarkDeletePositionlogic to only usehasSoughtByTimestamp_check when no messages have been received - Reset
startMessageId_to prevent message filtering issues after timestamp seeks - Enhanced test coverage to validate the fix by reading all available messages after seeking
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/ConsumerImpl.h | Added helper method hasSoughtByTimestamp() for consistent atomic access |
| lib/ConsumerImpl.cc | Fixed compareMarkDeletePosition logic and startMessageId_ handling for timestamp seeks |
| tests/ReaderTest.cc | Enhanced test to validate fix by consuming all messages after seeking by timestamp |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
RobertIndie
approved these changes
Aug 21, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
The computation for
compareMarkDeletePositionis wrong thathasSoughtByTimestamp_should only be checked whenlastDequedMessageId_isearliest, which means no messages have been received.Additionally, reset
startMessageId_when seeking by timestamp, otherwise, if the initialstartMessageIdof a reader is a valid message id, that message could be filtered inpulsar-client-cpp/lib/ConsumerImpl.cc
Lines 619 to 625 in 9b86f9e
pulsar-client-cpp/lib/ConsumerImpl.cc
Lines 774 to 780 in 9b86f9e
Improve
testHasMessageAvailableAfterSeekTimestampto cover the cases above.