Browse Source

HADOOP-2844. distcp closes file handles for sequence files.
(Tsz Wo (Nicholas), SZE via dhruba)



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

Dhruba Borthakur 17 years ago
parent
commit
6449f987b2
2 changed files with 22 additions and 16 deletions
  1. 3 0
      CHANGES.txt
  2. 19 16
      src/java/org/apache/hadoop/util/CopyFiles.java

+ 3 - 0
CHANGES.txt

@@ -47,6 +47,9 @@ Trunk (unreleased changes)
     HADOOP-2832. Remove tabs from code of DFSClient for better
     indentation. (dhruba)
 
+    HADOOP-2844. distcp closes file handles for sequence files.
+    (Tsz Wo (Nicholas), SZE via dhruba)
+
 Release 0.16.1 - Unrelease
 
   BUG FIXES

+ 19 - 16
src/java/org/apache/hadoop/util/CopyFiles.java

@@ -183,18 +183,24 @@ public class CopyFiles implements Tool {
       long last = 0L;
       long acc = 0L;
       long cbrem = srcst.getLen();
-      for (SequenceFile.Reader sl = new SequenceFile.Reader(fs, src, job);
-           sl.next(key, value); last = sl.getPosition()) {
-        // if adding this split would put this split past the target size,
-        // cut the last split and put this next file in the next split.
-        if (acc + key.get() > targetsize && acc != 0) {
-          long splitsize = last - pos;
-          splits.add(new FileSplit(src, pos, splitsize, job));
-          cbrem -= splitsize;
-          pos = last;
-          acc = 0L;
+      SequenceFile.Reader sl = null;
+      try {
+        sl = new SequenceFile.Reader(fs, src, job);
+        for (; sl.next(key, value); last = sl.getPosition()) {
+          // if adding this split would put this split past the target size,
+          // cut the last split and put this next file in the next split.
+          if (acc + key.get() > targetsize && acc != 0) {
+            long splitsize = last - pos;
+            splits.add(new FileSplit(src, pos, splitsize, job));
+            cbrem -= splitsize;
+            pos = last;
+            acc = 0L;
+          }
+          acc += key.get();
         }
-        acc += key.get();
+      }
+      finally {
+        checkAndClose(sl);
       }
       if (cbrem != 0) {
         splits.add(new FileSplit(src, pos, cbrem, job));
@@ -439,19 +445,16 @@ public class CopyFiles implements Tool {
       throws IOException {
     List<Path> result = new ArrayList<Path>();
     FileSystem fs = srcList.getFileSystem(conf);
-    DataInputStream raw = fs.open(srcList);
     BufferedReader input = null;
     try {
-      input = new BufferedReader(new InputStreamReader(raw));
+      input = new BufferedReader(new InputStreamReader(fs.open(srcList)));
       String line = input.readLine();
       while (line != null) {
         result.add(new Path(line));
         line = input.readLine();
       }
     } finally {
-      if (input != null) {
-        input.close();
-      }
+      checkAndClose(input);
     }
     return result;
   }