Catch NoSuchDirectoryException on consistency check - the directory might not be there anymore

This commit is contained in:
Simon Willnauer 2014-11-04 14:29:21 +01:00
parent 7a6fb892c9
commit 8163107be5
1 changed files with 25 additions and 20 deletions

View File

@ -210,29 +210,34 @@ public final class DistributorDirectory extends BaseDirectory {
static boolean assertConsistency(ESLogger logger, DistributorDirectory dir) throws IOException { static boolean assertConsistency(ESLogger logger, DistributorDirectory dir) throws IOException {
boolean consistent = true; boolean consistent = true;
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
Directory[] all = dir.distributor.all(); try {
for (Directory d : all) { Directory[] all = dir.distributor.all();
for (String file : d.listAll()) { for (Directory d : all) {
final Directory directory = dir.nameDirMapping.get(file); for (String file : d.listAll()) {
if (directory == null) { final Directory directory = dir.nameDirMapping.get(file);
consistent = false; if (directory == null) {
builder.append("File ").append(file) consistent = false;
.append(" was not mapped to a directory but exists in one of the distributors directories") builder.append("File ").append(file)
.append(System.lineSeparator()); .append(" was not mapped to a directory but exists in one of the distributors directories")
} .append(System.lineSeparator());
if (directory != d) { }
consistent = false; if (directory != d) {
builder.append("File ").append(file).append(" was mapped to a directory ").append(directory) consistent = false;
.append(" but exists in another distributor directory").append(d) builder.append("File ").append(file).append(" was mapped to a directory ").append(directory)
.append(System.lineSeparator()); .append(" but exists in another distributor directory").append(d)
} .append(System.lineSeparator());
}
}
} }
if (consistent == false) {
logger.info(builder.toString());
}
assert consistent: builder.toString();
} catch (NoSuchDirectoryException ex) {
// that's fine - we can't check the directory since we might have already been wiped by a shutdown or
// a test cleanup ie the directory is not there anymore.
} }
if (consistent == false) {
logger.info(builder.toString());
}
assert consistent: builder.toString();
return consistent; // return boolean so it can be easily be used in asserts return consistent; // return boolean so it can be easily be used in asserts
} }