rajinisivaram commented on code in PR #13277:
URL: https://github.com/apache/kafka/pull/13277#discussion_r1633579132


##########
clients/src/main/java/org/apache/kafka/clients/NetworkClient.java:
##########
@@ -1122,13 +1141,26 @@ public long maybeUpdate(long now) {
 
             // Beware that the behavior of this method and the computation of 
timeouts for poll() are
             // highly dependent on the behavior of leastLoadedNode.
-            Node node = leastLoadedNode(now);
-            if (node == null) {
+            LeastLoadedNode leastLoadedNode = leastLoadedNode(now);
+
+            // Rebootstrap if needed and configured.
+            if (leastLoadedNode.node() == null
+                    && !leastLoadedNode.isAtLeastOneConnected()

Review Comment:
   Could we add a method to `LeastLoadedNode` that checks 
`leastLoadedNode.node() == null && !leastLoadedNode.isAtLeastOneConnected()` 
since we use that here and in Admin client? It will make it more obvious in 
LeastLoadedNode that the boolean is only used when node is null. We could then 
remove `isAtLeastOneConnected` method perhaps.



##########
server/src/main/java/org/apache/kafka/server/config/ServerConfigs.java:
##########
@@ -75,6 +75,10 @@ public class ServerConfigs {
     public static final long SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS = 
CommonClientConfigs.DEFAULT_SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS;
     public static final String SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_DOC = 
CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_DOC;
 
+    public static final String METADATA_RECOVERY_STRATEGY_CONFIG = 
CommonClientConfigs.METADATA_RECOVERY_STRATEGY_CONFIG;
+    public static final String METADATA_RECOVERY_STRATEGY_DOC = 
CommonClientConfigs.METADATA_RECOVERY_STRATEGY_DOC;
+    public static final String DEFAULT_METADATA_RECOVERY_STRATEGY = 
CommonClientConfigs.DEFAULT_METADATA_RECOVERY_STRATEGY;

Review Comment:
   These are no longer required?



##########
clients/src/main/java/org/apache/kafka/clients/LeastLoadedNode.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.clients;
+
+import org.apache.kafka.common.Node;
+
+public class LeastLoadedNode {
+    private final Node node;
+    private final boolean atLeastOneConnected;
+
+    public LeastLoadedNode(Node node, boolean atLeastOneConnected) {
+        this.node = node;
+        this.atLeastOneConnected = atLeastOneConnected;
+    }
+
+    public Node node() {
+        return node;
+    }
+
+    public boolean isAtLeastOneConnected() {

Review Comment:
   We are setting this to true only for ready connections, should we rename the 
method to indicate that?



##########
clients/src/main/java/org/apache/kafka/clients/NetworkClient.java:
##########
@@ -705,16 +715,25 @@ public Node leastLoadedNode(long now) {
         Node foundCanConnect = null;
         Node foundReady = null;
 
+        boolean atLeastOneNodeConnected = false;
+
         int offset = this.randOffset.nextInt(nodes.size());
         for (int i = 0; i < nodes.size(); i++) {
             int idx = (offset + i) % nodes.size();
             Node node = nodes.get(idx);
+
+            if (!atLeastOneNodeConnected
+                    && connectionStates.isReady(node.idString(), now)
+                    && selector.isChannelReady(node.idString())) {
+                atLeastOneNodeConnected = true;

Review Comment:
   Can we add one unit test for the various combinations to verify the returned 
values for LeastLoadedNode?



-- 
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-unsubscr...@kafka.apache.org

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

Reply via email to