HDFS-15920.Solve the problem that the value of SafeModeMonitor#RECHECK_INTERVAL can be configured. (#2831). Contributed by JiangHua Zhu.
Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
parent
c4c5883d8b
commit
1032104b9a
@ -207,6 +207,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
|
||||
"dfs.namenode.replqueue.threshold-pct";
|
||||
public static final String DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY = "dfs.namenode.safemode.min.datanodes";
|
||||
public static final int DFS_NAMENODE_SAFEMODE_MIN_DATANODES_DEFAULT = 0;
|
||||
public static final String DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY =
|
||||
"dfs.namenode.safemode.recheck.interval";
|
||||
public static final long DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT =
|
||||
1000;
|
||||
public static final String DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY =
|
||||
HdfsClientConfigKeys.DeprecatedKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY;
|
||||
public static final String DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_DEFAULT =
|
||||
|
@ -109,7 +109,7 @@ enum BMSafeModeStatus {
|
||||
/** Timestamp of the safe mode initialized. */
|
||||
private long startTime;
|
||||
/** the safe mode monitor thread. */
|
||||
private final Daemon smmthread = new Daemon(new SafeModeMonitor());
|
||||
private final Daemon smmthread;
|
||||
|
||||
/** time of the last status printout */
|
||||
private long lastStatusReport;
|
||||
@ -156,6 +156,7 @@ enum BMSafeModeStatus {
|
||||
MILLISECONDS);
|
||||
|
||||
this.inRollBack = isInRollBackMode(NameNode.getStartupOption(conf));
|
||||
this.smmthread = new Daemon(new SafeModeMonitor(conf));
|
||||
|
||||
LOG.info("{} = {}", DFS_NAMENODE_SAFEMODE_THRESHOLD_PCT_KEY, threshold);
|
||||
LOG.info("{} = {}", DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY,
|
||||
@ -638,9 +639,22 @@ private void reportStatus(String msg, boolean rightNow) {
|
||||
* Periodically check whether it is time to leave safe mode.
|
||||
* This thread starts when the threshold level is reached.
|
||||
*/
|
||||
private class SafeModeMonitor implements Runnable {
|
||||
final private class SafeModeMonitor implements Runnable {
|
||||
/** Interval in msec for checking safe mode. */
|
||||
private static final long RECHECK_INTERVAL = 1000;
|
||||
private long recheckInterval;
|
||||
|
||||
private SafeModeMonitor(Configuration conf) {
|
||||
recheckInterval = conf.getLong(
|
||||
DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY,
|
||||
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);
|
||||
recheckInterval = DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_DEFAULT;
|
||||
}
|
||||
LOG.info("Using {} as SafeModeMonitor Interval", recheckInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -660,7 +674,7 @@ public void run() {
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(RECHECK_INTERVAL);
|
||||
Thread.sleep(recheckInterval);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
@ -1011,6 +1011,14 @@
|
||||
</description>
|
||||
</property>
|
||||
|
||||
<property>
|
||||
<name>dfs.namenode.safemode.recheck.interval</name>
|
||||
<value>1000</value>
|
||||
<description>
|
||||
Interval in msec for checking safe mode.
|
||||
</description>
|
||||
</property>
|
||||
|
||||
<property>
|
||||
<name>dfs.namenode.safemode.extension</name>
|
||||
<value>30000</value>
|
||||
|
@ -230,6 +230,18 @@ public void testCheckSafeMode8() throws Exception {
|
||||
assertEquals(BMSafeModeStatus.OFF, getSafeModeStatus());
|
||||
}
|
||||
|
||||
@Test(timeout = 20000)
|
||||
public void testCheckSafeMode9() throws Exception {
|
||||
Configuration conf = new HdfsConfiguration();
|
||||
conf.setLong(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_RECHECK_INTERVAL_KEY, 3000);
|
||||
GenericTestUtils.LogCapturer logs =
|
||||
GenericTestUtils.LogCapturer.captureLogs(BlockManagerSafeMode.LOG);
|
||||
BlockManagerSafeMode blockManagerSafeMode = new BlockManagerSafeMode(bm,
|
||||
fsn, true, conf);
|
||||
String content = logs.getOutput();
|
||||
assertTrue(content.contains("Using 3000 as SafeModeMonitor Interval"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the block safe increases up to block threshold.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user