private void check(DFSFileInfo file, Result res) throws Exception {
if (file.isDir()) {
if (showFiles)
System.out.println(file.getPath() + " <dir>");
res.totalDirs++;
DFSFileInfo[] files = dfs.listFiles(new UTF8(file.getPath()));
for (int i = 0; i < files.length; i++) {
check(files[i], res);
}
return;
}
res.totalFiles++;
res.totalSize += file.getLen();
LocatedBlock[] blocks = dfs.namenode.open(file.getPath());
res.totalBlocks += blocks.length;
if (showFiles) {
System.out.print(file.getPath() + " " + file.getLen() + ", " + blocks.length + " block(s): ");
} else {
System.out.print('.');
System.out.flush();
if (res.totalFiles % 100 == 0) System.out.println();
}
int missing = 0;
long missize = 0;
StringBuffer report = new StringBuffer();
for (int i = 0; i < blocks.length; i++) {
Block block = blocks[i].getBlock();
long id = block.getBlockId();
DatanodeInfo[] locs = blocks[i].getLocations();
if (locs.length > res.replication) res.overReplicatedBlocks += (locs.length - res.replication);
if (locs.length < res.replication && locs.length > 0) res.underReplicatedBlocks += (res.replication - locs.length);
report.append(i + ". " + id + " len=" + block.getNumBytes());
if (locs == null || locs.length == 0) {
report.append(" MISSING!");
res.addMissing(block.getBlockName(), block.getNumBytes());
missing++;
missize += block.getNumBytes();
} else {
report.append(" repl=" + locs.length);
if (showLocations) {
StringBuffer sb = new StringBuffer("[");
for (int j = 0; j < locs.length; j++) {
if (j > 0) sb.append(", ");
sb.append(locs[j]);
}
sb.append(']');
report.append(" " + sb.toString());
}
}
report.append('\n');
}
if (missing > 0) {
if (!showFiles)
System.out.println("\nMISSING " + missing + " blocks of total size " + missize + " B");
res.corruptFiles++;
switch (fixing) {
case FIXING_NONE: // do nothing
System.err.println("\n - ignoring corrupted " + file.getPath());
break;
case FIXING_MOVE:
System.err.println("\n - moving to /lost+found: " + file.getPath());
lostFoundMove(file, blocks);
break;
case FIXING_DELETE:
System.err.println("\n - deleting corrupted " + file.getPath());
dfs.delete(new UTF8(file.getPath()));
}
}
if (showFiles) {
if (missing > 0) {
System.out.println(" MISSING " + missing + " blocks of total size " + missize + " B");