瀏覽代碼

HADOOP-959. Fix namenode snapshot code added in HADOOP-227 to work on Windows. Contributed by Dhruba.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@501942 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年之前
父節點
當前提交
141eb57237

+ 3 - 0
CHANGES.txt

@@ -105,6 +105,9 @@ Trunk (unreleased changes)
 32. HADOOP-961.  Add a 'job -events' sub-command that prints job
     events, including task completions and failures.  (omalley via cutting)
 
+33. HADOOP-959.  Fix namenode snapshot code added in HADOOP-227 to
+    work on Windows.  (Dhruba Borthakur via cutting)
+
 
 Release 0.10.1 - 2007-01-10
 

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

@@ -131,7 +131,7 @@ class FSEditLog {
    * server to exit
    */
    void processIOError(int index) throws IOException {
-     if (editStreams.length == 1) {
+     if (editStreams == null || editStreams.length == 1) {
        throw new IOException("Checkpoint directories inaccessible.");
      }
      assert(index < editFiles.length);
@@ -590,8 +590,15 @@ class FSEditLog {
     //
     for (int idx = 0; idx < editFiles.length; idx++ ) {
       if (!editFilesNew[idx].renameTo(editFiles[idx])) {
-        processIOError(idx); 
-        idx--; 
+        //
+        // renameTo() fails on Windows if the destination
+        // file exists.
+        //
+        editFiles[idx].delete();
+        if (!editFilesNew[idx].renameTo(editFiles[idx])) {
+          processIOError(idx); 
+          idx--; 
+        }
       }
     }
     //

+ 14 - 5
src/java/org/apache/hadoop/dfs/FSImage.java

@@ -174,11 +174,15 @@ class FSImage {
           // shutdown. The fsimage.ckpt was created and the edits.new
           // file was moved to edits. We complete that checkpoint by
           // moving fsimage.new to fsimage. There is no need to 
-          // update the fstime file here.
+          // update the fstime file here. renameTo fails on Windows
+          // if the destination file already exists.
           //
           if (!ckptFile.renameTo(curFile)) {
-            throw new IOException("Unable to rename " + ckptFile +
-                                  " to " + curFile);
+            curFile.delete();
+            if (!ckptFile.renameTo(curFile)) {
+              throw new IOException("Unable to rename " + ckptFile +
+                                    " to " + curFile);
+            }
           }
         }
       }
@@ -480,9 +484,14 @@ class FSImage {
                            NameNodeFile.CKPT.getName());
       File curFile = new File(imageDirs[idx], 
                               NameNodeFile.IMAGE.getName());
+      // renameTo fails on Windows if the destination file 
+      // already exists.
       if (!ckpt.renameTo(curFile)) {
-        editLog.processIOError(idx);
-        idx--;
+        curFile.delete();
+        if (!ckpt.renameTo(curFile)) {
+          editLog.processIOError(idx);
+          idx--;
+        }
       }
     }
 

+ 2 - 0
src/java/org/apache/hadoop/dfs/NameNode.java

@@ -95,6 +95,7 @@ public class NameNode implements ClientProtocol, DatanodeProtocol, FSConstants {
       FSImage fsimage = new FSImage(dirs);
       FSNamesystem namesystem = new FSNamesystem(fsimage);
       fsimage.create();
+      fsimage.getEditLog().close();
     }
 
     /** Format a new filesystem.  Destroys any filesystem that may already
@@ -106,6 +107,7 @@ public class NameNode implements ClientProtocol, DatanodeProtocol, FSConstants {
       FSImage fsimage = new FSImage(dirs);
       FSNamesystem namesystem = new FSNamesystem(fsimage);
       fsimage.create();
+      fsimage.getEditLog().close();
     }
 
     private class NameNodeMetrics {