소스 검색

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 년 전
부모
커밋
aac1a07ac5
2개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  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
     as much as possible before reporting the error. Also report progress on
     every copy. (Chris Douglas via omalley)
+
+    HADOOP-2073.  Change size of VERSION file after writing contents to it.
+    (Konstantin Shvachko via dhruba)
  
   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");
       FileOutputStream out = null;
       try {
-        file.setLength(0);
         file.seek(0);
         out = new FileOutputStream(file.getFD());
+        /*
+         * If server is interrupted before this line, 
+         * the version file will remain unchanged.
+         */
         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 {
         if (out != null) {
           out.close();