|
@@ -84,7 +84,6 @@ public class NamenodeFsck {
|
|
private String path = "/";
|
|
private String path = "/";
|
|
|
|
|
|
private Configuration conf;
|
|
private Configuration conf;
|
|
- private HttpServletResponse response;
|
|
|
|
private PrintWriter out;
|
|
private PrintWriter out;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -101,7 +100,6 @@ public class NamenodeFsck {
|
|
HttpServletResponse response) throws IOException {
|
|
HttpServletResponse response) throws IOException {
|
|
this.conf = conf;
|
|
this.conf = conf;
|
|
this.nn = nn;
|
|
this.nn = nn;
|
|
- this.response = response;
|
|
|
|
this.out = response.getWriter();
|
|
this.out = response.getWriter();
|
|
for (Iterator<String> it = pmap.keySet().iterator(); it.hasNext();) {
|
|
for (Iterator<String> it = pmap.keySet().iterator(); it.hasNext();) {
|
|
String key = it.next();
|
|
String key = it.next();
|
|
@@ -127,12 +125,14 @@ public class NamenodeFsck {
|
|
for (int i = 0; i < files.length; i++) {
|
|
for (int i = 0; i < files.length; i++) {
|
|
check(files[i], res);
|
|
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 {
|
|
} finally {
|
|
out.close();
|
|
out.close();
|
|
@@ -141,8 +141,9 @@ public class NamenodeFsck {
|
|
|
|
|
|
private void check(DFSFileInfo file, FsckResult res) throws IOException {
|
|
private void check(DFSFileInfo file, FsckResult res) throws IOException {
|
|
if (file.isDir()) {
|
|
if (file.isDir()) {
|
|
- if (showFiles)
|
|
|
|
|
|
+ if (showFiles) {
|
|
out.println(file.getPath() + " <dir>");
|
|
out.println(file.getPath() + " <dir>");
|
|
|
|
+ }
|
|
res.totalDirs++;
|
|
res.totalDirs++;
|
|
DFSFileInfo[] files = nn.getListing(file.getPath());
|
|
DFSFileInfo[] files = nn.getListing(file.getPath());
|
|
for (int i = 0; i < files.length; i++) {
|
|
for (int i = 0; i < files.length; i++) {
|
|
@@ -160,7 +161,7 @@ public class NamenodeFsck {
|
|
} else {
|
|
} else {
|
|
out.print('.');
|
|
out.print('.');
|
|
out.flush();
|
|
out.flush();
|
|
- if (res.totalFiles % 100 == 0) out.println();
|
|
|
|
|
|
+ if (res.totalFiles % 100 == 0) { out.println(); }
|
|
}
|
|
}
|
|
int missing = 0;
|
|
int missing = 0;
|
|
long missize = 0;
|
|
long missize = 0;
|
|
@@ -170,8 +171,12 @@ public class NamenodeFsck {
|
|
long id = block.getBlockId();
|
|
long id = block.getBlockId();
|
|
DatanodeInfo[] locs = blocks[i].getLocations();
|
|
DatanodeInfo[] locs = blocks[i].getLocations();
|
|
short targetFileReplication = file.getReplication();
|
|
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());
|
|
report.append(i + ". " + id + " len=" + block.getNumBytes());
|
|
if (locs == null || locs.length == 0) {
|
|
if (locs == null || locs.length == 0) {
|
|
report.append(" MISSING!");
|
|
report.append(" MISSING!");
|
|
@@ -183,7 +188,7 @@ public class NamenodeFsck {
|
|
if (showLocations) {
|
|
if (showLocations) {
|
|
StringBuffer sb = new StringBuffer("[");
|
|
StringBuffer sb = new StringBuffer("[");
|
|
for (int j = 0; j < locs.length; j++) {
|
|
for (int j = 0; j < locs.length; j++) {
|
|
- if (j > 0) sb.append(", ");
|
|
|
|
|
|
+ if (j > 0) { sb.append(", "); }
|
|
sb.append(locs[j]);
|
|
sb.append(locs[j]);
|
|
}
|
|
}
|
|
sb.append(']');
|
|
sb.append(']');
|
|
@@ -193,8 +198,9 @@ public class NamenodeFsck {
|
|
report.append('\n');
|
|
report.append('\n');
|
|
}
|
|
}
|
|
if (missing > 0) {
|
|
if (missing > 0) {
|
|
- if (!showFiles)
|
|
|
|
|
|
+ if (!showFiles) {
|
|
out.println("\nMISSING " + missing + " blocks of total size " + missize + " B");
|
|
out.println("\nMISSING " + missing + " blocks of total size " + missize + " B");
|
|
|
|
+ }
|
|
res.corruptFiles++;
|
|
res.corruptFiles++;
|
|
switch(fixing) {
|
|
switch(fixing) {
|
|
case FIXING_NONE:
|
|
case FIXING_NONE:
|
|
@@ -209,8 +215,12 @@ public class NamenodeFsck {
|
|
if (showFiles) {
|
|
if (showFiles) {
|
|
if (missing > 0) {
|
|
if (missing > 0) {
|
|
out.println(" MISSING " + missing + " blocks of total size " + missize + " B");
|
|
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());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|