hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1124570 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
Date Thu, 19 May 2011 07:35:05 GMT
Author: todd
Date: Thu May 19 07:35:04 2011
New Revision: 1124570

URL: http://svn.apache.org/viewvc?rev=1124570&view=rev
Log:
HDFS-1958. Confirmation should be more lenient of user input when formatting the NameNode.
Contributed by Todd Lipcon.

Modified:
    hadoop/hdfs/trunk/CHANGES.txt
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1124570&r1=1124569&r2=1124570&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Thu May 19 07:35:04 2011
@@ -436,6 +436,9 @@ Trunk (unreleased changes)
     HDFS-1332.  Include more information in exceptions and debug messages
     when BlockPlacementPolicy cannot be satisfied.  (Ted Yu via szetszwo)
 
+    HDFS-1958. Confirmation should be more lenient of user input when
+    formatting the NameNode. (todd)
+
   OPTIMIZATIONS
 
     HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1124570&r1=1124569&r2=1124570&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java Thu May
19 07:35:04 2011
@@ -1487,12 +1487,10 @@ public class NameNode implements Namenod
       if (!curDir.exists())
         continue;
       if (isConfirmationNeeded) {
-        System.err.print("Re-format filesystem in " + curDir +" ? (Y or N) ");
-        if (System.in.read() != 'Y') {
+        if (!confirmPrompt("Re-format filesystem in " + curDir + " ?")) {
           System.err.println("Format aborted in "+ curDir);
           return true;
         }
-        while(System.in.read() != '\n'); // discard the enter-key
       }
     }
 
@@ -1508,11 +1506,9 @@ public class NameNode implements Namenod
         throw new IllegalArgumentException("Format must be provided with clusterid");
       }
       if(isConfirmationNeeded) {
-        System.err.print("Use existing cluster id=" + clusterId + "? (Y or N)");
-        if(System.in.read() != 'Y') {
+        if (!confirmPrompt("Use existing cluster id=" + clusterId + "?")) {
           throw new IllegalArgumentException("Format must be provided with clusterid");
         }
-        while(System.in.read() != '\n'); // discard the enter-key
       }
     }
     nsys.dir.fsImage.getStorage().format(clusterId);
@@ -1532,12 +1528,10 @@ public class NameNode implements Namenod
         + "Recent upgrade will become permanent.\n"
         + "Rollback option will not be available anymore.\n");
     if (isConfirmationNeeded) {
-      System.err.print("Finalize filesystem state ? (Y or N) ");
-      if (!(System.in.read() == 'Y')) {
+      if (!confirmPrompt("Finalize filesystem state?")) {
         System.err.println("Finalize aborted.");
         return true;
       }
-      while(System.in.read() != '\n'); // discard the enter-key
     }
     nsys.dir.fsImage.finalizeUpgrade();
     return false;
@@ -1640,6 +1634,34 @@ public class NameNode implements Namenod
                                           StartupOption.REGULAR.toString()));
   }
 
+  /**
+   * Print out a prompt to the user, and return true if the user
+   * responds with "Y" or "yes".
+   */
+  static boolean confirmPrompt(String prompt) throws IOException {
+    while (true) {
+      System.err.print(prompt + " (Y or N) ");
+      StringBuilder responseBuilder = new StringBuilder();
+      while (true) {
+        int c = System.in.read();
+        if (c == -1 || c == '\r' || c == '\n') {
+          break;
+        }
+        responseBuilder.append((char)c);
+      }
+  
+      String response = responseBuilder.toString();
+      if (response.equalsIgnoreCase("y") ||
+          response.equalsIgnoreCase("yes")) {
+        return true;
+      } else if (response.equalsIgnoreCase("n") ||
+          response.equalsIgnoreCase("no")) {
+        return false;
+      }
+      // else ask them again
+    }
+  }
+
   public static NameNode createNameNode(String argv[], Configuration conf)
       throws IOException {
     if (conf == null)



Mime
View raw message