diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java index 2d710be29f..c6948547e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java @@ -147,6 +147,9 @@ public class MiniDFSCluster implements AutoCloseable { GenericTestUtils.SYSPROP_TEST_DATA_DIR; /** Configuration option to set the data dir: {@value} */ public static final String HDFS_MINIDFS_BASEDIR = "hdfs.minidfs.basedir"; + /** Configuration option to set the provided data dir: {@value} */ + public static final String HDFS_MINIDFS_BASEDIR_PROVIDED = + "hdfs.minidfs.basedir.provided"; public static final String DFS_NAMENODE_SAFEMODE_EXTENSION_TESTING_KEY = DFS_NAMENODE_SAFEMODE_EXTENSION_KEY + ".testing"; public static final String DFS_NAMENODE_DECOMMISSION_INTERVAL_TESTING_KEY @@ -1397,7 +1400,12 @@ String makeDataNodeDirs(int dnIndex, StorageType[] storageTypes) throws IOExcept if ((storageTypes != null) && (j >= storageTypes.length)) { break; } - File dir = getInstanceStorageDir(dnIndex, j); + File dir; + if (storageTypes != null && storageTypes[j] == StorageType.PROVIDED) { + dir = getProvidedStorageDir(dnIndex, j); + } else { + dir = getInstanceStorageDir(dnIndex, j); + } dir.mkdirs(); if (!dir.isDirectory()) { throw new IOException("Mkdirs failed to create directory for DataNode " + dir); @@ -2846,6 +2854,26 @@ public File getInstanceStorageDir(int dnIndex, int dirIndex) { return new File(base_dir, getStorageDirPath(dnIndex, dirIndex)); } + /** + * Get a storage directory for PROVIDED storages. + * The PROVIDED directory to return can be set by using the configuration + * parameter {@link #HDFS_MINIDFS_BASEDIR_PROVIDED}. If this parameter is + * not set, this function behaves exactly the same as + * {@link #getInstanceStorageDir(int, int)}. Currently, the two parameters + * are ignored as only one PROVIDED storage is supported in HDFS-9806. + * + * @param dnIndex datanode index (starts from 0) + * @param dirIndex directory index + * @return Storage directory + */ + public File getProvidedStorageDir(int dnIndex, int dirIndex) { + String base = conf.get(HDFS_MINIDFS_BASEDIR_PROVIDED, null); + if (base == null) { + return getInstanceStorageDir(dnIndex, dirIndex); + } + return new File(base); + } + /** * Get a storage directory for a datanode. *