You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by sh...@apache.org on 2022/04/09 02:58:25 UTC

[kafka] branch trunk updated: KAFKA-13794: Follow up to fix producer batch comparator (#12006)

This is an automated email from the ASF dual-hosted git repository.

showuon pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 9596c7b9cf KAFKA-13794: Follow up to fix producer batch comparator (#12006)
9596c7b9cf is described below

commit 9596c7b9cfacb6aba961a328023c6572e8800837
Author: Xiaoyue Xue <28...@qq.com>
AuthorDate: Sat Apr 9 10:58:16 2022 +0800

    KAFKA-13794: Follow up to fix producer batch comparator (#12006)
    
    In comparator, objects that are not equal need to have a stable order otherwise, binary search may not find the objects. Improve the producer batch comparator
---
 .../org/apache/kafka/clients/producer/internals/TransactionManager.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java b/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java
index e7aa212eb7..961e4e4f5a 100644
--- a/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java
+++ b/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java
@@ -178,7 +178,7 @@ public class TransactionManager {
         private static final Comparator<ProducerBatch> PRODUCER_BATCH_COMPARATOR = (b1, b2) -> {
             if (b1.baseSequence() < b2.baseSequence()) return -1;
             else if (b1.baseSequence() > b2.baseSequence()) return 1;
-            else return b1.equals(b2) ? 0 : 1;
+            else return Integer.compare(b1.hashCode(), b2.hashCode());
         };
 
         TopicPartitionEntry() {