HDFS-11095. BlockManagerSafeMode should respect extension period default config value (30s). Contributed by Mingliang Liu

This commit is contained in:
Mingliang Liu 2016-11-02 13:01:54 -07:00
parent f2800f523d
commit 9b0c17f852
3 changed files with 32 additions and 4 deletions

View File

@ -35,12 +35,16 @@ import org.apache.hadoop.hdfs.server.namenode.startupprogress.StepType;
import org.apache.hadoop.net.NetworkTopology;
import org.apache.hadoop.util.Daemon;
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.atomic.AtomicLong;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_REPL_QUEUE_THRESHOLD_PCT_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY;
@ -96,7 +100,8 @@ class BlockManagerSafeMode {
private long blockReplQueueThreshold;
/** How long (in ms) is the extension period. */
private final int extension;
@VisibleForTesting
final long extension;
/** Timestamp of the first time when thresholds are met. */
private final AtomicLong reachedTime = new AtomicLong();
/** Timestamp of the safe mode initialized. */
@ -143,7 +148,9 @@ class BlockManagerSafeMode {
this.replQueueThreshold =
conf.getFloat(DFS_NAMENODE_REPL_QUEUE_THRESHOLD_PCT_KEY,
(float) threshold);
this.extension = conf.getInt(DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, 0);
this.extension = conf.getTimeDuration(DFS_NAMENODE_SAFEMODE_EXTENSION_KEY,
DFS_NAMENODE_SAFEMODE_EXTENSION_DEFAULT,
MILLISECONDS);
this.inRollBack = isInRollBackMode(NameNode.getStartupOption(conf));

View File

@ -847,8 +847,9 @@
<name>dfs.namenode.safemode.extension</name>
<value>30000</value>
<description>
Determines extension of safe mode in milliseconds
after the threshold level is reached.
Determines extension of safe mode in milliseconds after the threshold level
is reached. Support multiple time unit suffix (case insensitive), as
described in dfs.heartbeat.interval.
</description>
</property>

View File

@ -38,6 +38,7 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.TimeoutException;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_DEFAULT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -392,6 +393,25 @@ public class TestBlockManagerSafeMode {
"are cleared.", bmSafeMode.leaveSafeMode(false));
}
@Test(timeout = 10000)
public void testExtensionConfig() {
final Configuration conf = new HdfsConfiguration();
bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf);
assertEquals(DFS_NAMENODE_SAFEMODE_EXTENSION_DEFAULT, bmSafeMode.extension);
conf.set(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, "30000");
bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf);
assertEquals(30000, bmSafeMode.extension);
conf.set(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, "20s");
bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf);
assertEquals(20 * 1000, bmSafeMode.extension);
conf.set(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY, "7m");
bmSafeMode = new BlockManagerSafeMode(bm, fsn, false, conf);
assertEquals(7 * 60 * 1000, bmSafeMode.extension);
}
/**
* Test get safe mode tip.
*/