Ver código fonte

HDFS-970. fsync fsimage to disk before closing fsimage file.
(Todd Lipcon via dhruba)



git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@944566 13f79535-47bb-0310-9956-ffa450edef68

Dhruba Borthakur 15 anos atrás
pai
commit
1be7b229ed

+ 3 - 0
CHANGES.txt

@@ -18,6 +18,9 @@ Trunk (unreleased changes)
     HDFS 1021. specify correct server principal for RefreshAuthorizationPolicyProtocol 
     and RefreshUserToGroupMappingsProtocol protocols in DFSAdmin (for HADOOP-6612) (boryas)
 
+    HDFS-970. fsync fsimage to disk before closing fsimage file.
+    (Todd Lipcon via dhruba)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 9 - 4
src/java/org/apache/hadoop/hdfs/server/namenode/FSImage.java

@@ -728,10 +728,12 @@ public class FSImage extends Storage {
         LOG.error("Cannot delete chekpoint time file: "
                   + timeFile.getCanonicalPath());
     }
-    DataOutputStream out = new DataOutputStream(
-                                                new FileOutputStream(timeFile));
+    FileOutputStream fos = new FileOutputStream(timeFile);
+    DataOutputStream out = new DataOutputStream(fos);
     try {
       out.writeLong(checkpointTime);
+      out.flush();
+      fos.getChannel().force(true);
     } finally {
       out.close();
     }
@@ -1229,9 +1231,9 @@ public class FSImage extends Storage {
     //
     // Write out data
     //
+    FileOutputStream fos = new FileOutputStream(newFile);
     DataOutputStream out = new DataOutputStream(
-                                                new BufferedOutputStream(
-                                                                         new FileOutputStream(newFile)));
+      new BufferedOutputStream(fos));
     try {
       out.writeInt(FSConstants.LAYOUT_VERSION);
       out.writeInt(namespaceID);
@@ -1246,6 +1248,9 @@ public class FSImage extends Storage {
       fsNamesys.saveFilesUnderConstruction(out);
       fsNamesys.saveSecretManagerState(out);
       strbuf = null;
+
+      out.flush();
+      fos.getChannel().force(true);
     } finally {
       out.close();
     }

+ 1 - 0
src/java/org/apache/hadoop/hdfs/server/namenode/TransferFsImage.java

@@ -195,6 +195,7 @@ class TransferFsImage implements FSConstants {
       if (output != null) {
         for (int i = 0; i < output.length; i++) {
           if (output[i] != null) {
+            output[i].getChannel().force(true);
             output[i].close();
           }
         }