HDFS-14632. Reduce useless #getNumLiveDataNodes call in SafeModeMonitor. Contributed by He Xiaoqiao.
This commit is contained in:
parent
ac7a8accdf
commit
993dc8726b
|
@ -309,16 +309,20 @@ class BlockManagerSafeMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int numLive = blockManager.getDatanodeManager().getNumLiveDataNodes();
|
if (datanodeThreshold > 0) {
|
||||||
if (numLive < datanodeThreshold) {
|
int numLive = blockManager.getDatanodeManager().getNumLiveDataNodes();
|
||||||
msg += String.format(
|
if (numLive < datanodeThreshold) {
|
||||||
"The number of live datanodes %d needs an additional %d live "
|
msg += String.format(
|
||||||
+ "datanodes to reach the minimum number %d.%n",
|
"The number of live datanodes %d needs an additional %d live "
|
||||||
numLive, (datanodeThreshold - numLive), datanodeThreshold);
|
+ "datanodes to reach the minimum number %d.%n",
|
||||||
|
numLive, (datanodeThreshold - numLive), datanodeThreshold);
|
||||||
|
} else {
|
||||||
|
msg += String.format("The number of live datanodes %d has reached "
|
||||||
|
+ "the minimum number %d. ",
|
||||||
|
numLive, datanodeThreshold);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg += String.format("The number of live datanodes %d has reached "
|
msg += "The minimum number of live datanodes is not required. ";
|
||||||
+ "the minimum number %d. ",
|
|
||||||
numLive, datanodeThreshold);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getBytesInFuture() > 0) {
|
if (getBytesInFuture() > 0) {
|
||||||
|
|
|
@ -201,11 +201,11 @@ public class TestSafeMode {
|
||||||
final NameNode nn = cluster.getNameNode();
|
final NameNode nn = cluster.getNameNode();
|
||||||
|
|
||||||
String status = nn.getNamesystem().getSafemode();
|
String status = nn.getNamesystem().getSafemode();
|
||||||
assertEquals("Safe mode is ON. The reported blocks 0 needs additional " +
|
assertEquals("Safe mode is ON. The reported blocks 0 needs additional "
|
||||||
"14 blocks to reach the threshold 0.9990 of total blocks 15." + NEWLINE +
|
+ "14 blocks to reach the threshold 0.9990 of total blocks 15."
|
||||||
"The number of live datanodes 0 has reached the minimum number 0. " +
|
+ NEWLINE + "The minimum number of live datanodes is not required. "
|
||||||
"Safe mode will be turned off automatically once the thresholds " +
|
+ "Safe mode will be turned off automatically once the thresholds have "
|
||||||
"have been reached.", status);
|
+ "been reached.", status);
|
||||||
assertFalse("Mis-replicated block queues should not be initialized " +
|
assertFalse("Mis-replicated block queues should not be initialized " +
|
||||||
"until threshold is crossed",
|
"until threshold is crossed",
|
||||||
NameNodeAdapter.safeModeInitializedReplQueues(nn));
|
NameNodeAdapter.safeModeInitializedReplQueues(nn));
|
||||||
|
|
|
@ -468,6 +468,31 @@ public class TestBlockManagerSafeMode {
|
||||||
assertTrue(tip.contains("Safe mode will be turned off automatically soon"));
|
assertTrue(tip.contains("Safe mode will be turned off automatically soon"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get safe mode tip without minimum number of live datanodes required.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetSafeModeTipsWithoutNumLiveDatanode() throws IOException {
|
||||||
|
Configuration conf = new HdfsConfiguration();
|
||||||
|
conf.setDouble(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_THRESHOLD_PCT_KEY,
|
||||||
|
THRESHOLD);
|
||||||
|
conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_EXTENSION_KEY,
|
||||||
|
EXTENSION);
|
||||||
|
conf.setInt(DFSConfigKeys.DFS_NAMENODE_SAFEMODE_MIN_DATANODES_KEY, 0);
|
||||||
|
|
||||||
|
NameNode.initMetrics(conf, NamenodeRole.NAMENODE);
|
||||||
|
|
||||||
|
BlockManager blockManager = spy(new BlockManager(fsn, false, conf));
|
||||||
|
|
||||||
|
BlockManagerSafeMode safeMode = new BlockManagerSafeMode(blockManager,
|
||||||
|
fsn, false, conf);
|
||||||
|
safeMode.activate(BLOCK_TOTAL);
|
||||||
|
String tip = safeMode.getSafeModeTip();
|
||||||
|
|
||||||
|
assertTrue(tip.contains("The minimum number of live datanodes is not "
|
||||||
|
+ "required."));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test get safe mode tip in case of blocks with future GS.
|
* Test get safe mode tip in case of blocks with future GS.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -498,13 +498,22 @@ public class TestHASafeMode {
|
||||||
int numNodes, int nodeThresh) {
|
int numNodes, int nodeThresh) {
|
||||||
String status = nn.getNamesystem().getSafemode();
|
String status = nn.getNamesystem().getSafemode();
|
||||||
if (safe == total) {
|
if (safe == total) {
|
||||||
assertTrue("Bad safemode status: '" + status + "'",
|
if (nodeThresh == 0) {
|
||||||
status.startsWith(
|
assertTrue("Bad safemode status: '" + status + "'",
|
||||||
"Safe mode is ON. The reported blocks " + safe + " has reached the "
|
status.startsWith("Safe mode is ON. The reported blocks " + safe
|
||||||
+ "threshold 0.9990 of total blocks " + total + ". The number of "
|
+ " has reached the " + "threshold 0.9990 of total blocks "
|
||||||
+ "live datanodes " + numNodes + " has reached the minimum number "
|
+ total + ". The minimum number of live datanodes is not "
|
||||||
+ nodeThresh + ". In safe mode extension. "
|
+ "required. In safe mode extension. Safe mode will be turned "
|
||||||
+ "Safe mode will be turned off automatically"));
|
+ "off automatically"));
|
||||||
|
} else {
|
||||||
|
assertTrue("Bad safemode status: '" + status + "'",
|
||||||
|
status.startsWith(
|
||||||
|
"Safe mode is ON. The reported blocks " + safe + " has reached "
|
||||||
|
+ "the threshold 0.9990 of total blocks " + total + ". The "
|
||||||
|
+ "number of live datanodes " + numNodes + " has reached "
|
||||||
|
+ "the minimum number " + nodeThresh + ". In safe mode "
|
||||||
|
+ "extension. Safe mode will be turned off automatically"));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int additional = (int) (total * 0.9990) - safe;
|
int additional = (int) (total * 0.9990) - safe;
|
||||||
assertTrue("Bad safemode status: '" + status + "'",
|
assertTrue("Bad safemode status: '" + status + "'",
|
||||||
|
@ -573,9 +582,9 @@ public class TestHASafeMode {
|
||||||
assertTrue("Bad safemode status: '" + status + "'",
|
assertTrue("Bad safemode status: '" + status + "'",
|
||||||
status.startsWith(
|
status.startsWith(
|
||||||
"Safe mode is ON. The reported blocks 10 has reached the threshold "
|
"Safe mode is ON. The reported blocks 10 has reached the threshold "
|
||||||
+ "0.9990 of total blocks 10. The number of live datanodes 3 has "
|
+ "0.9990 of total blocks 10. The minimum number of live datanodes is "
|
||||||
+ "reached the minimum number 0. In safe mode extension. "
|
+ "not required. In safe mode extension. Safe mode will be turned off "
|
||||||
+ "Safe mode will be turned off automatically"));
|
+ "automatically"));
|
||||||
|
|
||||||
// Delete those blocks while the SBN is in safe mode.
|
// Delete those blocks while the SBN is in safe mode.
|
||||||
// Immediately roll the edit log before the actual deletions are sent
|
// Immediately roll the edit log before the actual deletions are sent
|
||||||
|
|
Loading…
Reference in New Issue