From 00dbec8db6ac91668f7c87f42fc40ee749f08545 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sun, 30 Apr 2023 19:56:36 +0800 Subject: [PATCH 1/9] YARN-11470. FederationStateStoreFacade Cache Support Guava Cache. --- .../cache/FederationGuavaCache.java | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java new file mode 100644 index 0000000000000..44d82a777bb18 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java @@ -0,0 +1,116 @@ +/** + * 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.hadoop.yarn.server.federation.cache; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.thirdparty.com.google.common.cache.Cache; +import org.apache.hadoop.thirdparty.com.google.common.cache.CacheBuilder; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.server.federation.store.FederationStateStore; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class FederationGuavaCache extends FederationCache { + + private Cache> cache; + + private int cacheTimeToLive; + + private String className = this.getClass().getSimpleName(); + + private boolean isCachingEnabled = false; + + @Override + public boolean isCachingEnabled() { + return isCachingEnabled; + } + + @Override + public void initCache(Configuration pConf, FederationStateStore pStateStore) { + // Picking the JCache provider from classpath, need to make sure there's + // no conflict or pick up a specific one in the future. + cacheTimeToLive = pConf.getInt(YarnConfiguration.FEDERATION_CACHE_TIME_TO_LIVE_SECS, + YarnConfiguration.DEFAULT_FEDERATION_CACHE_TIME_TO_LIVE_SECS); + if (cacheTimeToLive <= 0) { + isCachingEnabled = false; + return; + } + this.setStateStore(pStateStore); + + // Initialize Cache. + cache = CacheBuilder.newBuilder().expireAfterWrite(cacheTimeToLive, + TimeUnit.MILLISECONDS).build(); + isCachingEnabled = true; + } + + @Override + public void clearCache() { + cache.invalidateAll(); + cache = null; + } + + @Override + public Map getSubClusters(boolean filterInactiveSubClusters) throws YarnException { + final String cacheKey = buildCacheKey(className, GET_SUBCLUSTERS_CACHEID, + Boolean.toString(filterInactiveSubClusters)); + CacheRequest cacheRequest = cache.getIfPresent(cacheKey); + if (cacheRequest == null) { + cacheRequest = buildGetSubClustersCacheRequest(className, filterInactiveSubClusters); + cache.put(cacheKey, cacheRequest); + } + return buildSubClusterInfoMap(cacheRequest); + } + + @Override + public Map getPoliciesConfigurations() throws Exception { + final String cacheKey = buildCacheKey(className, GET_POLICIES_CONFIGURATIONS_CACHEID); + CacheRequest cacheRequest = cache.getIfPresent(cacheKey); + if(cacheRequest == null){ + cacheRequest = buildGetPoliciesConfigurationsCacheRequest(className); + cache.put(cacheKey, cacheRequest); + } + return buildPolicyConfigMap(cacheRequest); + } + + @Override + public SubClusterId getApplicationHomeSubCluster(ApplicationId appId) throws Exception { + final String cacheKey = buildCacheKey(className, GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, + appId.toString()); + CacheRequest cacheRequest = cache.getIfPresent(cacheKey); + if (cacheRequest == null) { + cacheRequest = buildGetApplicationHomeSubClusterRequest(className, appId); + cache.put(cacheKey, cacheRequest); + } + CacheResponse response = + ApplicationHomeSubClusterCacheResponse.class.cast(cacheRequest.getValue()); + return response.getItem(); + } + + @Override + public void removeSubCluster(boolean flushCache) { + final String cacheKey = buildCacheKey(className, GET_SUBCLUSTERS_CACHEID, + Boolean.toString(flushCache)); + cache.invalidate(cacheKey); + } +} From 62587d1ee9c08a0aa933c239dc0043b4758b000b Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Mon, 1 May 2023 09:25:06 +0800 Subject: [PATCH 2/9] YARN-11470. Fix CheckStyle. --- .../hadoop/yarn/conf/YarnConfiguration.java | 5 + .../cache/FederationGuavaCache.java | 9 +- .../utils/FederationStateStoreFacade.java | 7 +- .../federation/cache/TestFederationCache.java | 122 ++++++++++++++++++ 4 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index a3faec7171b44..42eaf589137f8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -4014,6 +4014,11 @@ public static boolean isAclEnabled(Configuration conf) { "org.apache.hadoop.yarn.server.federation.resolver." + "DefaultSubClusterResolverImpl"; + public static final String FEDERATION_FACADE_CACHE_CLASS = + FEDERATION_PREFIX + "facade.cache.class"; + public static final String DEFAULT_FEDERATION_FACADE_CACHE_CLASS = + "org.apache.hadoop.yarn.server.federation.cache.FederationJCache"; + // the maximum wait time for the first async heartbeat response public static final String FEDERATION_AMRMPROXY_HB_MAX_WAIT_MS = FEDERATION_PREFIX + "amrmproxy.hb.maximum.wait.ms"; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java index 44d82a777bb18..5ab0ef77218dd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationGuavaCache.java @@ -71,9 +71,10 @@ public void clearCache() { } @Override - public Map getSubClusters(boolean filterInactiveSubClusters) throws YarnException { + public Map getSubClusters(boolean filterInactiveSubClusters) + throws YarnException { final String cacheKey = buildCacheKey(className, GET_SUBCLUSTERS_CACHEID, - Boolean.toString(filterInactiveSubClusters)); + Boolean.toString(filterInactiveSubClusters)); CacheRequest cacheRequest = cache.getIfPresent(cacheKey); if (cacheRequest == null) { cacheRequest = buildGetSubClustersCacheRequest(className, filterInactiveSubClusters); @@ -96,7 +97,7 @@ public Map getPoliciesConfigurations() th @Override public SubClusterId getApplicationHomeSubCluster(ApplicationId appId) throws Exception { final String cacheKey = buildCacheKey(className, GET_APPLICATION_HOME_SUBCLUSTER_CACHEID, - appId.toString()); + appId.toString()); CacheRequest cacheRequest = cache.getIfPresent(cacheKey); if (cacheRequest == null) { cacheRequest = buildGetApplicationHomeSubClusterRequest(className, appId); @@ -110,7 +111,7 @@ public SubClusterId getApplicationHomeSubCluster(ApplicationId appId) throws Exc @Override public void removeSubCluster(boolean flushCache) { final String cacheKey = buildCacheKey(className, GET_SUBCLUSTERS_CACHEID, - Boolean.toString(flushCache)); + Boolean.toString(flushCache)); cache.invalidate(cacheKey); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java index 6597533117e3a..9d3b3a6f8384d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java @@ -132,8 +132,11 @@ private void initializeFacadeInternal(Configuration config) { SubClusterResolver.class); this.subclusterResolver.load(); - federationCache = new FederationJCache(); - federationCache.initCache(config, stateStore); + this.federationCache = createInstance(conf, + YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, + YarnConfiguration.DEFAULT_FEDERATION_FACADE_CACHE_CLASS, + FederationCache.class); + this.federationCache.initCache(config, stateStore); } catch (YarnException ex) { LOG.error("Failed to initialize the FederationStateStoreFacade object", ex); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java new file mode 100644 index 0000000000000..88d435b1fdfde --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java @@ -0,0 +1,122 @@ +/** + * 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.hadoop.yarn.server.federation.cache; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.server.federation.store.FederationStateStore; +import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; +import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade; +import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +/** + * Unit tests for FederationCache. + */ +@RunWith(Parameterized.class) +public class TestFederationCache { + + @Parameterized.Parameters + public static Collection getParameters() { + return Arrays.asList( + new String[][] { { "org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache" }, + { "org.apache.hadoop.yarn.server.federation.cache.FederationJCache" } }); + } + + private final long clusterTs = System.currentTimeMillis(); + private final int numSubClusters = 3; + private final int numApps = 5; + private final int numQueues = 2; + + private Configuration conf; + private FederationStateStore stateStore; + private FederationStateStoreTestUtil stateStoreTestUtil; + private FederationStateStoreFacade facade = FederationStateStoreFacade.getInstance(); + + public TestFederationCache(String cacheClassName) { + conf = new Configuration(); + conf.setInt(YarnConfiguration.FEDERATION_CACHE_TIME_TO_LIVE_SECS, 1); + conf.set(YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, cacheClassName); + } + + @Before + public void setUp() throws IOException, YarnException { + stateStore = new MemoryFederationStateStore(); + stateStore.init(conf); + facade.reinitialize(stateStore, conf); + // hydrate the store + stateStoreTestUtil = new FederationStateStoreTestUtil(stateStore); + stateStoreTestUtil.registerSubClusters(numSubClusters); + stateStoreTestUtil.addAppsHomeSC(clusterTs, numApps); + stateStoreTestUtil.addPolicyConfigs(numQueues); + } + + @After + public void tearDown() throws Exception { + stateStore.close(); + stateStore = null; + } + + @Test + public void testGetSubCluster() throws YarnException { + for (int i = 0; i < numSubClusters; i++) { + SubClusterId subClusterId = + SubClusterId.newInstance(FederationStateStoreTestUtil.SC_PREFIX + i); + SubClusterInfo expectedSubCluster = stateStoreTestUtil.querySubClusterInfo(subClusterId); + SubClusterInfo cachedSubCluster = facade.getSubCluster(subClusterId); + assertEquals(expectedSubCluster, cachedSubCluster); + } + } + + @Test + public void testGetPoliciesConfigurations() throws YarnException { + Map queuePolicies = + facade.getPoliciesConfigurations(); + for (String queue : queuePolicies.keySet()) { + SubClusterPolicyConfiguration expectedPC = stateStoreTestUtil.queryPolicyConfiguration(queue); + SubClusterPolicyConfiguration cachedPC = queuePolicies.get(queue); + assertEquals(expectedPC, cachedPC); + } + } + + @Test + public void testGetHomeSubClusterForApp() throws YarnException { + for (int i = 0; i < numApps; i++) { + ApplicationId appId = ApplicationId.newInstance(clusterTs, i); + SubClusterId expectedSC = stateStoreTestUtil.queryApplicationHomeSC(appId); + SubClusterId cachedPC = facade.getApplicationHomeSubCluster(appId); + assertEquals(expectedSC, cachedPC); + } + } +} From 9609a097c6bcebd234f525586d6958359cb583bd Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Mon, 1 May 2023 16:16:19 +0800 Subject: [PATCH 3/9] YARN-11470. Fix CheckStyle. --- .../src/main/resources/yarn-default.xml | 9 ++++++ .../federation/cache/TestFederationCache.java | 28 +++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index 4fc414f0e01b4..a51fe8b22e9fc 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -5193,4 +5193,13 @@ 1000 + + + Specifies the class name of the cache implementation in YARN FederationCache. + By default, this property is org.apache.hadoop.yarn.server.federation.cache.FederationJCache. + + yarn.federation.facade.cache.class + org.apache.hadoop.yarn.server.federation.cache.FederationJCache + + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java index 88d435b1fdfde..92d05cb1b1011 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java @@ -50,8 +50,8 @@ public class TestFederationCache { @Parameterized.Parameters public static Collection getParameters() { return Arrays.asList( - new String[][] { { "org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache" }, - { "org.apache.hadoop.yarn.server.federation.cache.FederationJCache" } }); + new String[][] { {"org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache"}, + {"org.apache.hadoop.yarn.server.federation.cache.FederationJCache"} }); } private final long clusterTs = System.currentTimeMillis(); @@ -91,11 +91,11 @@ public void tearDown() throws Exception { @Test public void testGetSubCluster() throws YarnException { for (int i = 0; i < numSubClusters; i++) { - SubClusterId subClusterId = - SubClusterId.newInstance(FederationStateStoreTestUtil.SC_PREFIX + i); - SubClusterInfo expectedSubCluster = stateStoreTestUtil.querySubClusterInfo(subClusterId); - SubClusterInfo cachedSubCluster = facade.getSubCluster(subClusterId); - assertEquals(expectedSubCluster, cachedSubCluster); + SubClusterId subClusterId = + SubClusterId.newInstance(FederationStateStoreTestUtil.SC_PREFIX + i); + SubClusterInfo expectedSubCluster = stateStoreTestUtil.querySubClusterInfo(subClusterId); + SubClusterInfo cachedSubCluster = facade.getSubCluster(subClusterId); + assertEquals(expectedSubCluster, cachedSubCluster); } } @@ -104,19 +104,19 @@ public void testGetPoliciesConfigurations() throws YarnException { Map queuePolicies = facade.getPoliciesConfigurations(); for (String queue : queuePolicies.keySet()) { - SubClusterPolicyConfiguration expectedPC = stateStoreTestUtil.queryPolicyConfiguration(queue); - SubClusterPolicyConfiguration cachedPC = queuePolicies.get(queue); - assertEquals(expectedPC, cachedPC); + SubClusterPolicyConfiguration expectedPC = stateStoreTestUtil.queryPolicyConfiguration(queue); + SubClusterPolicyConfiguration cachedPC = queuePolicies.get(queue); + assertEquals(expectedPC, cachedPC); } } @Test public void testGetHomeSubClusterForApp() throws YarnException { for (int i = 0; i < numApps; i++) { - ApplicationId appId = ApplicationId.newInstance(clusterTs, i); - SubClusterId expectedSC = stateStoreTestUtil.queryApplicationHomeSC(appId); - SubClusterId cachedPC = facade.getApplicationHomeSubCluster(appId); - assertEquals(expectedSC, cachedPC); + ApplicationId appId = ApplicationId.newInstance(clusterTs, i); + SubClusterId expectedSC = stateStoreTestUtil.queryApplicationHomeSC(appId); + SubClusterId cachedPC = facade.getApplicationHomeSubCluster(appId); + assertEquals(expectedSC, cachedPC); } } } From ee634de982706077dbee05a8b6cbe33f87e04e6d Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Mon, 1 May 2023 20:42:43 +0800 Subject: [PATCH 4/9] YARN-11470. Fix CheckStyle. --- .../server/federation/utils/FederationStateStoreFacade.java | 1 - .../yarn/server/federation/cache/TestFederationCache.java | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java index 9d3b3a6f8384d..1050b14c02ca8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java @@ -44,7 +44,6 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.server.federation.cache.FederationCache; -import org.apache.hadoop.yarn.server.federation.cache.FederationJCache; import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils; import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException; import org.apache.hadoop.yarn.server.federation.resolver.SubClusterResolver; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java index 92d05cb1b1011..89e64ec28cf67 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java @@ -49,9 +49,9 @@ public class TestFederationCache { @Parameterized.Parameters public static Collection getParameters() { - return Arrays.asList( - new String[][] { {"org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache"}, - {"org.apache.hadoop.yarn.server.federation.cache.FederationJCache"} }); + String federationGuavaCacheClass = FederationGuavaCache.class.getName(); + String federationJCacheClass = FederationJCache.class.getName(); + return Arrays.asList(new String[][] {{federationGuavaCacheClass}, {federationJCacheClass}}); } private final long clusterTs = System.currentTimeMillis(); From 8425562c65900b67063a252c3fa6578e719ebac2 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Tue, 2 May 2023 16:54:46 +0800 Subject: [PATCH 5/9] YARN-11470. Fix CheckStyle. --- .../hadoop/yarn/conf/YarnConfiguration.java | 2 +- .../src/main/resources/yarn-default.xml | 2 +- .../utils/FederationStateStoreFacade.java | 3 +++ .../src/site/markdown/Federation.md | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 42eaf589137f8..3990eedfae9d7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -4015,7 +4015,7 @@ public static boolean isAclEnabled(Configuration conf) { + "DefaultSubClusterResolverImpl"; public static final String FEDERATION_FACADE_CACHE_CLASS = - FEDERATION_PREFIX + "facade.cache.class"; + FEDERATION_PREFIX + "cache.class"; public static final String DEFAULT_FEDERATION_FACADE_CACHE_CLASS = "org.apache.hadoop.yarn.server.federation.cache.FederationJCache"; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index a51fe8b22e9fc..8ba2834e47934 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -5198,7 +5198,7 @@ Specifies the class name of the cache implementation in YARN FederationCache. By default, this property is org.apache.hadoop.yarn.server.federation.cache.FederationJCache. - yarn.federation.facade.cache.class + yarn.federation.cache.class org.apache.hadoop.yarn.server.federation.cache.FederationJCache diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java index 1050b14c02ca8..3ca70e7f4805a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java @@ -131,6 +131,9 @@ private void initializeFacadeInternal(Configuration config) { SubClusterResolver.class); this.subclusterResolver.load(); + // We check the configuration of Cache, + // if the configuration is null, set it to FederationJCache + this.federationCache = createInstance(conf, YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, YarnConfiguration.DEFAULT_FEDERATION_FACADE_CACHE_CLASS, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md index 3f7acee2d97a1..bdd9e5d33930e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md @@ -292,6 +292,7 @@ Optional: |`yarn.router.submit.interval.time` | `10ms` | The interval between two retry, the default value is 10ms. | |`yarn.federation.statestore.max-connections` | `10` | This is the maximum number of parallel connections each Router makes to the state-store. | |`yarn.federation.cache-ttl.secs` | `60` | The Router caches informations, and this is the time to leave before the cache is invalidated. | +|`yarn.federation.cache.class` | `org.apache.hadoop.yarn.server.federation.cache.FederationJCache` | The Router caches informations, We can configure the Cache implementation and the default implementation is FederationJCache.| |`yarn.router.webapp.interceptor-class.pipeline` | `org.apache.hadoop.yarn.server.router.webapp.FederationInterceptorREST` | A comma-separated list of interceptor classes to be run at the router when interfacing with the client via REST interface. The last step of this pipeline must be the Federation Interceptor REST. | Security: @@ -313,6 +314,22 @@ To enable cross-origin support (CORS) for the Yarn Router, please set the follow | `hadoop.http.filter.initializers` | `org.apache.hadoop.security.HttpCrossOriginFilterInitializer` | Optional. Set the filter to HttpCrossOriginFilterInitializer, Configure this parameter in core-site.xml. | | `yarn.router.webapp.cross-origin.enabled` | `true` | Optional. Enable/disable CORS filter.Configure this parameter in yarn-site.xml. | +Cache: + +Cache is not enabled by default. When we set the `yarn.federation.cache-ttl.secs` parameter and its value is greater than 0, Cache will be enabled. +We currently provide two Cache implementations: `JCache` and `GuavaCache`. + +> JCache + + We used `geronimo-jcache`,`geronimo-jcache` is an implementation of the Java Caching API (JSR-107) specification provided by the Apache Geronimo project. + It defines a standardized implementation of the JCache API, allowing developers to use the same API to access different caching implementations. + In YARN Federation we use a combination of `geronimo-jcache` and `Ehcache`. + If we want to use JCache, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationJCache`. + +> GuavaCache + + This is a Cache implemented based on the Guava framework. + If we want to use it, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache`. ###ON NMs: From 0039781b66cb1db6fb748635a4d0c03d4dc8bfe4 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Tue, 2 May 2023 22:35:29 +0800 Subject: [PATCH 6/9] YARN-11470. Fix CheckStyle. --- .../hadoop-yarn-site/src/site/markdown/Federation.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md index bdd9e5d33930e..137e78335e158 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md @@ -321,15 +321,15 @@ We currently provide two Cache implementations: `JCache` and `GuavaCache`. > JCache - We used `geronimo-jcache`,`geronimo-jcache` is an implementation of the Java Caching API (JSR-107) specification provided by the Apache Geronimo project. - It defines a standardized implementation of the JCache API, allowing developers to use the same API to access different caching implementations. - In YARN Federation we use a combination of `geronimo-jcache` and `Ehcache`. - If we want to use JCache, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationJCache`. +We used `geronimo-jcache`,`geronimo-jcache` is an implementation of the Java Caching API (JSR-107) specification provided by the Apache Geronimo project. +It defines a standardized implementation of the JCache API, allowing developers to use the same API to access different caching implementations. +In YARN Federation we use a combination of `geronimo-jcache` and `Ehcache`. +If we want to use JCache, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationJCache`. > GuavaCache - This is a Cache implemented based on the Guava framework. - If we want to use it, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache`. +This is a Cache implemented based on the Guava framework. +If we want to use it, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationGuavaCache`. ###ON NMs: From 6b75349eec655cd9ebf0093a11083df6a176ce83 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Tue, 2 May 2023 22:45:31 +0800 Subject: [PATCH 7/9] YARN-11470. Fix CheckStyle. --- .../yarn/server/federation/utils/FederationStateStoreFacade.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java index 3ca70e7f4805a..b4be7ca62c430 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/utils/FederationStateStoreFacade.java @@ -133,7 +133,6 @@ private void initializeFacadeInternal(Configuration config) { // We check the configuration of Cache, // if the configuration is null, set it to FederationJCache - this.federationCache = createInstance(conf, YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, YarnConfiguration.DEFAULT_FEDERATION_FACADE_CACHE_CLASS, From e3852b143ec68707ab86ffbe32917dc6f84f8d7c Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Wed, 3 May 2023 15:46:40 +0800 Subject: [PATCH 8/9] YARN-11470. Fix CheckStyle. --- .../hadoop-yarn-site/src/site/markdown/Federation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md index 137e78335e158..c5fcef8b2e329 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/Federation.md @@ -316,7 +316,7 @@ To enable cross-origin support (CORS) for the Yarn Router, please set the follow Cache: -Cache is not enabled by default. When we set the `yarn.federation.cache-ttl.secs` parameter and its value is greater than 0, Cache will be enabled. +Cache is not enabled by default. When we set the `yarn.federation.cache-ttl.secs` parameter and its value is greater than 0, Cache will be enabled. We currently provide two Cache implementations: `JCache` and `GuavaCache`. > JCache From e9352f7493ce7119ed687f6509bfacae55977285 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Thu, 4 May 2023 23:10:19 +0800 Subject: [PATCH 9/9] YARN-11470. Fix CheckStyle. --- .../server/federation/cache/TestFederationCache.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java index 89e64ec28cf67..0e77bcfc84504 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/cache/TestFederationCache.java @@ -48,10 +48,8 @@ public class TestFederationCache { @Parameterized.Parameters - public static Collection getParameters() { - String federationGuavaCacheClass = FederationGuavaCache.class.getName(); - String federationJCacheClass = FederationJCache.class.getName(); - return Arrays.asList(new String[][] {{federationGuavaCacheClass}, {federationJCacheClass}}); + public static Collection getParameters() { + return Arrays.asList(new Class[][] {{FederationGuavaCache.class}, {FederationJCache.class}}); } private final long clusterTs = System.currentTimeMillis(); @@ -64,10 +62,11 @@ public static Collection getParameters() { private FederationStateStoreTestUtil stateStoreTestUtil; private FederationStateStoreFacade facade = FederationStateStoreFacade.getInstance(); - public TestFederationCache(String cacheClassName) { + public TestFederationCache(Class cacheClassName) { conf = new Configuration(); conf.setInt(YarnConfiguration.FEDERATION_CACHE_TIME_TO_LIVE_SECS, 1); - conf.set(YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, cacheClassName); + conf.setClass(YarnConfiguration.FEDERATION_FACADE_CACHE_CLASS, + cacheClassName, FederationCache.class); } @Before