AndrewJSchofield commented on code in PR #22512:
URL: https://github.com/apache/kafka/pull/22512#discussion_r3467460009


##########
clients/src/main/java/org/apache/kafka/common/Node.java:
##########
@@ -31,30 +31,47 @@ public class Node {
     private final int port;
     private final String rack;
     private final boolean isFenced;
+    private final boolean isCoordinator;
 
     // Cache hashCode as it is called in performance sensitive parts of the 
code (e.g. RecordAccumulator.ready)
     private Integer hash;
 
     public Node(int id, String host, int port) {
-        this(id, host, port, null, false);
+        this(id, host, port, null, false, false);
     }
 
     public Node(int id, String host, int port, String rack) {
-        this.id = id;
-        this.idString = Integer.toString(id);
-        this.host = host;
-        this.port = port;
-        this.rack = rack;
-        this.isFenced = false;
+        this(id, host, port, rack, false, false);
     }
 
     public Node(int id, String host, int port, String rack, boolean isFenced) {
+        this(id, host, port, rack, isFenced, false);
+    }
+
+    public Node(int id, String host, int port, String rack, boolean isFenced, 
boolean isCoordinator) {
         this.id = id;
-        this.idString = Integer.toString(id);
+        // The contract here is that the node's id can be extracted from the 
node's idString by parsing as
+        // an integer. We want coordinator and non-coordinator nodes with the 
same id to have different
+        // idString values which parse to the same numeric id value. The Kafka 
network code depends upon having
+        // separate coordinator connections to brokers, and uses idString to 
differentiate.
+        //
+        // There are three cases:
+        // * Negative node ID - used for bootstrap, will not be a coordinator, 
idString will be a negative integer string
+        // * Non-negative node ID, not coordinator - idString will be a 
non-negative integer string with no sign
+        // * Non-negative node ID, coordinator - idString will be a 
non-negative integer string, with a leading '+'
+        if (isCoordinator) {
+            if (id < 0) {
+                throw new IllegalArgumentException("Node id for coordinator 
node cannot be negative");
+            }
+            this.idString = "+" + id;

Review Comment:
   Because I want integer parsing to work. All we need is a difference. There's 
no need to make this more difficult I feel. I did start with `coordinator-[%d}` 
but then I needed a parsing method in `Node` and I decided the complexity 
wasn't really worth it.



-- 
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