You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2022/08/04 17:20:36 UTC

[GitHub] [hadoop] goiri commented on a diff in pull request #4701: YARN-10885. add FederationStateStoreFacade#getApplicationHomeSubCluster use JCache.

goiri commented on code in PR #4701:
URL: https://github.com/apache/hadoop/pull/4701#discussion_r938061543


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java:
##########
@@ -376,10 +378,20 @@ public void updateApplicationHomeSubCluster(
    */
   public SubClusterId getApplicationHomeSubCluster(ApplicationId appId)
       throws YarnException {
-    GetApplicationHomeSubClusterResponse response =
-        stateStore.getApplicationHomeSubCluster(
+    try {
+      if (isCachingEnabled()) {
+        Map<ApplicationId, SubClusterId> cacheAppSubCluster =
+            (Map<ApplicationId, SubClusterId>)
+                cache.get(buildGetApplicationHomeSubClusterRequest(appId.toString()));

Review Comment:
   Extract things a little.
   buildGetApplicationHomeSubClusterRequest could also take ApplicationId.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/TestFederationStateStoreFacade.java:
##########
@@ -169,7 +169,7 @@ public void testGetPoliciesConfigurations() throws YarnException {
   }
 
   @Test
-  public void testGetHomeSubClusterForApp() throws YarnException {
+  public void getApplicationHomeSubCluster() throws YarnException {

Review Comment:
   I think we use test for the method name



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java:
##########
@@ -513,6 +525,31 @@ public Map<String, SubClusterPolicyConfiguration> invoke(
     return cacheRequest;
   }
 
+  private Map<ApplicationId, SubClusterId> buildApplicationSubClusterMap(
+      GetApplicationHomeSubClusterResponse response) {
+    ApplicationHomeSubCluster applicationHomeSubCluster = response.getApplicationHomeSubCluster();
+    SubClusterId subClusterId = applicationHomeSubCluster.getHomeSubCluster();
+    ApplicationId applicationId = applicationHomeSubCluster.getApplicationId();
+    Map<ApplicationId, SubClusterId> appSubCluster = new HashMap<>();
+    appSubCluster.put(applicationId, subClusterId);
+    return appSubCluster;
+  }
+
+  private Object buildGetApplicationHomeSubClusterRequest(String appId) {
+    final String cacheKey = buildCacheKey(getClass().getSimpleName(),
+        GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, appId);
+    CacheRequest<String, Map<ApplicationId, SubClusterId>> cacheRequest =
+        new CacheRequest<>(cacheKey,
+            input -> {
+              ApplicationId applicationId = ApplicationId.fromString(appId);
+              GetApplicationHomeSubClusterResponse response =
+                  stateStore.getApplicationHomeSubCluster(
+                  GetApplicationHomeSubClusterRequest.newInstance(applicationId));

Review Comment:
   Let's create a method that takes string and does the appId transformation inside.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java:
##########
@@ -513,6 +525,31 @@ public Map<String, SubClusterPolicyConfiguration> invoke(
     return cacheRequest;
   }
 
+  private Map<ApplicationId, SubClusterId> buildApplicationSubClusterMap(
+      GetApplicationHomeSubClusterResponse response) {
+    ApplicationHomeSubCluster applicationHomeSubCluster = response.getApplicationHomeSubCluster();
+    SubClusterId subClusterId = applicationHomeSubCluster.getHomeSubCluster();
+    ApplicationId applicationId = applicationHomeSubCluster.getApplicationId();
+    Map<ApplicationId, SubClusterId> appSubCluster = new HashMap<>();
+    appSubCluster.put(applicationId, subClusterId);
+    return appSubCluster;
+  }
+
+  private Object buildGetApplicationHomeSubClusterRequest(String appId) {
+    final String cacheKey = buildCacheKey(getClass().getSimpleName(),
+        GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, appId);
+    CacheRequest<String, Map<ApplicationId, SubClusterId>> cacheRequest =
+        new CacheRequest<>(cacheKey,
+            input -> {
+              ApplicationId applicationId = ApplicationId.fromString(appId);
+              GetApplicationHomeSubClusterResponse response =
+                  stateStore.getApplicationHomeSubCluster(
+                  GetApplicationHomeSubClusterRequest.newInstance(applicationId));

Review Comment:
   The indentation is not correct.



-- 
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: common-issues-unsubscribe@hadoop.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org