瀏覽代碼

HADOOP-2121. Cleanup DFSOutputStream when the stream encountered errors
when Datanodes became full. (Raghu Angadi via dhruba)



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

Dhruba Borthakur 17 年之前
父節點
當前提交
976bcc10af
共有 3 個文件被更改,包括 25 次插入8 次删除
  1. 4 1
      CHANGES.txt
  2. 19 6
      src/java/org/apache/hadoop/dfs/DFSClient.java
  3. 2 1
      src/java/org/apache/hadoop/fs/FSOutputSummer.java

+ 4 - 1
CHANGES.txt

@@ -88,9 +88,12 @@ Trunk (unreleased changes)
     Now invalid options are caught, logged and jobs are failed early. (Lohit
     Now invalid options are caught, logged and jobs are failed early. (Lohit
     Vijayarenu via acmurthy)
     Vijayarenu via acmurthy)
 
 
-    HADOOP-2151. FileSyste.globPaths validates the list of Paths that
+    HADOOP-2151. FileSystem.globPaths validates the list of Paths that
     it returns.  (Lohit Vijayarenu via dhruba)
     it returns.  (Lohit Vijayarenu via dhruba)
 
 
+    HADOOP-2121. Cleanup DFSOutputStream when the stream encountered errors
+    when Datanodes became full.  (Raghu Angadi via dhruba)
+
 Release 0.15.1 -
 Release 0.15.1 -
 
 
   BUG FIXES
   BUG FIXES

+ 19 - 6
src/java/org/apache/hadoop/dfs/DFSClient.java

@@ -1701,6 +1701,22 @@ class DFSClient implements FSConstants {
       namenode.abandonBlock(block, src.toString());
       namenode.abandonBlock(block, src.toString());
     }
     }
 
 
+    private void internalClose() throws IOException {
+      // Clean up any resources that might be held.
+      closed = true;
+      
+      synchronized (pendingCreates) {
+        pendingCreates.remove(src);
+      }
+      
+      if (s != null) {
+        s.close();
+        s = null;
+      }
+      
+      closeBackupStream();
+    }
+    
     /**
     /**
      * Closes this output stream and releases any system 
      * Closes this output stream and releases any system 
      * resources associated with this stream.
      * resources associated with this stream.
@@ -1712,9 +1728,9 @@ class DFSClient implements FSConstants {
         throw new IOException("Stream closed");
         throw new IOException("Stream closed");
       }
       }
       
       
-      flushBuffer();
-      
       try {
       try {
+        flushBuffer();
+        
         if (filePos == 0 || bytesWrittenToBlock != 0) {
         if (filePos == 0 || bytesWrittenToBlock != 0) {
           try {
           try {
             endBlock();
             endBlock();
@@ -1743,11 +1759,8 @@ class DFSClient implements FSConstants {
             }
             }
           }
           }
         }
         }
-        closed = true;
       } finally {
       } finally {
-        synchronized (pendingCreates) {
-          pendingCreates.remove(src.toString());
-        }
+        internalClose();
       }
       }
     }
     }
   }
   }

+ 2 - 1
src/java/org/apache/hadoop/fs/FSOutputSummer.java

@@ -119,8 +119,9 @@ abstract public class FSOutputSummer extends OutputStream {
    */
    */
   protected synchronized void flushBuffer() throws IOException {
   protected synchronized void flushBuffer() throws IOException {
     if(count != 0) {
     if(count != 0) {
-      writeChecksumChunk(buf, 0, count);
+      int chunkLen = count;
       count = 0;
       count = 0;
+      writeChecksumChunk(buf, 0, chunkLen);
     }
     }
   }
   }