mridulm commented on code in PR #2629:
URL: https://github.com/apache/celeborn/pull/2629#discussion_r1679814439


##########
common/src/main/java/org/apache/celeborn/common/client/MasterClient.java:
##########
@@ -226,14 +225,24 @@ private void resetRpcEndpointRef(@Nullable RpcEndpointRef 
oldRef) {
    *     cannot be obtained.
    * @return non-empty RpcEndpointRef.
    */
-  private RpcEndpointRef getOrSetupRpcEndpointRef(AtomicInteger currentIndex) {
+  private RpcEndpointRef getOrSetupRpcEndpointRef(AtomicInteger currentIndex, 
int numTry) {

Review Comment:
   nit: `numTry` -> `currentAttempt`



##########
common/src/main/scala/org/apache/celeborn/common/client/MasterEndpointResolver.scala:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.celeborn.common.client
+
+import java.util.concurrent.atomic.AtomicBoolean
+
+import scala.collection.JavaConverters._
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.protocol.RpcNameConstants
+
+abstract class MasterEndpointResolver(
+    private val conf: CelebornConf,
+    private val isWorker: Boolean) extends Logging {
+
+  private var masterEndpointName: Option[String] = None
+
+  protected var activeMasterEndpoints: Option[List[String]] = None
+
+  protected val updated = new AtomicBoolean(false)
+
+  if (isWorker && conf.internalPortEnabled) {
+    // For worker, we should use the internal endpoints if internal port is 
enabled.
+    this.masterEndpointName = Some(RpcNameConstants.MASTER_INTERNAL_EP)
+    resolve(conf.masterInternalEndpoints)
+  } else {
+    this.masterEndpointName = Some(RpcNameConstants.MASTER_EP)
+    resolve(conf.masterEndpoints)
+  }
+
+  def getMasterEndpointName: String = masterEndpointName.get
+
+  def getActiveMasterEndpoints: java.util.List[String] = 
activeMasterEndpoints.get.asJava
+
+  def isUpdated: Boolean = updated.compareAndSet(true, false)

Review Comment:
   This method mutates state, so use `()`. Also rename it to be more clear
   ```suggestion
     def getUpdatedAndReset(): Boolean = updated.compareAndSet(true, false)
   ```



##########
common/src/main/java/org/apache/celeborn/common/client/MasterClient.java:
##########
@@ -226,14 +225,24 @@ private void resetRpcEndpointRef(@Nullable RpcEndpointRef 
oldRef) {
    *     cannot be obtained.
    * @return non-empty RpcEndpointRef.
    */
-  private RpcEndpointRef getOrSetupRpcEndpointRef(AtomicInteger currentIndex) {
+  private RpcEndpointRef getOrSetupRpcEndpointRef(AtomicInteger currentIndex, 
int numTry) {
     RpcEndpointRef endpointRef = rpcEndpointRef.get();
+
+    // If endpoints are updated by MasterEndpointResolver, we should reset the 
currentIndex to 0.
+    // This also unset the value of updated, so we don't always reset 
currentIndex to 0.
+    if (masterEndpointResolver.isUpdated()) {
+      currentIndex.set(0);
+      maxRetries =
+          Math.max(maxRetries, numTry + 
masterEndpointResolver.getActiveMasterEndpoints().size());
+    }
+    List<String> activeMasterEndpoints = 
masterEndpointResolver.getActiveMasterEndpoints();

Review Comment:
   nit: Move this above the previous `if` and use it within `maxRetries` 
computation as well.



##########
common/src/main/scala/org/apache/celeborn/common/client/MasterEndpointResolver.scala:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.celeborn.common.client
+
+import java.util.concurrent.atomic.AtomicBoolean
+
+import scala.collection.JavaConverters._
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.internal.Logging
+import org.apache.celeborn.common.protocol.RpcNameConstants
+
+abstract class MasterEndpointResolver(
+    private val conf: CelebornConf,
+    private val isWorker: Boolean) extends Logging {
+
+  private var masterEndpointName: Option[String] = None
+
+  protected var activeMasterEndpoints: Option[List[String]] = None
+
+  protected val updated = new AtomicBoolean(false)
+
+  if (isWorker && conf.internalPortEnabled) {
+    // For worker, we should use the internal endpoints if internal port is 
enabled.
+    this.masterEndpointName = Some(RpcNameConstants.MASTER_INTERNAL_EP)
+    resolve(conf.masterInternalEndpoints)
+  } else {
+    this.masterEndpointName = Some(RpcNameConstants.MASTER_EP)
+    resolve(conf.masterEndpoints)
+  }

Review Comment:
   We dont need `masterEndpointName` to be mutable, or an `Option`
   We can also drop `activeMasterEndpoints` field - have subclasses override 
`getActiveMasterEndpoints`
   
   ```suggestion
     private val masterEndpointName: String = {
       if (isWorker && conf.internalPortEnabled) {
         // For worker, we should use the internal endpoints if internal port 
is enabled.
         resolve(conf.masterInternalEndpoints)
         RpcNameConstants.MASTER_INTERNAL_EP
       } else {
         resolve(conf.masterEndpoints)
         RpcNameConstants.MASTER_EP
       }
     }
   
     protected val updated = new AtomicBoolean(false)
   ```



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