merlimat commented on a change in pull request #1029: Fix MessageRouter hash inconsistent on C++/Java client URL: https://github.com/apache/incubator-pulsar/pull/1029#discussion_r164276552
########## File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/RoundRobinPartitionMessageRouterImpl.java ########## @@ -34,25 +30,18 @@ AtomicIntegerFieldUpdater.newUpdater(RoundRobinPartitionMessageRouterImpl.class, "partitionIndex"); private volatile int partitionIndex = 0; - public RoundRobinPartitionMessageRouterImpl(boolean useMurmurHash) { - super(useMurmurHash); + public RoundRobinPartitionMessageRouterImpl(ProducerConfiguration.HashingScheme hashingScheme) { + super(hashingScheme); PARTITION_INDEX_UPDATER.set(this, 0); } @Override public int choosePartition(Message msg, TopicMetadata topicMetadata) { // If the message has a key, it supersedes the round robin routing policy if (msg.hasKey()) { - if (useMurmurHash) { - HashFunction hf = Hashing.murmur3_32(0); - HashCode hc = hf.hashString(msg.getKey(), StandardCharsets.UTF_8); - long l = Integer.toUnsignedLong(hc.asInt()); - return (int) (l % topicMetadata.numPartitions()); - } - else { - return ((msg.getKey().hashCode() & Integer.MAX_VALUE) % topicMetadata.numPartitions()); - } + return (int) (hash.makeHash(msg.getKey()) % topicMetadata.numPartitions()); Review comment: This depends on the `makeHash()` to always return a positive number, which is true in the current implementation. We should mention that in the `makeHash()` javadoc. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services