浏览代码

HADOOP-5650. Fix safemode messages in the Namenode log. Contributed by Suresh Srinivas

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@766182 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 年之前
父节点
当前提交
43a01ff832
共有 2 个文件被更改,包括 29 次插入22 次删除
  1. 3 0
      CHANGES.txt
  2. 26 22
      src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

+ 3 - 0
CHANGES.txt

@@ -418,6 +418,9 @@ Trunk (unreleased changes)
     HADOOP-5704. Fix compilation problems in TestFairScheduler and
     HADOOP-5704. Fix compilation problems in TestFairScheduler and
     TestCapacityScheduler.  (Chris Douglas via szetszwo)
     TestCapacityScheduler.  (Chris Douglas via szetszwo)
 
 
+    HADOOP-5650. Fix safemode messages in the Namenode log.  (Suresh Srinivas
+    via szetszwo)
+
 Release 0.20.0 - Unreleased
 Release 0.20.0 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 26 - 22
src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -4053,6 +4053,8 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
     int blockTotal; 
     int blockTotal; 
     /** Number of safe blocks. */
     /** Number of safe blocks. */
     private int blockSafe;
     private int blockSafe;
+    /** Number of blocks needed to satisfy safe mode threshold condition */
+    private int blockThreshold;
     /** time of the last status printout */
     /** time of the last status printout */
     private long lastStatusReport = 0;
     private long lastStatusReport = 0;
       
       
@@ -4172,15 +4174,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
      * if DFS is empty or {@link #threshold} == 0
      * if DFS is empty or {@link #threshold} == 0
      */
      */
     boolean needEnter() {
     boolean needEnter() {
-      return getSafeBlockRatio() < threshold;
-    }
-      
-    /**
-     * Ratio of the number of safe blocks to the total number of blocks 
-     * to be compared with the threshold.
-     */
-    private float getSafeBlockRatio() {
-      return (blockTotal == 0 ? 1 : (float)blockSafe/blockTotal);
+      return threshold != 0 && blockSafe < blockThreshold;
     }
     }
       
       
     /**
     /**
@@ -4213,7 +4207,8 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
      * Set total number of blocks.
      * Set total number of blocks.
      */
      */
     synchronized void setBlockTotal(int total) {
     synchronized void setBlockTotal(int total) {
-      this.blockTotal = total; 
+      this.blockTotal = total;
+      this.blockThreshold = (int) (blockTotal * threshold);
       checkMode();
       checkMode();
     }
     }
       
       
@@ -4257,9 +4252,9 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
      * A tip on how safe mode is to be turned off: manually or automatically.
      * A tip on how safe mode is to be turned off: manually or automatically.
      */
      */
     String getTurnOffTip() {
     String getTurnOffTip() {
-      String leaveMsg = "Safe mode will be turned off automatically";
       if(reached < 0)
       if(reached < 0)
         return "Safe mode is OFF.";
         return "Safe mode is OFF.";
+      String leaveMsg = "Safe mode will be turned off automatically";
       if(isManual()) {
       if(isManual()) {
         if(getDistributedUpgradeState())
         if(getDistributedUpgradeState())
           return leaveMsg + " upon completion of " + 
           return leaveMsg + " upon completion of " + 
@@ -4269,15 +4264,24 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
       }
       }
       if(blockTotal < 0)
       if(blockTotal < 0)
         return leaveMsg + ".";
         return leaveMsg + ".";
-      String safeBlockRatioMsg = 
-        String.format("The ratio of reported blocks %.4f has " +
-          (reached == 0 ? "not " : "") + "reached the threshold %.4f. ",
-          getSafeBlockRatio(), threshold) + leaveMsg;
-      if(reached == 0 || isManual())  // threshold is not reached or manual
-        return safeBlockRatioMsg + ".";
+      
+      String msg = null;
+      if (reached == 0) {
+        msg = String.format("The reported blocks %d needs additional %d"
+            + " blocks to reach the threshold %.4f of total blocks %d. %s",
+            blockSafe, (blockThreshold - blockSafe), threshold, blockTotal,
+            leaveMsg);
+      } else {
+        msg = String.format("The reported blocks %d has reached the threshold"
+            + " %.4f of total blocks %d. %s", blockSafe, threshold, 
+            blockTotal, leaveMsg);
+      }
+      if(reached == 0 || isManual()) {  // threshold is not reached or manual       
+        return msg + ".";
+      }
       // extension period is in progress
       // extension period is in progress
-      return safeBlockRatioMsg + " in " 
-            + Math.abs(reached + extension - now())/1000 + " seconds.";
+      return msg + " in " + Math.abs(reached + extension - now()) / 1000
+          + " seconds.";
     }
     }
 
 
     /**
     /**
@@ -4295,9 +4299,9 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
      * Returns printable state of the class.
      * Returns printable state of the class.
      */
      */
     public String toString() {
     public String toString() {
-      String resText = "Current safe block ratio = " 
-        + getSafeBlockRatio() 
-        + ". Target threshold = " + threshold
+      String resText = "Current safe blocks = " 
+        + blockSafe 
+        + ". Target blocks = " + blockThreshold + " for threshold = %" + threshold
         + ". Minimal replication = " + safeReplication + ".";
         + ". Minimal replication = " + safeReplication + ".";
       if (reached > 0) 
       if (reached > 0) 
         resText += " Threshold was reached " + new Date(reached) + ".";
         resText += " Threshold was reached " + new Date(reached) + ".";