Skip to content

Commit cbeabd2

Browse files
committed
HDFS-17824. DataNode fails to start when dfs.datanode.directoryscan.threads is 0 or negative.
1 parent 38f48fb commit cbeabd2

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DirectoryScanner.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ public DirectoryScanner(FsDatasetSpi<?> dataset, Configuration conf) {
313313
conf.getInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY,
314314
DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_DEFAULT);
315315

316+
if (threads <= 0) {
317+
LOG.warn("Invalid value configured for "
318+
+ DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY
319+
+ " ({}), must be greater than 0. Using default ({}).",
320+
threads, DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_DEFAULT);
321+
threads = DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_DEFAULT;
322+
}
323+
316324
reportCompileThreadPool =
317325
Executors.newFixedThreadPool(threads, new Daemon.DaemonFactory());
318326

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDirectoryScanner.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,34 @@ public void setup() {
128128
LazyPersistTestCase.initCacheManipulator();
129129
}
130130

131+
/**
132+
* HDFS-17824: When dfs.datanode.directoryscan.threads is 0 or negative,
133+
* DirectoryScanner should use the default instead of throwing
134+
* IllegalArgumentException from Executors.newFixedThreadPool(threads).
135+
*/
136+
@Test
137+
@Timeout(value = 30)
138+
public void testInvalidDirectoryScanThreadsUsesDefault() throws Exception {
139+
Configuration conf = getConfiguration();
140+
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY, 0);
141+
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
142+
try {
143+
cluster.waitActive();
144+
bpid = cluster.getNamesystem().getBlockPoolId();
145+
fds = DataNodeTestUtils.getFSDataset(cluster.getDataNodes().get(0));
146+
scanner = new DirectoryScanner(fds, conf);
147+
scanner.start();
148+
assertTrue(scanner.getRunStatus());
149+
} finally {
150+
if (scanner != null) {
151+
scanner.shutdown();
152+
}
153+
if (cluster != null) {
154+
cluster.shutdown();
155+
}
156+
}
157+
}
158+
131159
/** create a file with a length of <code>fileLen</code>. */
132160
private List<LocatedBlock> createFile(String fileNamePrefix, long fileLen,
133161
boolean isLazyPersist) throws IOException {

0 commit comments

Comments
 (0)