[ 
https://issues.apache.org/jira/browse/YARN-10885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576994#comment-17576994
 ] 

ASF GitHub Bot commented on YARN-10885:
---------------------------------------

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


##########
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 +528,26 @@ public Map<String, SubClusterPolicyConfiguration> invoke(
     return cacheRequest;
   }
 
+  private Object buildGetApplicationHomeSubClusterRequest(ApplicationId 
applicationId) {
+    final String cacheKey = buildCacheKey(getClass().getSimpleName(),
+        GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, applicationId.toString());
+    CacheRequest<String, SubClusterId> cacheRequest =
+        new CacheRequest<>(
+            cacheKey,
+            input -> {
+              GetApplicationHomeSubClusterResponse response =
+                  stateStore.getApplicationHomeSubCluster(
+                      
GetApplicationHomeSubClusterRequest.newInstance(applicationId));

Review Comment:
   Extract the request and probably do indentation like:
   ```
       CacheRequest<String, SubClusterId> cacheRequest = new CacheRequest<>(
           cacheKey,
   ```



##########
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,23 @@ public void updateApplicationHomeSubCluster(
    */
   public SubClusterId getApplicationHomeSubCluster(ApplicationId appId)
       throws YarnException {
-    GetApplicationHomeSubClusterResponse response =
-        stateStore.getApplicationHomeSubCluster(
+    try {
+      if (isCachingEnabled()) {
+        Object value =
+            cache.get(buildGetApplicationHomeSubClusterRequest(appId));
+        if (value instanceof SubClusterId) {
+          return (SubClusterId) value;
+        } else {
+          throw new YarnException("Cannot be converted to SubClusterId.");

Review Comment:
   Maybe add the type of the original.



##########
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,23 @@ public void updateApplicationHomeSubCluster(
    */
   public SubClusterId getApplicationHomeSubCluster(ApplicationId appId)
       throws YarnException {
-    GetApplicationHomeSubClusterResponse response =
-        stateStore.getApplicationHomeSubCluster(
+    try {
+      if (isCachingEnabled()) {
+        Object value =

Review Comment:
   This fits in one line.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/utils/TestFederationStateStoreFacade.java:
##########
@@ -206,4 +210,27 @@ public void testAddApplicationHomeSubCluster() throws 
YarnException {
     Assert.assertEquals(subClusterId1, result);
   }
 
+  @Test
+  public void testGetApplicationHomeSubClusterCache() throws YarnException {
+    ApplicationId appId = ApplicationId.newInstance(clusterTs, numApps + 1);
+    SubClusterId subClusterId1 = SubClusterId.newInstance("Home1");
+
+    ApplicationHomeSubCluster appHomeSubCluster =
+        ApplicationHomeSubCluster.newInstance(appId, subClusterId1);
+    SubClusterId subClusterIdAdd =

Review Comment:
   One line?





> Make FederationStateStoreFacade#getApplicationHomeSubCluster use JCache
> -----------------------------------------------------------------------
>
>                 Key: YARN-10885
>                 URL: https://issues.apache.org/jira/browse/YARN-10885
>             Project: Hadoop YARN
>          Issue Type: Improvement
>            Reporter: chaosju
>            Assignee: fanshilun
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> Yarn Client getApplicationReport function may produce lots of zookeeper ops, 
> Its import to use the JCache that cache the mapping of  application and 
> subcluster id. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to