You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/02/07 15:13:11 UTC

[GitHub] [kafka] predatorray commented on a change in pull request #10525: KAFKA-7572: Producer should not send requests with negative partition id

predatorray commented on a change in pull request #10525:
URL: https://github.com/apache/kafka/pull/10525#discussion_r800756743



##########
File path: clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
##########
@@ -1305,10 +1305,16 @@ private ClusterResourceListeners configureClusterResourceListeners(Serializer<K>
      */
     private int partition(ProducerRecord<K, V> record, byte[] serializedKey, byte[] serializedValue, Cluster cluster) {
         Integer partition = record.partition();
-        return partition != null ?
-                partition :
-                partitioner.partition(
-                        record.topic(), record.key(), serializedKey, record.value(), serializedValue, cluster);
+        if (partition != null) {
+            return partition;
+        }
+
+        int customPartition = partitioner.partition(
+                record.topic(), record.key(), serializedKey, record.value(), serializedValue, cluster);
+        if (customPartition < 0) {
+            throw new IllegalArgumentException(String.format("Invalid partition: %d. Partition number should always be non-negative.", customPartition));

Review comment:
       Sure. I have pushed a new commit. How about this one?
   ```java
   "The partitioner generated an invalid partition number: %d. Partition number should always be non-negative."
   ```
   
   By the way, I think Jenkins PR check did not run quite well. The failed tests are not related to this change. I tried some of these. Looks like they could be passed on my laptop.




-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org