Pankraz76 commented on code in PR #21149:
URL: https://github.com/apache/kafka/pull/21149#discussion_r2634703731
##########
clients/src/main/java/org/apache/kafka/clients/producer/RoundRobinPartitioner.java:
##########
@@ -64,7 +64,11 @@ public int partition(String topic, Object key, byte[]
keyBytes, Object value, by
}
private int nextValue(String topic) {
- AtomicInteger counter = topicCounterMap.computeIfAbsent(topic, k ->
new AtomicInteger(0));
+ AtomicInteger counter = topicCounterMap.get(topic);
+ if(counter == null) {
+ counter = new AtomicInteger(0);
+ AtomicInteger counter = topicCounterMap.putIfAbsent(topic,
counter);
+ }
Review Comment:
currently the counter var is unused, this seems kind of an issue. Also the
`counter` reference is kind of omni present having high coupling but low
cohesion. This seems kind of bad taste.
<img width="610" height="151" alt="Image"
src="https://github.com/user-attachments/assets/24ade5f7-ae0f-46c0-8c2f-b2794db64e58"
/>
```suggestion
AtomicInteger counter = topicCounterMap.get(topic);
if (counter == null) {
return topicCounterMap.putIfAbsent(topic, new
AtomicInteger(0)).getAndIncrement();
}
```
--
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]