1
0
Kaynağa Gözat

HADOOP-3363. Fix unformatted storage detection in FSImage. Contributed by Konstantin Shvachko.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@668264 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 17 yıl önce
ebeveyn
işleme
8773aedc36

+ 2 - 0
CHANGES.txt

@@ -596,6 +596,8 @@ Release 0.18.0 - Unreleased
     HADOOP-3548. Fixes build.xml to copy all *.jar files to the dist.
     (Owen O'Malley via ddas)
 
+    HADOOP-3363. Fix unformatted storage detection in FSImage. (shv)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 6 - 3
src/hdfs/org/apache/hadoop/dfs/FSImage.java

@@ -562,9 +562,12 @@ class FSImage extends Storage {
 
   boolean isConversionNeeded(StorageDirectory sd) throws IOException {
     File oldImageDir = new File(sd.root, "image");
-    if (!oldImageDir.exists())
-      throw new InconsistentFSStateException(sd.root,
-          oldImageDir + " does not exist.");
+    if (!oldImageDir.exists()) {
+      if(sd.getVersionFile().exists())
+        throw new InconsistentFSStateException(sd.root,
+            oldImageDir + " does not exist.");
+      return false;
+    }
     // check the layout version inside the image file
     File oldF = new File(oldImageDir, "fsimage");
     RandomAccessFile oldFile = new RandomAccessFile(oldF, "rws");

+ 10 - 3
src/test/org/apache/hadoop/dfs/TestDFSStorageStateRecovery.java

@@ -37,7 +37,7 @@ public class TestDFSStorageStateRecovery extends TestCase {
  
   private static final Log LOG = LogFactory.getLog(
                                                    "org.apache.hadoop.dfs.TestDFSStorageStateRecovery");
-  private Configuration conf;
+  private Configuration conf = null;
   private int testCounter = 0;
   private MiniDFSCluster cluster = null;
   
@@ -197,8 +197,15 @@ public class TestDFSStorageStateRecovery extends TestCase {
           try {
             cluster = new MiniDFSCluster(conf, 0, StartupOption.REGULAR);
             throw new AssertionError("NameNode should have failed to start");
-          } catch (Exception expected) {
-            // expected
+          } catch (IOException expected) {
+            // the exception is expected
+            // check that the message says "not formatted" 
+            // when storage directory is empty (case #5)
+            if(!testCases[i][0] && !testCases[i][2] 
+                      && !testCases[i][1] && !testCases[i][3]) {
+              assertTrue(expected.getLocalizedMessage().contains(
+                  "NameNode is not formatted"));
+            }
           }
         }