[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keys
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- distributed-systems
Research direction
The bug is in internal.JavaStringHash, which returns the raw 32-bit hash without clearing the sign bit. NewDefaultRouter and the single-partition router then take it modulo the partition count. Compare with Murmur3_32Hash in the same file, which masks with 0x7fffffff, and check how the default router consumes the value. Done when keys such as customer-42 and device-7f3a map to the partitions in the issue's Java column for 3, 5, 6 and 10 partitions, and existing hash tests still pass.
Written by the indexing model from the issue text.
Description
Expected behavior
With the default HashingScheme (JavaStringHash), a message with a given key should go to the same partition as the same key sent by the Java client (and the C++/Python clients). The option is documented as "Java String.hashCode() equivalent".
Actual behavior
The Java client routes a keyed message to signSafeMod(key.hashCode() & Integer.MAX_VALUE, numPartitions); the C++ client also clears the sign bit (hash &= std::numeric_limits<int32_t>::max()). The Go internal.JavaStringHash returns the raw 32-bit value, and NewDefaultRouter / the single-partition router then compute hash % numPartitions on it.
When hashCode() has the top bit set, the Go result differs unless the partition count is a power of two. Murmur3_32Hash in the same file already masks with 0x7fffffff "to maintain compatibility with values used in Java client"; JavaStringHash does not.
Steps to reproduce
Partition chosen for a keyed message, for 3 / 5 / 6 / 10 partitions. Java: RoundRobinPartitionMessageRouterImpl(HashingScheme.JavaStringHash, …).choosePartition from pulsar-client 5.0.1. Go: pulsar.NewDefaultRouter(internal.JavaStringHash, …) at master 05daf3d.
| key | Java 5.0.1 | Go master |
|---|---|---|
| hello | 1 2 4 2 | 1 2 4 2 |
| order-1001 | 2 3 5 3 | 2 3 5 3 |
| customer-42 | 1 3 1 3 | 0 1 3 1 |
| device-7f3a | 0 1 0 6 | 2 4 2 4 |
"customer-42".hashCode() is 0x965fbacd. Java's makeHash returns 0x165fbacd, but Go's JavaStringHash returns 0x965fbacd.
Over 100,000 random UUID-string keys, 49,749 land on a different partition than in the Java client for every partition count tested that is not a power of two (3, 5, 6, 10, 12). With 16 partitions, none do.
Where this shows up
When a topic is produced to from both Go and Java (or C++/Python) services, or a producer is ported from Java to Go, the same key is written to two partitions. Per-key ordering is then lost, and consumers that rely on key → partition affinity (Failover/Exclusive per partition, stateful processing keyed by partition) see a key's messages split.
Note: non-ASCII keys differ for a second reason. Go hashes UTF-8 bytes, while Java hashes UTF-16 code units (for example café). That is a separate question, and this report covers only the sign-bit handling, which affects plain ASCII keys.
System configuration
Pulsar version: client master (05daf3d); Java reference pulsar-client 5.0.1
- Dominant language
- Go
- Stars
- 746
- Forks
- 394
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 7
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/pulsar-client-go
-
[Bug] Concurrent transactional ACKs can crash in registerAckTopicPossibly taken @Ebispongebob claimed this 73 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/pulsar-client-go#1536 ·
Maintainers usually reply within 2 days
-
Nil pointer panic in `sendRequest.done()` during producer reconnection via `FailTimeoutMessages`Possibly taken @nodece claimed this 186 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/pulsar-client-go#1497 · 1 comment ·
Maintainers usually reply within 2 days
-
[Bug][Consumer] Throughput collapse and permanent deadlock on large payloads since v0.20.0Possibly taken @HrithikShet claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 32/100
apache/pulsar-client-go#1573 ·
Maintainers usually reply within 2 days
-
[Bug] Lookup retries use a fixed backoff that doubles to 60 s, so a reconnect during a broker outage can sleep through the failoverPossibly taken @EdwardShen125 claimed this 26 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 54/100
apache/pulsar-client-go#1554 ·
Maintainers usually reply within 2 days
-
[Bug][Producer] A send error or an out-of-order receipt for one producer closes the shared connection, reconnecting every producer and consumer on itPossibly taken @diegofernandes claimed this 26 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
apache/pulsar-client-go#1553 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
All issues in apache/pulsar-client-go
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
seaweedfs/seaweed-block#443 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
version-fox/vfox#825 ·
Maintainers usually reply within 1 day
-
HTTP `batch.Send` returns nil and inserts no rows when the block does not encodePossibly taken @Indian-boult claimed this today. Openbug queries
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ClickHouse/clickhouse-go#2155 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
transparency-dev/tessera#1286 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100