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

[Bug] collision while using ConsistentHashing & consumer name that end by a number #22050

Closed
1 of 2 tasks
jbarotin opened this issue Feb 13, 2024 · 0 comments · Fixed by #22053
Closed
1 of 2 tasks

[Bug] collision while using ConsistentHashing & consumer name that end by a number #22050

jbarotin opened this issue Feb 13, 2024 · 0 comments · Fixed by #22053
Assignees

Comments

@jbarotin
Copy link

Search before asking

  • I searched in the issues and found nothing similar.

Version

pulsar v3.1.1 & ubuntu 22.04

Minimal reproduce step

Consistent hashing enabled in brocker config :
subscriptionKeySharedUseConsistentHashing=true

Create Pulsar consumers in a loop like this :

for (int i = 0; i < 40; i++) {

  ConsumerBuilder<GenericRecord> consumerBuilder = client.newConsumer(myschema)
         .topic("mytopic")
         .consumerName(hostname+"-"+i)
         .subscriptionName("mysubcription")
         .subscriptionMode(SubscriptionMode.Durable)
         .subscriptionType(SubscriptionType.Key_Shared)
         .keySharedPolicy(KeySharedPolicy.autoSplitHashRange().setAllowOutOfOrderDelivery(true))
         .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
         .receiverQueueSize(1000)
         .maxAcknowledgmentGroupSize(100)
         .acknowledgmentGroupTime(100, TimeUnit.MILLISECONDS)
         .messageListener((MessageListener<GenericRecord>) (consumer, msg) -> {
            // my consumer code
          }
}  

What did you expect to see?

While I'm executing
pulsar-admin topics stats public/default/mytopic-partition-0

if I look keyHashRanges field, I found that the following range "[1932476396, 1932750362]" is associated to two different consumers host2-2 and host2-25 .

What did you see instead?

While I'm executing
pulsar-admin topics stats public/default/mytopic

if I look keyHashRanges field, I want to found every range associated to only one consumer.

Anything else?

On slack @lhotari told me that hash collision that happens with my use case where Ihave a consumerName ending with a number, and pointed me to this code

for (int i = 0; i < numberOfPoints; i++) {
String key = consumer.consumerName() + i;
int hash = Murmur3_32Hash.getInstance().makeHash(key.getBytes());

A simple workaround is to use .consumerName(hostname+"-"+i+"-"), ie add some character other than a number to the end of the consumer name.

Are you willing to submit a PR?

  • I'm willing to submit a PR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants