[fix][client] Fix wrong results of hasMessageAvailable and readNext after seeking by timestamp - #22363
Merged
BewareMyPower merged 3 commits intoMar 27, 2024
Conversation
…fter seeking by timestamp ### Motivation After seeking by timestamp, `hasMessageAvailable()` and `readNext()` could return wrong values. The 1st bug was a regression introduced by apache#22201, which modifies `startMessageId` to `seekMessageId` before a seek operation is done. However, the previous behavior is also a bug but accidentally works in this case. When seeking by timestamp, the `seekMessageId` is modified to `earliest`, which should not be compared with `lastMessageIdInBroker` because the actual start position is determined by the seek timestamp, not the `earliest` message id. The 2nd bug was caused by apache#9652, when `startMessageIdInclusive()` is configured to create a reader, it could seek to the position of the latest message when `lastDequeuedMessageId` is `earliest` and `startMessageId` is `latest`. ### Modifications Add a boolean flag `hasSoughtByTimestamp` to represent whether the last seek call accepts a timestamp. If it's true, don't take `startMessageId` into comparison with `lastMessageIdInBroker`, just compare the mark-delete position and last position in the GetLastMessageId response. Add `testHasMessageAvailableAfterSeekTimestamp` to verify the change. For the `readNext` call, if the reader has sought by timestamp, don't seek to the latest position in `hasMessageAvailable`. Modify `testReadMessageWithBatchingWithMessageInclusive` to verify the fix. However, this patch does not modify the existing behavior when `seek` is not called because the inclusive reader relies on the implicit seek operation in `hasMessageAvailable`.
BewareMyPower
requested review from
RobertIndie,
Technoboy-,
codelipenghui,
dao-jun,
lhotari,
poorbarcode and
shibd
March 26, 2024 14:14
lhotari
reviewed
Mar 26, 2024
Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com>
dao-jun
approved these changes
Mar 27, 2024
shibd
approved these changes
Mar 27, 2024
BewareMyPower
added a commit
to BewareMyPower/pulsar-client-cpp
that referenced
this pull request
Mar 27, 2024
…y timestamp Fixes apache#420 It's a catch-up for apache/pulsar#22363
BewareMyPower
added a commit
to apache/pulsar-client-cpp
that referenced
this pull request
Mar 28, 2024
…y timestamp (#422) Fixes #420 It's a catch-up for apache/pulsar#22363
BewareMyPower
added a commit
to apache/pulsar-client-cpp
that referenced
this pull request
Mar 28, 2024
…y timestamp (#422) Fixes #420 It's a catch-up for apache/pulsar#22363 (cherry picked from commit 27d8cc0)
Technoboy-
pushed a commit
to Technoboy-/pulsar
that referenced
this pull request
Apr 1, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com>
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 15, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> (cherry picked from commit 149deaa) (cherry picked from commit 1045f8b)
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 17, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> (cherry picked from commit 149deaa) (cherry picked from commit 1045f8b)
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 17, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> (cherry picked from commit 149deaa) (cherry picked from commit 1045f8b)
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 19, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> (cherry picked from commit 149deaa) (cherry picked from commit 1045f8b)
srinath-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Apr 23, 2024
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com> (cherry picked from commit 149deaa) (cherry picked from commit 1045f8b)
hanmz
pushed a commit
to hanmz/pulsar
that referenced
this pull request
Feb 12, 2025
…fter seeking by timestamp (apache#22363) Co-authored-by: Lari Hotari <lhotari@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #22363 +/- ##
============================================
+ Coverage 73.57% 73.76% +0.18%
+ Complexity 32624 32340 -284
============================================
Files 1877 1886 +9
Lines 139502 139445 -57
Branches 15299 15287 -12
============================================
+ Hits 102638 102856 +218
+ Misses 28908 28635 -273
+ Partials 7956 7954 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Motivation
After seeking by timestamp,
hasMessageAvailable()andreadNext()could return wrong values.The 1st bug was a regression introduced by
#22201, which modifies
startMessageIdtoseekMessageIdbefore a seek operation is done. However, the previous behavior is also a bug but accidentally works in this case. When seeking by timestamp, theseekMessageIdis modified toearliest, which should not be compared withlastMessageIdInBrokerbecause the actual start position is determined by the seek timestamp, not theearliestmessage id.The 2nd bug was caused by #9652, when
startMessageIdInclusive()is configured to create a reader, it could seek to the position of the latest message whenlastDequeuedMessageIdisearliestandstartMessageIdislatest.Modifications
Add a boolean flag
hasSoughtByTimestampto represent whether the last seek call accepts a timestamp. If it's true, don't takestartMessageIdinto comparison withlastMessageIdInBroker, just compare the mark-delete position and last position in the GetLastMessageId response.Add
testHasMessageAvailableAfterSeekTimestampto verify the change.For the
readNextcall, if the reader has sought by timestamp, don't seek to the latest position inhasMessageAvailable. ModifytestReadMessageWithBatchingWithMessageInclusiveto verify the fix. However, this patch does not modify the existing behavior whenseekis not called because the inclusive reader relies on the implicit seek operation inhasMessageAvailable.Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: