Browse Source

HADOOP-2073. Change size of VERSION file after writing contents to it.
(Konstantin Shvachko via dhruba)



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

Dhruba Borthakur 17 years ago
parent
commit
aac1a07ac5
2 changed files with 16 additions and 1 deletions
  1. 3 0
      CHANGES.txt
  2. 13 1
      src/java/org/apache/hadoop/dfs/Storage.java

+ 3 - 0
CHANGES.txt

@@ -341,6 +341,9 @@ Branch 0.15 (unreleased changes)
     HADOOP-2048.  Change error handling in distcp so that each map copies
     HADOOP-2048.  Change error handling in distcp so that each map copies
     as much as possible before reporting the error. Also report progress on
     as much as possible before reporting the error. Also report progress on
     every copy. (Chris Douglas via omalley)
     every copy. (Chris Douglas via omalley)
+
+    HADOOP-2073.  Change size of VERSION file after writing contents to it.
+    (Konstantin Shvachko via dhruba)
  
  
   IMPROVEMENTS
   IMPROVEMENTS
 
 

+ 13 - 1
src/java/org/apache/hadoop/dfs/Storage.java

@@ -170,10 +170,22 @@ abstract class Storage extends StorageInfo {
       RandomAccessFile file = new RandomAccessFile(to, "rws");
       RandomAccessFile file = new RandomAccessFile(to, "rws");
       FileOutputStream out = null;
       FileOutputStream out = null;
       try {
       try {
-        file.setLength(0);
         file.seek(0);
         file.seek(0);
         out = new FileOutputStream(file.getFD());
         out = new FileOutputStream(file.getFD());
+        /*
+         * If server is interrupted before this line, 
+         * the version file will remain unchanged.
+         */
         props.store(out, null);
         props.store(out, null);
+        /*
+         * Now the new fields are flushed to the head of the file, but file 
+         * length can still be larger then required and therefore the file can 
+         * contain whole or corrupted fields from its old contents in the end.
+         * If server is interrupted here and restarted later these extra fields
+         * either should not effect server behavior or should be handled
+         * by the server correctly.
+         */
+        file.setLength(out.getChannel().position());
       } finally {
       } finally {
         if (out != null) {
         if (out != null) {
           out.close();
           out.close();