K-jun98 opened a new pull request, #24322:
URL: https://github.com/apache/kafka/pull/24322

   RoundRobinPartitioner created its per-topic counter with `new 
AtomicInteger(0)`, so every
   producer instance started from the first available partition. Producers that 
start at the
   same time and send the same number of records keep their counters in sync, 
and the k-th
   record of every producer goes to the same partition. N producers then stack 
N records on
   the same few partitions instead of spreading them.
   
   This change starts each counter at a random value
   (`ThreadLocalRandom.current().nextInt()`), as `DefaultPartitioner` did 
before 2.4 and as
   KAFKA-1071 did for the old producer. Round robin within one producer is 
unchanged; only the
   starting partition becomes random. `partition()` already applies
   `Utils.toPositive(next) % availablePartitions.size()`, so the partition 
count does not need to
   be known when the counter is created.
   
   Testing: added `testPartitionersStartedTogetherDoNotPickTheSamePartitions`, 
which creates
   10 partitioners on a 100-partition topic and checks that their first picks 
are not all the
   same partition (false failure probability (1/100)^9). It fails on the 
current code (all 10
   pick the same partition) and passes with this change. The existing tests 
count records per
   partition over full cycles, so they do not depend on the start partition.
   
   Generated-by: Claude Code


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to