You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by in...@apache.org on 2020/09/25 16:48:14 UTC
[hadoop] branch trunk updated: HDFS-15594. Lazy calculate live
datanodes in safe mode tip (#2332)
This is an automated email from the ASF dual-hosted git repository.
inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 00c4de6 HDFS-15594. Lazy calculate live datanodes in safe mode tip (#2332)
00c4de6 is described below
commit 00c4de63cf5cacec3463eafe5c8d654318461ca2
Author: Ye Ni <14...@users.noreply.github.com>
AuthorDate: Fri Sep 25 09:47:54 2020 -0700
HDFS-15594. Lazy calculate live datanodes in safe mode tip (#2332)
---
.../blockmanagement/BlockManagerSafeMode.java | 71 ++++++++++++----------
.../blockmanagement/TestBlockManagerSafeMode.java | 4 +-
2 files changed, 42 insertions(+), 33 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 aecdb59..eec2aa5 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
@@ -294,65 +294,74 @@ class BlockManagerSafeMode {
}
String getSafeModeTip() {
- String msg = "";
+ StringBuilder msg = new StringBuilder();
+ boolean isBlockThresholdMet = false;
synchronized (this) {
- if (blockSafe < blockThreshold) {
- msg += String.format(
+ isBlockThresholdMet = (blockSafe >= blockThreshold);
+ if (!isBlockThresholdMet) {
+ msg.append(String.format(
"The reported blocks %d needs additional %d"
+ " blocks to reach the threshold %.4f of total blocks %d.%n",
- blockSafe, (blockThreshold - blockSafe), threshold, blockTotal);
+ blockSafe, (blockThreshold - blockSafe), threshold, blockTotal));
} else {
- msg += String.format("The reported blocks %d has reached the threshold"
- + " %.4f of total blocks %d. ", blockSafe, threshold, blockTotal);
+ msg.append(String.format(
+ "The reported blocks %d has reached the threshold %.4f of total"
+ + " blocks %d. ", blockSafe, threshold, blockTotal));
}
}
if (datanodeThreshold > 0) {
- int numLive = blockManager.getDatanodeManager().getNumLiveDataNodes();
- if (numLive < datanodeThreshold) {
- msg += String.format(
- "The number of live datanodes %d needs an additional %d live "
- + "datanodes to reach the minimum number %d.%n",
- numLive, (datanodeThreshold - numLive), datanodeThreshold);
+ if (isBlockThresholdMet) {
+ int numLive = blockManager.getDatanodeManager().getNumLiveDataNodes();
+ if (numLive < datanodeThreshold) {
+ msg.append(String.format(
+ "The number of live datanodes %d needs an additional %d live "
+ + "datanodes to reach the minimum number %d.%n",
+ numLive, (datanodeThreshold - numLive), datanodeThreshold));
+ } else {
+ msg.append(String.format(
+ "The number of live datanodes %d has reached the minimum number"
+ + " %d. ", numLive, datanodeThreshold));
+ }
} else {
- msg += String.format("The number of live datanodes %d has reached "
- + "the minimum number %d. ",
- numLive, datanodeThreshold);
+ msg.append("The number of live datanodes is not calculated ")
+ .append("since reported blocks hasn't reached the threshold. ");
}
} else {
- msg += "The minimum number of live datanodes is not required. ";
+ msg.append("The minimum number of live datanodes is not required. ");
}
if (getBytesInFuture() > 0) {
- msg += "Name node detected blocks with generation stamps " +
- "in future. This means that Name node metadata is inconsistent. " +
- "This can happen if Name node metadata files have been manually " +
- "replaced. Exiting safe mode will cause loss of " +
- getBytesInFuture() + " byte(s). Please restart name node with " +
- "right metadata or use \"hdfs dfsadmin -safemode forceExit\" " +
- "if you are certain that the NameNode was started with the " +
- "correct FsImage and edit logs. If you encountered this during " +
- "a rollback, it is safe to exit with -safemode forceExit.";
- return msg;
+ msg.append("Name node detected blocks with generation stamps in future. ")
+ .append("This means that Name node metadata is inconsistent. This ")
+ .append("can happen if Name node metadata files have been manually ")
+ .append("replaced. Exiting safe mode will cause loss of ")
+ .append(getBytesInFuture())
+ .append(" byte(s). Please restart name node with right metadata ")
+ .append("or use \"hdfs dfsadmin -safemode forceExit\" if you ")
+ .append("are certain that the NameNode was started with the correct ")
+ .append("FsImage and edit logs. If you encountered this during ")
+ .append("a rollback, it is safe to exit with -safemode forceExit.");
+ return msg.toString();
}
final String turnOffTip = "Safe mode will be turned off automatically ";
switch(status) {
case PENDING_THRESHOLD:
- msg += turnOffTip + "once the thresholds have been reached.";
+ msg.append(turnOffTip).append("once the thresholds have been reached.");
break;
case EXTENSION:
- msg += "In safe mode extension. "+ turnOffTip + "in " +
- timeToLeaveExtension() / 1000 + " seconds.";
+ msg.append("In safe mode extension. ").append(turnOffTip).append("in ")
+ .append(timeToLeaveExtension() / 1000).append(" seconds.");
break;
case OFF:
- msg += turnOffTip + "soon.";
+ msg.append(turnOffTip).append("soon.");
break;
default:
assert false : "Non-recognized block manager safe mode status: " + status;
}
- return msg;
+ return msg.toString();
}
/**
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 cf4ec64..5d2a07e 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
@@ -527,8 +527,8 @@ public class TestBlockManagerSafeMode {
"threshold %.4f of total blocks %d.%n",
0, BLOCK_THRESHOLD, THRESHOLD, BLOCK_TOTAL)));
assertTrue(tip.contains(
- String.format("The number of live datanodes %d has reached the " +
- "minimum number %d. ", dn.getNumLiveDataNodes(), DATANODE_NUM)));
+ "The number of live datanodes is not calculated " +
+ "since reported blocks hasn't reached the threshold."));
assertTrue(tip.contains("Safe mode will be turned off automatically once " +
"the thresholds have been reached."));
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org