[ 
https://issues.apache.org/jira/browse/KAFKA-1988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14340663#comment-14340663
 ] 

Jun Rao commented on KAFKA-1988:
--------------------------------

Hi, Tong,

My suggestion is slightly different. My point is that If we change the behavior 
of o.a.k.c.u.Utils.abs(), it will impact the following code in 
o.a.k.c.p.i.Partitioner since a given key will now be mapped to a different 
partition.

            // hash the key to choose a partition
            return Utils.abs(Utils.murmur2(key)) % numPartitions;

To preserve the current behavior, I was suggesting that we define a local 
method in o.a.k.c.p.i.Partitioner that looks like the following.

    private static int toPositive(int n) {
        return n & 0x7fffffff;
    }

and change the partitioning code to

            // hash the key to choose a partition
            return toPositive(Utils.murmur2(key)) % numPartitions;

This will preserve the partitioning behavior of the producer in o.a.k.c.p. The 
rest of the changes will be the same as your original patch. We don't have to 
change the partitioning code in DefaultEventHandler. The scala producer already 
uses a different hash function from the java producer in o.a.k.c.p. So, the 
partitioning won't be consistent btw the scala and the java producer anyway. 
The replacing of k.u.Utils.abs() with o.a.k.c.u.Utils.abs() doesn't have to be 
done in this jira since you are already handling it in KAFKA-1926.


> org.apache.kafka.common.utils.Utils.abs method returns wrong value for 
> negative numbers.
> ----------------------------------------------------------------------------------------
>
>                 Key: KAFKA-1988
>                 URL: https://issues.apache.org/jira/browse/KAFKA-1988
>             Project: Kafka
>          Issue Type: Bug
>    Affects Versions: 0.8.2.0
>            Reporter: Tong Li
>            Assignee: Tong Li
>            Priority: Blocker
>             Fix For: 0.8.2.1
>
>         Attachments: KAFKA-1988.patch, KAFKA-1988.patch
>
>
> org.apache.kafka.common.utils.Utils.abs method returns wrong value for 
> negative numbers. The method only returns intended value for positive 
> numbers. All negative numbers except the Integer.Min_Value will be returned 
> an unsigned integer.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to