This is an automated email from the ASF dual-hosted git repository. zanderxu pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new 0c209961f82 HDFS-17019. Optimize the logic for reconfigure slow peer enable for Namenode" (#5671) 0c209961f82 is described below commit 0c209961f82e1b5d1ba2bf8e886cf872fdb67993 Author: huhaiyang <huhaiyang...@126.com> AuthorDate: Thu Jun 8 10:05:49 2023 +0800 HDFS-17019. Optimize the logic for reconfigure slow peer enable for Namenode" (#5671) * HDFS-17019. Optimize the logic for reconfigure slow peer enable for Namenode --- .../hdfs/server/blockmanagement/DatanodeManager.java | 20 ++++++++++++++++---- .../server/namenode/TestNameNodeReconfigure.java | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index ed60f388d3f..22496167028 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -253,7 +253,6 @@ public class DatanodeManager { final boolean dataNodePeerStatsEnabledVal = conf.getBoolean(DFSConfigKeys.DFS_DATANODE_PEER_STATS_ENABLED_KEY, DFSConfigKeys.DFS_DATANODE_PEER_STATS_ENABLED_DEFAULT); - initSlowPeerTracker(conf, timer, dataNodePeerStatsEnabledVal); this.maxSlowPeerReportNodes = conf.getInt( DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY, DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_DEFAULT); @@ -261,9 +260,7 @@ public class DatanodeManager { DFSConfigKeys.DFS_NAMENODE_SLOWPEER_COLLECT_INTERVAL_KEY, DFSConfigKeys.DFS_NAMENODE_SLOWPEER_COLLECT_INTERVAL_DEFAULT, TimeUnit.MILLISECONDS); - if (slowPeerTracker.isSlowPeerTrackerEnabled()) { - startSlowPeerCollector(); - } + initSlowPeerTracker(conf, timer, dataNodePeerStatsEnabledVal); this.slowDiskTracker = dataNodeDiskStatsEnabled ? new SlowDiskTracker(conf, timer) : null; this.defaultXferPort = NetUtils.createSocketAddr( @@ -376,10 +373,16 @@ public class DatanodeManager { this.slowPeerTracker = dataNodePeerStatsEnabled ? new SlowPeerTracker(conf, timer) : new SlowPeerDisabledTracker(conf, timer); + if (slowPeerTracker.isSlowPeerTrackerEnabled()) { + startSlowPeerCollector(); + } else { + stopSlowPeerCollector(); + } } private void startSlowPeerCollector() { if (slowPeerCollectorDaemon != null) { + LOG.warn("Slow peers collection thread has been started."); return; } slowPeerCollectorDaemon = new Daemon(new Runnable() { @@ -402,9 +405,11 @@ public class DatanodeManager { } }); slowPeerCollectorDaemon.start(); + LOG.info("Slow peers collection thread start."); } public void stopSlowPeerCollector() { + LOG.info("Slow peers collection thread shutdown"); if (slowPeerCollectorDaemon == null) { return; } @@ -413,6 +418,8 @@ public class DatanodeManager { slowPeerCollectorDaemon.join(); } catch (InterruptedException e) { LOG.error("Slow peers collection thread did not shutdown", e); + } finally { + slowPeerCollectorDaemon = null; } } @@ -2270,4 +2277,9 @@ public class DatanodeManager { Preconditions.checkNotNull(slowPeerTracker, "slowPeerTracker should not be un-assigned"); slowPeerTracker.setMaxSlowPeersToReport(maxSlowPeersToReport); } + + @VisibleForTesting + public boolean isSlowPeerCollectorInitialized() { + return slowPeerCollectorDaemon == null; + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeReconfigure.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeReconfigure.java index 5573b1fa107..ec7717e503a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeReconfigure.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeReconfigure.java @@ -502,6 +502,7 @@ public class TestNameNodeReconfigure { assertFalse("SlowNode tracker is already enabled. It should be disabled by default", datanodeManager.getSlowPeerTracker().isSlowPeerTrackerEnabled()); + assertTrue(datanodeManager.isSlowPeerCollectorInitialized()); try { nameNode.reconfigurePropertyImpl(DFS_DATANODE_PEER_STATS_ENABLED_KEY, "non-boolean"); @@ -515,6 +516,7 @@ public class TestNameNodeReconfigure { nameNode.reconfigurePropertyImpl(DFS_DATANODE_PEER_STATS_ENABLED_KEY, "True"); assertTrue("SlowNode tracker is still disabled. Reconfiguration could not be successful", datanodeManager.getSlowPeerTracker().isSlowPeerTrackerEnabled()); + assertFalse(datanodeManager.isSlowPeerCollectorInitialized()); nameNode.reconfigurePropertyImpl(DFS_DATANODE_PEER_STATS_ENABLED_KEY, null); assertFalse("SlowNode tracker is still enabled. Reconfiguration could not be successful", --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org