|
@@ -1617,6 +1617,21 @@ public class DataNode extends Configured
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Small wrapper around the DiskChecker class that provides means to mock
|
|
|
+ // DiskChecker static methods and unittest DataNode#getDataDirsFromURIs.
|
|
|
+ static class DataNodeDiskChecker {
|
|
|
+ private FsPermission expectedPermission;
|
|
|
+
|
|
|
+ public DataNodeDiskChecker(FsPermission expectedPermission) {
|
|
|
+ this.expectedPermission = expectedPermission;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkDir(LocalFileSystem localFS, Path path)
|
|
|
+ throws DiskErrorException, IOException {
|
|
|
+ DiskChecker.checkDir(localFS, path, expectedPermission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Make an instance of DataNode after ensuring that at least one of the
|
|
|
* given data directories (and their parent directories, if necessary)
|
|
@@ -1635,7 +1650,10 @@ public class DataNode extends Configured
|
|
|
FsPermission permission = new FsPermission(
|
|
|
conf.get(DFS_DATANODE_DATA_DIR_PERMISSION_KEY,
|
|
|
DFS_DATANODE_DATA_DIR_PERMISSION_DEFAULT));
|
|
|
- ArrayList<File> dirs = getDataDirsFromURIs(dataDirs, localFS, permission);
|
|
|
+ DataNodeDiskChecker dataNodeDiskChecker =
|
|
|
+ new DataNodeDiskChecker(permission);
|
|
|
+ ArrayList<File> dirs =
|
|
|
+ getDataDirsFromURIs(dataDirs, localFS, dataNodeDiskChecker);
|
|
|
DefaultMetricsSystem.initialize("DataNode");
|
|
|
|
|
|
assert dirs.size() > 0 : "number of data directories should be > 0";
|
|
@@ -1644,7 +1662,8 @@ public class DataNode extends Configured
|
|
|
|
|
|
// DataNode ctor expects AbstractList instead of List or Collection...
|
|
|
static ArrayList<File> getDataDirsFromURIs(Collection<URI> dataDirs,
|
|
|
- LocalFileSystem localFS, FsPermission permission) throws IOException {
|
|
|
+ LocalFileSystem localFS, DataNodeDiskChecker dataNodeDiskChecker)
|
|
|
+ throws IOException {
|
|
|
ArrayList<File> dirs = new ArrayList<File>();
|
|
|
StringBuilder invalidDirs = new StringBuilder();
|
|
|
for (URI dirURI : dataDirs) {
|
|
@@ -1656,7 +1675,7 @@ public class DataNode extends Configured
|
|
|
// drop any (illegal) authority in the URI for backwards compatibility
|
|
|
File dir = new File(dirURI.getPath());
|
|
|
try {
|
|
|
- DiskChecker.checkDir(localFS, new Path(dir.toURI()), permission);
|
|
|
+ dataNodeDiskChecker.checkDir(localFS, new Path(dir.toURI()));
|
|
|
dirs.add(dir);
|
|
|
} catch (IOException ioe) {
|
|
|
LOG.warn("Invalid " + DFS_DATANODE_DATA_DIR_KEY + " "
|