diff --git a/LICENSE-binary b/LICENSE-binary index c0258e9311..32f9f06ae1 100644 --- a/LICENSE-binary +++ b/LICENSE-binary @@ -226,6 +226,7 @@ com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.12.7 com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.12.7 com.fasterxml.uuid:java-uuid-generator:3.1.4 com.fasterxml.woodstox:woodstox-core:5.4.0 +com.github.ben-manes.caffeine:caffeine:2.9.3 com.github.davidmoten:rxjava-extras:0.8.0.17 com.github.stephenc.jcip:jcip-annotations:1.0-1 com.google:guice:4.0 diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index ba7631189a..0345925e99 100644 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -134,6 +134,7 @@ 2.0.3 3.8.2 1.1.1 + 2.9.3 4.0.3 10.14.2.0 6.2.1.jre7 @@ -1975,6 +1976,11 @@ + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + com.zaxxer HikariCP diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml index 1f762d3180..e768ad5e48 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml @@ -131,6 +131,20 @@ org.ehcache ehcache + + com.github.ben-manes.caffeine + caffeine + + + org.checkerframework + checker-qual + + + com.google.errorprone + error_prone_annotations + + + com.zaxxer HikariCP 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/FederationCaffeineCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationCaffeineCache.java new file mode 100644 index 0000000000..cbf3e9db3d --- /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/FederationCaffeineCache.java @@ -0,0 +1,131 @@ +/** + * 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 com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +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.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * CaffeineCache is a high-performance caching library for Java, offering better performance compared to Ehcache and Guava Cache. + * We are integrating this cache to store information about application and homesubclusters etc. + */ +public class FederationCaffeineCache extends FederationCache { + + private static final Logger LOG = LoggerFactory.getLogger(FederationCaffeineCache.class); + + private Cache cache; + + private int cacheTimeToLive; + private long cacheEntityNums; + + private String className = this.getClass().getSimpleName(); + + private boolean isCachingEnabled = false; + + @Override + public boolean isCachingEnabled() { + return isCachingEnabled; + } + + @Override + public void initCache(Configuration pConf, FederationStateStore pStateStore) { + cacheTimeToLive = pConf.getInt(YarnConfiguration.FEDERATION_CACHE_TIME_TO_LIVE_SECS, + YarnConfiguration.DEFAULT_FEDERATION_CACHE_TIME_TO_LIVE_SECS); + cacheEntityNums = pConf.getLong(YarnConfiguration.FEDERATION_CACHE_ENTITY_NUMS, + YarnConfiguration.DEFAULT_FEDERATION_CACHE_ENTITY_NUMS); + if (cacheTimeToLive <= 0) { + isCachingEnabled = false; + LOG.warn("Federation cache is not enabled. If we want to enable federation cache, " + + "we need to set yarn.federation.cache-ttl.secs greater than 0."); + return; + } + this.setStateStore(pStateStore); + + // Initialize Cache. + LOG.info("Creating a JCache Manager with name {}. " + + "Cache TTL Time = {} secs. Cache Entity Nums = {}.", className, cacheTimeToLive, + cacheEntityNums); + + this.cache = Caffeine.newBuilder().maximumSize(cacheEntityNums) + .expireAfterWrite(cacheTimeToLive, TimeUnit.SECONDS).build(); + } + + @Override + public void clearCache() { + this.cache.cleanUp(); + this.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); + } +} 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/FederationJCache.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationJCache.java index b4dbefe127..07f300e65f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationJCache.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/cache/FederationJCache.java @@ -91,7 +91,7 @@ public void initCache(Configuration pConf, FederationStateStore pStateStore) { @Override public void clearCache() { - + this.cache.clear(); this.cache = null; } 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 8e0f15802b..8873e60939 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,7 +49,8 @@ public class TestFederationCache { @Parameterized.Parameters public static Collection getParameters() { - return Arrays.asList(new Class[][] {{FederationGuavaCache.class}, {FederationJCache.class}}); + return Arrays.asList(new Class[][]{{FederationGuavaCache.class}, {FederationJCache.class}, + {FederationCaffeineCache.class}}); } private final long clusterTs = System.currentTimeMillis(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/pom.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/pom.xml index 7f3c711fe7..976c21e2dd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase/hadoop-yarn-server-timelineservice-hbase-common/pom.xml @@ -66,6 +66,10 @@ com.google.inject guice + + error_prone_annotations + com.google.errorprone + 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 3886f54041..fcb36c250c 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 @@ -536,7 +536,7 @@ To enable cross-origin support (CORS) for the Yarn Router, please set the follow #### How to configure Router Cache Cache is 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`. +We currently provide three Cache implementations: `JCache`, `GuavaCache`, `CaffeineCache` - JCache @@ -550,6 +550,12 @@ If we want to use JCache, we can configure `yarn.federation.cache.class` to `org 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`. +- CaffeineCache + +[CaffeineCache](https://github.com/ben-manes/caffeine) is a high-performance caching library for Java, offering better performance compared to Ehcache and Guava Cache. +If we want to use it, we can configure `yarn.federation.cache.class` to `org.apache.hadoop.yarn.server.federation.cache.FederationCaffeineCache`. + + #### How to configure Router AuditLog We can enable the AuditLog configuration for the Router and collect the AuditLog in a separate log file. We need to modify the configuration related to RouterAuditLog in the **conf/log4j.properties** file.