Slackbot
02/12/2024, 5:17 PMJerome B
02/12/2024, 5:18 PMfor (int i = 0; i < concurrentConsumer; 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
}
}David K
02/12/2024, 5:42 PMJerome B
02/12/2024, 5:49 PMDavid K
02/12/2024, 5:58 PMJerome B
02/12/2024, 6:09 PMLari Hotari
02/12/2024, 6:21 PMKeySharedPolicy.autoSplitHashRange() is selected. https://github.com/apache/pulsar/issues/13305 for more details. It seems that hash ranges aren't unique in the internal data structure. That's why the keyHashRanges information might not be relevant.Jerome B
02/12/2024, 6:34 PM# On KeyShared subscriptions, with default AUTO_SPLIT mode, use splitting ranges or
# consistent hashing to reassign keys to new consumers
subscriptionKeySharedUseConsistentHashing=true
# On KeyShared subscriptions, number of points in the consistent-hashing ring.
# The higher the number, the more equal the assignment of keys to consumers
subscriptionKeySharedConsistentHashingReplicaPoints=100
Sorry to forgot mention thatJerome B
02/12/2024, 6:36 PMLari Hotari
02/12/2024, 6:42 PMLari Hotari
02/12/2024, 6:49 PMif I look keyHashRanges field, I found that the following rangeThat is because of the weakness of the current way the internal hashes are created in ConsistentHashingStickyKeyConsumerSelector: https://github.com/apache/pulsar/blob/08b28f5c5cbbdc63467455c40106173475ff01e5/pul[…]/broker/service/ConsistentHashingStickyKeyConsumerSelector.javais associated to two different consumers"[1932476396, 1932750362]"andhost2-2host2-25
Lari Hotari
02/12/2024, 6:50 PMhost2-2 and host2-25 would collide for example with key host2-251 . That would be i=51 for host2-2 and i=1 for host2-25 .
The workaround would be to add some other character at the end of the consumer name.Lari Hotari
02/12/2024, 6:51 PM.consumerName(hostname+"-"+i+"-")Lari Hotari
02/13/2024, 11:36 AMhost2-2 and host2-25 consumer names collide).Lari Hotari
02/13/2024, 11:37 AMJerome B
02/13/2024, 2:33 PMLari Hotari
02/13/2024, 2:49 PMLari Hotari
02/14/2024, 6:05 PMJerome B
02/15/2024, 9:32 AM