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] Consumer batch receive will cause data loss. #228

Merged
merged 3 commits into from
Mar 31, 2023

Conversation

shibd
Copy link
Member

@shibd shibd commented Mar 23, 2023

Motivation

Currently, the batch receive method may cause data loss.

The root cause is, when peekMsg can't add to messages(The batch has satisfied the batch receive policy), it has actually been popped.

Message peekMsg;
while (incomingMessages_.pop(peekMsg, std::chrono::milliseconds(0)) && messages->canAdd(peekMsg)) {
messageProcessed(peekMsg);
Message interceptMsg = interceptors_->beforeConsume(Consumer(shared_from_this()), peekMsg);
messages->add(interceptMsg);
}

Modifications

  • Peek first, pop only when it can be added.

Verifying this change

  • Change testBatchReceive test to cover this case:
    Send 100 messages first, batch receive 10 messages at a time, and assert that all messages can be received.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@shibd shibd added bug Something isn't working release/3.1.3 labels Mar 23, 2023
@shibd shibd added this to the 3.2.0 milestone Mar 23, 2023
@shibd shibd self-assigned this Mar 23, 2023
lib/ConsumerImpl.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@BewareMyPower BewareMyPower left a comment

Choose a reason for hiding this comment

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

Should we also check isClosedNoMutex for both BlockingQueue and UnboundedBlockingQueue?

@shibd
Copy link
Member Author

shibd commented Mar 29, 2023

Should we also check isClosedNoMutex for both BlockingQueue and UnboundedBlockingQueue?

oh, I missed it. added check, PTAL.

@shibd shibd merged commit 86d66bd into apache:main Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release/3.1.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants