Przeglądaj źródła

Merge -r 650764:650765 -r 669327:669328 from trunk to branch-0.17 to fix HADOOP-1979

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.17@669334 13f79535-47bb-0310-9956-ffa450edef68
Arun Murthy 17 lat temu
rodzic
commit
2443dc179e

+ 5 - 0
CHANGES.txt

@@ -14,6 +14,11 @@ Release 0.17.1 - Unreleased
     HADOOP-3522. Improve documentation on reduce pointing out that
     input keys and values will be reused. (omalley)
 
+  BUG FIXES
+
+    HADOOP-1979. Speed up fsck by adding a buffered stream. (Lohit
+    Vijaya Renu via omalley)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 6 - 6
src/java/org/apache/hadoop/dfs/DFSck.java

@@ -20,6 +20,7 @@ package org.apache.hadoop.dfs;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.BufferedReader;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
@@ -106,13 +107,12 @@ public class DFSck extends Configured implements Tool {
     URL path = new URL(url.toString());
     URLConnection connection = path.openConnection();
     InputStream stream = connection.getInputStream();
-    InputStreamReader input =
-      new InputStreamReader(stream, "UTF-8");
+    BufferedReader input = new BufferedReader(new InputStreamReader(
+                                              stream, "UTF-8"));
+    String line = null;
     try {
-      int c = input.read();
-      while (c != -1) {
-        System.out.print((char) c);
-        c = input.read();
+      while ((line = input.readLine()) != null) {
+        System.out.println(line);
       }
     } finally {
       input.close();

+ 5 - 6
src/java/org/apache/hadoop/dfs/NamenodeFsck.java

@@ -167,9 +167,8 @@ public class NamenodeFsck {
           blocks.locatedBlockCount() + " block(s): ");
     }  else {
       out.print('.');
-      out.flush();
-      if (res.totalFiles % 100 == 0) { out.println(); }
     }
+    if (res.totalFiles % 100 == 0) { out.flush(); }
     int missing = 0;
     long missize = 0;
     int underReplicatedPerFile = 0;
@@ -242,7 +241,7 @@ public class NamenodeFsck {
     }
     if (missing > 0) {
       if (!showFiles) {
-        out.println("\n" + path + ": MISSING " + missing
+        out.print("\n" + path + ": MISSING " + missing
             + " blocks of total size " + missize + " B.");
       }
       res.corruptFiles++;
@@ -258,12 +257,12 @@ public class NamenodeFsck {
     }
     if (showFiles) {
       if (missing > 0) {
-        out.println(" MISSING " + missing + " blocks of total size " + missize + " B");
+        out.print(" MISSING " + missing + " blocks of total size " + missize + " B\n");
       }  else if (underReplicatedPerFile == 0 && misReplicatedPerFile == 0) {
-        out.println(" OK");
+        out.print(" OK\n");
       }
       if (showBlocks) {
-        out.println(report.toString());
+        out.print(report.toString() + "\n");
       }
     }
   }