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

[C++] SinglePartition message router is always picking the same partition #9702

Merged
merged 4 commits into from
Feb 25, 2021

Conversation

merlimat
Copy link
Contributor

Motivation

The SinglePartitionMessageRouter is supposed to pick a random partition for a given producer and to stick with that. The problem is that the C rand() call is always using the seed 0 and that ends up having multiple processes to always deterministically pick the same partition.

@merlimat merlimat added type/bug The PR fixed a bug or issue reported a bug release/2.7.2 labels Feb 24, 2021
@merlimat merlimat added this to the 2.8.0 milestone Feb 24, 2021
@merlimat merlimat self-assigned this Feb 24, 2021
ProducerConfiguration::HashingScheme hashingScheme)
: MessageRouterBase(hashingScheme) {
boost::random::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
boost::random::uniform_int_distribution<int> dist;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use std::random from C++ standard library instead of boost::random?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed.

There are also other places where we use it. They should get converted as well .

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, in BackOff.cc and RoundRobinMessageRouter.cc.

@merlimat merlimat merged commit 935ceda into apache:master Feb 25, 2021
@merlimat merlimat deleted the fix-single-partition-router branch February 25, 2021 21:20
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Mar 23, 2021
codelipenghui pushed a commit that referenced this pull request Mar 23, 2021
…tion (#9702)

* [C++] SinglePartition message router is always picking the same partition

* Fixed formatting

* using std::random

* Fixed formatting

(cherry picked from commit 935ceda)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants