-
Notifications
You must be signed in to change notification settings - Fork 70
Fix hasMessageAvailable might return true after seeking to latest #409
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
Merged
BewareMyPower
merged 5 commits into
apache:main
from
BewareMyPower:bewaremypower/has-msg-available-after-seek-latest
Mar 11, 2024
Merged
Fix hasMessageAvailable might return true after seeking to latest #409
BewareMyPower
merged 5 commits into
apache:main
from
BewareMyPower:bewaremypower/has-msg-available-after-seek-latest
Mar 11, 2024
Conversation
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
f59e148
to
886ff1c
Compare
After a seek operation is done, the `startMessageId` will be updated until the reconnection due to the seek is done in `connectionOpened`. So before it's updated, `hasMessageAvailable` could compare with an outdated `startMessageId` and return a wrong value. ### Modifications Replace `duringSeek` with a `SeekStatus` field: - `NOT_STARTED`: initial, or a seek operation is done. `seek` could only succeed in this status. - `IN_PROGRESS`: A seek operation has started but the client does not receive the response from broker. - `COMPLETED`: The client has received the seek response but the seek future is not done. After the status becomes `COMPLETED`, if the connection is not ready, next time the connection is established, the status will change from `COMPLETED` to `NOT_STARTED` and then seek future will be completed in the internal executor. Add `testHasMessageAvailableAfterSeekToEnd` and `testSeekInProgress`.
886ff1c
to
0e91bbd
Compare
@merlimat @shibd @RobertIndie @Demogorgon314 Could you take a look? |
shibd
reviewed
Mar 11, 2024
RobertIndie
reviewed
Mar 11, 2024
lib/ConsumerImpl.cc
Outdated
@@ -236,16 +236,15 @@ Future<Result, bool> ConsumerImpl::connectionOpened(const ClientConnectionPtr& c | |||
// sending the subscribe request. | |||
cnx->registerConsumer(consumerId_, get_shared_this_ptr()); | |||
|
|||
if (duringSeek_) { | |||
if (duringSeek()) { | |||
ackGroupingTrackerPtr_->flushAndClean(); | |||
} | |||
|
|||
Lock lockForMessageId(mutexForMessageId_); | |||
// Update startMessageId so that we can discard messages after delivery restarts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move this comment inside the clearReceiveQueue
.
@RobertIndie @shibd Comments are addressed, PTAL again. |
Demogorgon314
approved these changes
Mar 11, 2024
RobertIndie
approved these changes
Mar 11, 2024
shibd
approved these changes
Mar 11, 2024
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
See apache/pulsar-client-python#199
There is a race condition when
hasMessageAvailable
is called afterseek
if the start message ID ofReader
is earliest.In
ConsumerImpl::hasMessageAvailableAsync
, if the connection is not established at the moment,lastDequedMessageId_
will beearliest
because no message is received. SincelastMessageIdInBroker_
is alsoearliest
,getLastMessageIdAsync
will be called and then it comes atpulsar-client-cpp/lib/ConsumerImpl.cc
Line 1554 in e2cacb7
However, before
getLastMessageIdAsync
is called,messageId
wasearliest
becauselastDequedMessageId_
andstartMessageId_
were bothearliest
. However, when the callback is called, thestartMessageId_
has already been updated tolatest
inconnectionOpened
, so we should compare tolatest
.Modifications
In the callback of
getLastMessageIdAsync
, retrieve the latest value ofstartMessageId_
to compare rather then reusing the old value.Refactor the seek flow to reset the seek states and trigger the callback after updating the
startMessageId_
.ReaderTest.testHasMessageAvailableAfterSeekToEnd
is added to cover the changes.