ayushtkn commented on a change in pull request #2831: URL: https://github.com/apache/hadoop/pull/2831#discussion_r606710952
########## File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java ########## @@ -640,7 +644,18 @@ private void reportStatus(String msg, boolean rightNow) { */ private class SafeModeMonitor implements Runnable { /** Interval in msec for checking safe mode. */ - private static final long RECHECK_INTERVAL = 1000; + private long recheckInterval; + + public SafeModeMonitor(Configuration conf) { + recheckInterval = conf.getLong( + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT); + if (recheckInterval < 1) { + LOG.warn("The current value of recheckInterval is {}, " + + "this variable should be a positive number.", recheckInterval); Review comment: Can you change the message as ```"Invalid value for " + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY + ". Should be greater than 0, but is {}", recheckInterval``` Please correct the syntax.... ########## File path: hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManagerSafeMode.java ########## @@ -640,7 +644,18 @@ private void reportStatus(String msg, boolean rightNow) { */ private class SafeModeMonitor implements Runnable { /** Interval in msec for checking safe mode. */ - private static final long RECHECK_INTERVAL = 1000; + private long recheckInterval; + + public SafeModeMonitor(Configuration conf) { + recheckInterval = conf.getLong( + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT); + if (recheckInterval < 1) { + LOG.warn("The current value of recheckInterval is {}, " + + "this variable should be a positive number.", recheckInterval); + recheckInterval = DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT; + } Review comment: Add a Log.info("Using {} as SafeModeMonitor Interval", recheckInterval) ########## File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManagerSafeMode.java ########## @@ -230,6 +232,50 @@ public void testCheckSafeMode8() throws Exception { assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus()); } + @Test(timeout = 20000) + public void testCheckSafeMode9() throws Exception { + Configuration conf = new HdfsConfiguration(); + try { + conf.setLong(DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, 3000); + bm = spy(new BlockManager(fsn, false, conf)); + doReturn(true).when(bm).isGenStampInFuture(any(Block.class)); + dn = spy(bm.getDatanodeManager()); + Whitebox.setInternalState(bm, "datanodeManager", dn); + // the datanode threshold is always met + when(dn.getNumLiveDataNodes()).thenReturn(DATANODE_NUM); + bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf); + bmSafeMode.activate(BLOCK_TOTAL); + Whitebox.setInternalState(bmSafeMode, "extension", Integer.MAX_VALUE); + setSafeModeStatus(BMSafeModeStatus.PENDING_THRESHOLD); + setBlockSafe(BLOCK_THRESHOLD); + bmSafeMode.checkSafeMode(); + + assertTrue(bmSafeMode.isInSafeMode()); + assertEquals(BMSafeModeStatus.EXTENSION, getSafeModeStatus()); + + GenericTestUtils.waitFor(new Supplier<Boolean>() { + @Override + public Boolean get() { + Whitebox.setInternalState(bmSafeMode, "extension", 0); + return getSafeModeStatus() != BMSafeModeStatus.EXTENSION; + } + }, EXTENSION / 10, EXTENSION * 10); + + assertFalse(bmSafeMode.isInSafeMode()); + assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus()); + } finally { + conf.setLong(DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, + DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT); + bm = spy(new BlockManager(fsn, false, conf)); + doReturn(true).when(bm).isGenStampInFuture(any(Block.class)); + dn = spy(bm.getDatanodeManager()); + Whitebox.setInternalState(bm, "datanodeManager", dn); + // the datanode threshold is always met + when(dn.getNumLiveDataNodes()).thenReturn(DATANODE_NUM); + bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf); + } Review comment: The tests have too many warnings due to deprecation. See if you can get rid of them, If not, just do a assert on the log output, That it contains ``Using <value> as SafeModeMonitor Interval`` ``GenericTestUtils`` has a ``LogCapturer`` you can use that. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org