Make NodeEnvironment.getFileStore a bit more defensive

This improves the NodeEnvironment code that walks through all mount
points looking for the one matching the file store for a specified
path, to make it a bit more defensive.  We currently rely on this to
log the correct file system type of the path.data paths.

Closes #10696
This commit is contained in:
Michael McCandless 2015-04-22 06:24:42 -04:00 committed by mikemccand
parent f857f9e47c
commit 4d2bc25b1f
1 changed files with 22 additions and 3 deletions

View File

@ -300,12 +300,26 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
try { try {
String mount = getMountPoint(store); String mount = getMountPoint(store);
// find the "matching" FileStore from system list, it's the one we want. FileStore sameMountPoint = null;
for (FileStore fs : path.getFileSystem().getFileStores()) { for (FileStore fs : path.getFileSystem().getFileStores()) {
if (mount.equals(getMountPoint(fs))) { if (mount.equals(getMountPoint(fs))) {
return fs; if (sameMountPoint == null) {
sameMountPoint = fs;
} else {
// more than one filesystem has the same mount point; something is wrong!
// fall back to crappy one we got from Files.getFileStore
return store;
}
} }
} }
if (sameMountPoint != null) {
// ok, we found only one, use it:
return sameMountPoint;
} else {
// fall back to crappy one we got from Files.getFileStore
return store;
}
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
@ -319,7 +333,12 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
// these are hacks that are not guaranteed // these are hacks that are not guaranteed
private static String getMountPoint(FileStore store) { private static String getMountPoint(FileStore store) {
String desc = store.toString(); String desc = store.toString();
return desc.substring(0, desc.lastIndexOf('(') - 1); int index = desc.lastIndexOf(" (");
if (index != -1) {
return desc.substring(0, index);
} else {
return desc;
}
} }
/** /**