From 2f126846ee5acbb232f2d5dea279c8ad5b7b9d5c Mon Sep 17 00:00:00 2001 From: zhanghaobo Date: Thu, 19 Dec 2024 16:13:32 +0800 Subject: [PATCH] HDFS-17694.RBF:Make get datanodes reports configurable. --- .../metrics/NamenodeBeanMetrics.java | 35 ++++++++++++------- .../federation/router/RBFConfigKeys.java | 3 ++ .../src/main/resources/hdfs-rbf-default.xml | 9 +++++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java index e6f41c3107a7c..2d85ef96a583e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java @@ -93,7 +93,8 @@ public class NamenodeBeanMetrics /** Timeout to get the DN report. */ private final long dnReportTimeOut; /** DN type -> full DN report in JSON. */ - private final LoadingCache dnCache; + private LoadingCache dnCache = null; + private final boolean dnReportEnable; public NamenodeBeanMetrics(Router router) { @@ -139,18 +140,23 @@ public NamenodeBeanMetrics(Router router) { this.dnReportTimeOut = conf.getTimeDuration( RBFConfigKeys.DN_REPORT_TIME_OUT, RBFConfigKeys.DN_REPORT_TIME_OUT_MS_DEFAULT, TimeUnit.MILLISECONDS); - long dnCacheExpire = conf.getTimeDuration( - RBFConfigKeys.DN_REPORT_CACHE_EXPIRE, - RBFConfigKeys.DN_REPORT_CACHE_EXPIRE_MS_DEFAULT, TimeUnit.MILLISECONDS); - this.dnCache = CacheBuilder.newBuilder() - .expireAfterWrite(dnCacheExpire, TimeUnit.MILLISECONDS) - .build( - new CacheLoader() { - @Override - public String load(DatanodeReportType type) throws Exception { - return getNodesImpl(type); - } - }); + this.dnReportEnable = conf.getBoolean(RBFConfigKeys.DFS_ROUTER_DN_REPORT_ENABLE_KEY, + RBFConfigKeys.DFS_ROUTER_DN_REPORT_ENABLE_DEFAULT); + if (dnReportEnable) { + long dnCacheExpire = conf.getTimeDuration( + RBFConfigKeys.DN_REPORT_CACHE_EXPIRE, + RBFConfigKeys.DN_REPORT_CACHE_EXPIRE_MS_DEFAULT, TimeUnit.MILLISECONDS); + this.dnCache = CacheBuilder.newBuilder() + .expireAfterWrite(dnCacheExpire, TimeUnit.MILLISECONDS) + .build( + new CacheLoader() { + @Override + public String load(DatanodeReportType type) throws Exception { + return getNodesImpl(type); + } + }); + } + } /** @@ -458,6 +464,9 @@ public String getDecomNodes() { * @return JSON with the nodes. */ private String getNodes(final DatanodeReportType type) { + if (!dnReportEnable) { + return "N/A"; + } try { return this.dnCache.get(type); } catch (ExecutionException e) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RBFConfigKeys.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RBFConfigKeys.java index 64f27bd3ba32e..67fb0ae902aa5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RBFConfigKeys.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RBFConfigKeys.java @@ -375,6 +375,9 @@ public class RBFConfigKeys extends CommonConfigurationKeysPublic { public static final String DFS_ROUTER_ENABLE_GET_DN_USAGE_KEY = FEDERATION_ROUTER_PREFIX + "enable.get.dn.usage"; public static final boolean DFS_ROUTER_ENABLE_GET_DN_USAGE_DEFAULT = true; + public static final String DFS_ROUTER_DN_REPORT_ENABLE_KEY = + FEDERATION_ROUTER_PREFIX + "dn.report.enable"; + public static final boolean DFS_ROUTER_DN_REPORT_ENABLE_DEFAULT = true; // HDFS Router-based federation quota public static final String DFS_ROUTER_QUOTA_ENABLE = diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/resources/hdfs-rbf-default.xml b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/resources/hdfs-rbf-default.xml index 26b89ce0313fd..ea307ae190e7f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/resources/hdfs-rbf-default.xml +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/resources/hdfs-rbf-default.xml @@ -205,6 +205,15 @@ + + dfs.federation.router.dn.report.enable + true + + If false, the getLiveNodes|getDeadNodes|getDecomNodes methods in NamenodeBeanMetrics will + return "N/A", else will return the cached result collecting from downstream nameservices. + + + dfs.federation.router.metrics.class org.apache.hadoop.hdfs.server.federation.metrics.FederationRPCPerformanceMonitor