hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r500394 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/NamenodeFsck.java src/test/org/apache/hadoop/dfs/TestFsck.java
Date Fri, 26 Jan 2007 22:58:26 GMT
Author: cutting
Date: Fri Jan 26 14:58:25 2007
New Revision: 500394

URL: http://svn.apache.org/viewvc?view=rev&rev=500394
Log:
HADOOP-856.  Fix HDFS's fsck command to not report non-existant filesystems as healthy.  Contributed
by Milind.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestFsck.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=500394&r1=500393&r2=500394
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Jan 26 14:58:25 2007
@@ -79,6 +79,9 @@
 24. HADOOP-936.  More metric renamings, as in HADOOP-890.
     (Nigel Daley via cutting)
 
+25. HADOOP-856.  Fix HDFS's fsck command to not report that
+    non-existent filesystems are healthy.  (Milind Bhandarkar via cutting)
+
 
 Release 0.10.1 - 2007-01-10
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java?view=diff&rev=500394&r1=500393&r2=500394
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java Fri Jan 26 14:58:25
2007
@@ -84,7 +84,6 @@
   private String path = "/";
   
   private Configuration conf;
-  private HttpServletResponse response;
   private PrintWriter out;
   
   /**
@@ -101,7 +100,6 @@
       HttpServletResponse response) throws IOException {
     this.conf = conf;
     this.nn = nn;
-    this.response = response;
     this.out = response.getWriter();
     for (Iterator<String> it = pmap.keySet().iterator(); it.hasNext();) {
       String key = it.next();
@@ -127,12 +125,14 @@
         for (int i = 0; i < files.length; i++) {
           check(files[i], res);
         }
-      }
-      out.println(res);
-      if (res.isHealthy()) {
-        out.println("\n\nThe filesystem under path '" + path + "' is HEALTHY");
-      }  else {
-        out.println("\n\nThe filesystem under path '" + path + "' is CORRUPT");
+        out.println(res);
+        if (res.isHealthy()) {
+          out.println("\n\nThe filesystem under path '" + path + "' is HEALTHY");
+        }  else {
+          out.println("\n\nThe filesystem under path '" + path + "' is CORRUPT");
+        }
+      } else {
+        out.println("\n\nPath '" + path + "' does not exist.");
       }
     } finally {
       out.close();
@@ -141,8 +141,9 @@
   
   private void check(DFSFileInfo file, FsckResult res) throws IOException {
     if (file.isDir()) {
-      if (showFiles)
+      if (showFiles) {
         out.println(file.getPath() + " <dir>");
+      }
       res.totalDirs++;
       DFSFileInfo[] files = nn.getListing(file.getPath());
       for (int i = 0; i < files.length; i++) {
@@ -160,7 +161,7 @@
     }  else {
       out.print('.');
       out.flush();
-      if (res.totalFiles % 100 == 0)        out.println();
+      if (res.totalFiles % 100 == 0) { out.println(); }
     }
     int missing = 0;
     long missize = 0;
@@ -170,8 +171,12 @@
       long id = block.getBlockId();
       DatanodeInfo[] locs = blocks[i].getLocations();
       short targetFileReplication = file.getReplication();
-      if (locs.length > targetFileReplication) res.overReplicatedBlocks += (locs.length
- targetFileReplication);
-      if (locs.length < targetFileReplication && locs.length > 0) res.underReplicatedBlocks
+= (targetFileReplication - locs.length);
+      if (locs.length > targetFileReplication) {
+        res.overReplicatedBlocks += (locs.length - targetFileReplication);
+      }
+      if (locs.length < targetFileReplication && locs.length > 0) {
+        res.underReplicatedBlocks += (targetFileReplication - locs.length);
+      }
       report.append(i + ". " + id + " len=" + block.getNumBytes());
       if (locs == null || locs.length == 0) {
         report.append(" MISSING!");
@@ -183,7 +188,7 @@
         if (showLocations) {
           StringBuffer sb = new StringBuffer("[");
           for (int j = 0; j < locs.length; j++) {
-            if (j > 0) sb.append(", ");
+            if (j > 0) { sb.append(", "); }
             sb.append(locs[j]);
           }
           sb.append(']');
@@ -193,8 +198,9 @@
       report.append('\n');
     }
     if (missing > 0) {
-      if (!showFiles)
+      if (!showFiles) {
         out.println("\nMISSING " + missing + " blocks of total size " + missize + " B");
+      }
       res.corruptFiles++;
       switch(fixing) {
         case FIXING_NONE:
@@ -209,8 +215,12 @@
     if (showFiles) {
       if (missing > 0) {
         out.println(" MISSING " + missing + " blocks of total size " + missize + " B");
-      }  else        out.println(" OK");
-      if (showBlocks)        out.println(report.toString());
+      }  else {
+        out.println(" OK");
+      }
+      if (showBlocks) {
+        out.println(report.toString());
+      }
     }
   }
   

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestFsck.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestFsck.java?view=diff&rev=500394&r1=500393&r2=500394
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestFsck.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestFsck.java Fri Jan 26 14:58:25 2007
@@ -18,14 +18,13 @@
 
 package org.apache.hadoop.dfs;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.Random;
 import junit.framework.*;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.dfs.MiniDFSCluster;
 import org.apache.hadoop.fs.*;
-import org.apache.hadoop.util.CopyFiles;
-
 
 /**
  * A JUnit test for doing fsck
@@ -143,7 +142,41 @@
       namenode = conf.get("fs.default.name", "local");
       if (!"local".equals(namenode)) {
         MyFile[] files = createFiles(namenode, "/srcdat");
+        PrintStream oldOut = System.out;
+        ByteArrayOutputStream bStream = new ByteArrayOutputStream();
+        PrintStream newOut = new PrintStream(bStream, true);
+        System.setOut(newOut);
         assertEquals(0, new DFSck().doMain(conf, new String[] {"/"}));
+        System.setOut(oldOut);
+        String outStr = bStream.toString();
+        assertTrue(-1 != outStr.indexOf("HEALTHY"));
+        System.out.println(outStr);
+        deldir(namenode, "/srcdat");
+      }
+    } finally {
+      if (cluster != null) { cluster.shutdown(); }
+    }
+  }
+  
+  /** do fsck on non-existent path*/
+  public void testFsckNonExistent() throws Exception {
+    String namenode = null;
+    MiniDFSCluster cluster = null;
+    try {
+      Configuration conf = new Configuration();
+      cluster = new MiniDFSCluster(65314, conf, 4, false);
+      namenode = conf.get("fs.default.name", "local");
+      if (!"local".equals(namenode)) {
+        MyFile[] files = createFiles(namenode, "/srcdat");
+        PrintStream oldOut = System.out;
+        ByteArrayOutputStream bStream = new ByteArrayOutputStream();
+        PrintStream newOut = new PrintStream(bStream, true);
+        System.setOut(newOut);
+        assertEquals(0, new DFSck().doMain(conf, new String[] {"/non-existent"}));
+        System.setOut(oldOut);
+        String outStr = bStream.toString();
+        assertEquals(-1, outStr.indexOf("HEALTHY"));
+        System.out.println(outStr);
         deldir(namenode, "/srcdat");
       }
     } finally {



Mime
View raw message