From 67fff53c5021bc0361d3a289c15345537b8be6bf Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 12 Jun 2018 13:49:57 +0200 Subject: [PATCH 1/2] ensure that hash is positive before mod and not after ( like the java lib is doing it ) --- partitioner.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/partitioner.go b/partitioner.go index 972932728..98be07971 100644 --- a/partitioner.go +++ b/partitioner.go @@ -123,10 +123,7 @@ func (p *hashPartitioner) Partition(message *ProducerMessage, numPartitions int3 if err != nil { return -1, err } - partition := int32(p.hasher.Sum32()) % numPartitions - if partition < 0 { - partition = -partition - } + partition := (int32(p.hasher.Sum32()) & 0x7fffffff) % numPartitions return partition, nil } From bb8189f5061871658f5c9e5def2aeb0826b7cb47 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 12 Jun 2018 14:15:59 +0200 Subject: [PATCH 2/2] fix fmt for new partitioner behavior --- partitioner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partitioner.go b/partitioner.go index 98be07971..c3baa0712 100644 --- a/partitioner.go +++ b/partitioner.go @@ -123,7 +123,7 @@ func (p *hashPartitioner) Partition(message *ProducerMessage, numPartitions int3 if err != nil { return -1, err } - partition := (int32(p.hasher.Sum32()) & 0x7fffffff) % numPartitions + partition := (int32(p.hasher.Sum32()) & 0x7fffffff) % numPartitions return partition, nil }