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][client] Fix wrong results of hasMessageAvailable and readNext after seeking by timestamp #22363

Merged

Conversation

BewareMyPower
Copy link
Contributor

Motivation

After seeking by timestamp, hasMessageAvailable() and readNext() could return wrong values.

The 1st bug was a regression introduced by
#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 #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.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

…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`.
Co-authored-by: Lari Hotari <[email protected]>
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM

BewareMyPower added a commit to BewareMyPower/pulsar-client-cpp that referenced this pull request Mar 27, 2024
@BewareMyPower BewareMyPower merged commit 149deaa into apache:master Mar 27, 2024
50 checks passed
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-seek-ts-latest branch March 27, 2024 11:49
lhotari pushed a commit that referenced this pull request Mar 27, 2024
…fter seeking by timestamp (#22363)

Co-authored-by: Lari Hotari <[email protected]>
(cherry picked from commit 149deaa)
lhotari pushed a commit that referenced this pull request Mar 27, 2024
…fter seeking by timestamp (#22363)

Co-authored-by: Lari Hotari <[email protected]>
(cherry picked from commit 149deaa)
BewareMyPower added a commit to apache/pulsar-client-cpp that referenced this pull request Mar 28, 2024
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- Technoboy- added this to the 3.3.0 milestone Apr 1, 2024
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Apr 1, 2024
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 <[email protected]>
(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 <[email protected]>
(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 <[email protected]>
(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 <[email protected]>
(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 <[email protected]>
(cherry picked from commit 149deaa)
(cherry picked from commit 1045f8b)
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