mridulm commented on code in PR #2363:
URL: 
https://github.com/apache/incubator-celeborn/pull/2363#discussion_r1516662852


##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala:
##########
@@ -1099,6 +1103,26 @@ private[celeborn] class Master(
     }.asJava
   }
 
+  private def handleRequestForApplicationMeta(
+      context: RpcCallContext,
+      pb: PbApplicationMetaRequest): Unit = {
+    val appId = pb.getAppId
+    logDebug(
+      s"Handling request for application meta info $appId.")

Review Comment:
   super nit: single line for logDebug ? :-)
   
   ```suggestion
       logDebug(s"Handling request for application meta info $appId.")
   ```



##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala:
##########
@@ -1099,6 +1103,26 @@ private[celeborn] class Master(
     }.asJava
   }
 
+  private def handleRequestForApplicationMeta(
+      context: RpcCallContext,
+      pb: PbApplicationMetaRequest): Unit = {
+    val appId = pb.getAppId
+    logDebug(
+      s"Handling request for application meta info $appId.")
+    if (!secretRegistry.isRegistered(appId)) {
+      logWarning(s"Could not find the application meta of $appId.")
+      context.sendFailure(new CelebornException(s"$appId is not registered."))
+    } else {
+      val pbApplicationMeta = PbApplicationMeta.newBuilder()
+        .setAppId(appId)
+        .setSecret(secretRegistry.getSecretKey(appId))
+        .build()

Review Comment:
   There is a potential race here between `isRegistered` and `getSecretKey`, 
right ?
   Do we want to do `getSecretKey` always and use non-null value to distinguish 
whether it is registered ?



##########
worker/src/main/java/org/apache/celeborn/service/deploy/worker/WorkerSecretRegistryImpl.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.service.deploy.worker;
+
+import com.google.common.base.Preconditions;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.celeborn.common.client.MasterClient;
+import org.apache.celeborn.common.network.sasl.SecretRegistry;
+import org.apache.celeborn.common.protocol.PbApplicationMeta;
+import org.apache.celeborn.common.protocol.PbApplicationMetaRequest;
+
+/** A secret registry that fetches the secret from the master if it is not 
found locally. */
+public class WorkerSecretRegistryImpl implements SecretRegistry {
+  private static final Logger LOG = 
LoggerFactory.getLogger(WorkerSecretRegistryImpl.class);
+
+  // MasterClient is created in Worker after the secret registry is created 
and this order currently
+  // cannot be changed.
+  // So, we need to set the masterClient after the secret registry is created.
+  private MasterClient masterClient;
+  private final Cache<String, String> secretCache;
+
+  public WorkerSecretRegistryImpl(long maxCacheSize) {
+    secretCache = CacheBuilder.newBuilder().maximumSize(maxCacheSize).build();
+  }
+
+  /** Gets an appropriate SASL secret key for the given appId. */
+  @Override
+  public String getSecretKey(String appId) {
+    String secret = secretCache.getIfPresent(appId);
+    if (secret == null) {
+      LOG.debug("Missing the secret for {}; fetching it from the master", 
appId);
+      PbApplicationMetaRequest pbApplicationMetaRequest =
+          PbApplicationMetaRequest.newBuilder().setAppId(appId).build();
+      try {
+        PbApplicationMeta pbApplicationMeta =
+            masterClient.askSync(pbApplicationMetaRequest, 
PbApplicationMeta.class);
+        LOG.debug(
+            "Successfully fetched the application meta info for " + appId + " 
from the master");
+        register(pbApplicationMeta.getAppId(), pbApplicationMeta.getSecret());
+        secret = pbApplicationMeta.getSecret();
+      } catch (Throwable e) {
+        // We catch Throwable here because masterClient.askSync declares it in 
its definition.
+        // If the secret is null, the authentication will fail so just logging 
the exception here.
+        LOG.error("Failed to fetch the application meta info for {} from the 
master", appId, e);
+      }
+    }

Review Comment:
   Do we want to move this into a CacheLoader for the cache ?



##########
common/src/main/scala/org/apache/celeborn/common/CelebornConf.scala:
##########
@@ -4632,4 +4634,12 @@ object CelebornConf extends Logging {
       .version("0.5.0")
       .intConf
       .createWithDefault(8)
+
+  val WORKER_APPLICATION_REGISTRY_CACHE_SIZE: ConfigEntry[Int] =
+    buildConf("celeborn.worker.applicationRegistryCache.size")
+      .categories("worker", "auth")
+      .doc("Cache size of the application registry on Workers.")
+      .version("0.5.0")
+      .intConf
+      .createWithDefault(10000)

Review Comment:
   To clarify, internally we would be overriding this to a much higher value 
... it essentially should be a reasonable approximation of max number of apps.
   If app is not found in cache, it will trigger a query to master.



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