From 00d483d6de2c1057e62939631ab1e5339cea1b57 Mon Sep 17 00:00:00 2001 From: GuoPhilipse <46367746+GuoPhilipse@users.noreply.github.com> Date: Wed, 8 Dec 2021 20:21:48 +0800 Subject: [PATCH] HDFS-16324. Fix error log in BlockManagerSafeMode (#3661) Reviewed-by: tomscut Reviewed-by: Ayush Saxena Signed-off-by: Akira Ajisaka --- .../blockmanagement/BlockManagerSafeMode.java | 4 ++-- .../blockmanagement/TestBlockManagerSafeMode.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java index d825c5ecb31..de26929c616 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java @@ -649,8 +649,8 @@ class BlockManagerSafeMode { DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT); if (recheckInterval < 1) { LOG.warn("Invalid value for " + - DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT + - ".Should be greater than 0, but is {}", recheckInterval); + DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY + + ". Should be greater than 0, but is {}", recheckInterval); recheckInterval = DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT; } LOG.info("Using {} as SafeModeMonitor Interval", recheckInterval); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java index 291b7c62b8e..d32cde83473 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java @@ -30,6 +30,7 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.Whitebox; +import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; @@ -242,6 +243,20 @@ public class TestBlockManagerSafeMode { assertTrue(content.contains("Using 3000 as SafeModeMonitor Interval")); } + @Test(timeout = 20000) + public void testCheckSafeMode10(){ + Configuration conf = new HdfsConfiguration(); + conf.setLong(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, -1); + GenericTestUtils.LogCapturer logs = + GenericTestUtils.LogCapturer.captureLogs(BlockManagerSafeMode.LOG); + BlockManagerSafeMode blockManagerSafeMode = new BlockManagerSafeMode(bm, + fsn, true, conf); + String content = logs.getOutput(); + Assertions.assertThat(content).contains("Invalid value for " + + DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY + + ". Should be greater than 0, but is -1"); + } + /** * Test that the block safe increases up to block threshold. *