Author: dhruba
Date: Mon Feb 18 21:58:26 2008
New Revision: 628998

URL: http://svn.apache.org/viewvc?rev=628998&view=rev
Log:
HADOOP-2844. distcp closes file handles for sequence files.
(Tsz Wo (Nicholas), SZE via dhruba)


Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/util/CopyFiles.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=628998&r1=628997&r2=628998&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Feb 18 21:58:26 2008
@@ -47,6 +47,9 @@
     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

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/util/CopyFiles.java
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/util/CopyFiles.java?rev=628998&r1=628997&r2=628998&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/util/CopyFiles.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/util/CopyFiles.java Mon Feb 18 
21:58:26 2008
@@ -183,18 +183,24 @@
       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 @@
       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;
   }


Reply via email to