Author: cutting Date: Fri Feb 16 13:56:14 2007 New Revision: 508603 URL: http://svn.apache.org/viewvc?view=rev&rev=508603 Log: HADOOP-943. Improve HDFS's fsck command to display the filename for under-replicated blocks. Contributed by Dhruba.
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=508603&r1=508602&r2=508603 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Fri Feb 16 13:56:14 2007 @@ -65,6 +65,9 @@ 19. HADOOP-889. Remove duplicate code from HDFS unit tests. (Milind Bhandarkar via cutting) +20. HADOOP-943. Improve HDFS's fsck command to display the filename + for under-replicated blocks. (Dhruba Borthakur via cutting) + Branch 0.11 (unreleased) 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=508603&r1=508602&r2=508603 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/NamenodeFsck.java Fri Feb 16 13:56:14 2007 @@ -165,6 +165,7 @@ } int missing = 0; long missize = 0; + int under = 0; StringBuffer report = new StringBuffer(); for (int i = 0; i < blocks.length; i++) { Block block = blocks[i].getBlock(); @@ -173,9 +174,19 @@ short targetFileReplication = file.getReplication(); if (locs.length > targetFileReplication) { res.overReplicatedBlocks += (locs.length - targetFileReplication); + res.numOverReplicatedBlocks += 1; } if (locs.length < targetFileReplication && locs.length > 0) { res.underReplicatedBlocks += (targetFileReplication - locs.length); + res.numUnderReplicatedBlocks += 1; + under++; + if (!showFiles) { + out.print("\n" + file.getPath() + ": "); + } + out.println(" Under replicated " + block.getBlockName() + + ". Target Replicas is " + + targetFileReplication + " but found " + + locs.length + " replica(s)."); } report.append(i + ". " + id + " len=" + block.getNumBytes()); if (locs == null || locs.length == 0) { @@ -199,7 +210,9 @@ } if (missing > 0) { if (!showFiles) { - out.println("\nMISSING " + missing + " blocks of total size " + missize + " B"); + out.println("\n" + file.getPath() + ": " + + "MISSING " + missing + " blocks of total size " + + missize + " B."); } res.corruptFiles++; switch(fixing) { @@ -215,7 +228,7 @@ if (showFiles) { if (missing > 0) { out.println(" MISSING " + missing + " blocks of total size " + missize + " B"); - } else { + } else if (under == 0) { out.println(" OK"); } if (showBlocks) { @@ -460,6 +473,8 @@ private long corruptFiles = 0L; private long overReplicatedBlocks = 0L; private long underReplicatedBlocks = 0L; + private long numOverReplicatedBlocks = 0L; + private long numUnderReplicatedBlocks = 0L; private int replication = 0; private long totalBlocks = 0L; private long totalFiles = 0L; @@ -493,7 +508,7 @@ this.missingSize = missingSize; } - /** Return the number of over-replicsted blocks. */ + /** Return the number of over-replicated blocks. */ public long getOverReplicatedBlocks() { return overReplicatedBlocks; } @@ -584,10 +599,10 @@ res.append("\n MISSING SIZE:\t\t" + missingSize + " B"); res.append("\n ********************************"); } - res.append("\n Over-replicated blocks:\t" + overReplicatedBlocks); + res.append("\n Over-replicated blocks:\t" + numOverReplicatedBlocks); if (totalBlocks > 0) res.append(" (" + ((float) (overReplicatedBlocks * 100) / (float) totalBlocks) + " %)"); - res.append("\n Under-replicated blocks:\t" + underReplicatedBlocks); - if (totalBlocks > 0) res.append(" (" + ((float) (underReplicatedBlocks * 100) / (float) totalBlocks) + " %)"); + res.append("\n Under-replicated blocks:\t" + numUnderReplicatedBlocks); + if (totalBlocks > 0) res.append(" (" + ((float) (numUnderReplicatedBlocks * 100) / (float) totalBlocks) + " %)"); res.append("\n Target replication factor:\t" + replication); res.append("\n Real replication factor:\t" + getReplicationFactor()); return res.toString();