Skip to content

Commit eabf277

Browse files
committed
HDFS-11060. Make DEFAULT_MAX_CORRUPT_FILEBLOCKS_RETURNED configurable
1 parent 57187fd commit eabf277

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
225225
public static final int DFS_NAMENODE_MAINTENANCE_REPLICATION_MIN_DEFAULT
226226
= 1;
227227

228+
public static final String DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY = "dfs.namenode.max-corrupt-file-blocks-returned";
229+
public static final int DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_DEFAULT = 100;
230+
228231
public static final String DFS_NAMENODE_REPLICATION_MAX_STREAMS_KEY =
229232
HdfsClientConfigKeys.DeprecatedKeys.DFS_NAMENODE_REPLICATION_MAX_STREAMS_KEY;
230233
public static final int DFS_NAMENODE_REPLICATION_MAX_STREAMS_DEFAULT = 2;

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private void logAuditEvent(boolean succeeded,
384384
public static final Log auditLog = LogFactory.getLog(
385385
FSNamesystem.class.getName() + ".audit");
386386

387-
static final int DEFAULT_MAX_CORRUPT_FILEBLOCKS_RETURNED = 100;
387+
private final int maxCorruptFileBlocksReturn;
388388
static int BLOCK_DELETION_INCREMENT = 1000;
389389
private final boolean isPermissionEnabled;
390390
private final UserGroupInformation fsOwner;
@@ -778,6 +778,10 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
778778
DFSConfigKeys.DFS_NAMENODE_FILE_CLOSE_NUM_COMMITTED_ALLOWED_KEY,
779779
DFSConfigKeys.DFS_NAMENODE_FILE_CLOSE_NUM_COMMITTED_ALLOWED_DEFAULT);
780780

781+
this.maxCorruptFileBlocksReturn = conf.getInt(
782+
DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY,
783+
DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_DEFAULT);
784+
781785
this.dtpReplaceDatanodeOnFailure = ReplaceDatanodeOnFailure.get(conf);
782786

783787
this.standbyShouldCheckpoint = conf.getBoolean(
@@ -5003,7 +5007,7 @@ Collection<CorruptFileBlockInfo> listCorruptFileBlocks(String path,
50035007
if (src.startsWith(path)){
50045008
corruptFiles.add(new CorruptFileBlockInfo(src, blk));
50055009
count++;
5006-
if (count >= DEFAULT_MAX_CORRUPT_FILEBLOCKS_RETURNED)
5010+
if (count >= maxCorruptFileBlocksReturn)
50075011
break;
50085012
}
50095013
}

hadoop-hdfs-project/hadoop-hdfs/src/main/resources/hdfs-default.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@
566566
</description>
567567
</property>
568568

569+
<property>
570+
<name>dfs.namenode.max-corrupt-file-blocks-returned</name>
571+
<value>100</value>
572+
<description>
573+
The maximum number of corrupt file blocks listed by NameNode Web UI,
574+
JMX and other client request.
575+
</description>
576+
</property>
577+
569578
<property>
570579
<name>dfs.blocksize</name>
571580
<value>134217728</value>

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestListCorruptFileBlocks.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void testListCorruptFilesCorruptedBlock() throws Exception {
6767

6868
try {
6969
Configuration conf = new HdfsConfiguration();
70+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
7071
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); // datanode scans directories
7172
conf.setInt(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 3 * 1000); // datanode sends block reports
7273
// Set short retry timeouts so this test runs faster
@@ -138,6 +139,8 @@ public void testListCorruptFileBlocksInSafeMode() throws Exception {
138139

139140
try {
140141
Configuration conf = new HdfsConfiguration();
142+
// max list corrupt file blocks returned
143+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
141144
// datanode scans directories
142145
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1);
143146
// datanode sends block reports
@@ -260,6 +263,7 @@ public void testListCorruptFileBlocksInSafeMode() throws Exception {
260263
@Test (timeout=300000)
261264
public void testlistCorruptFileBlocks() throws Exception {
262265
Configuration conf = new Configuration();
266+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
263267
conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000);
264268
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); // datanode scans
265269
// directories
@@ -371,6 +375,7 @@ private int countPaths(RemoteIterator<Path> iter) throws IOException {
371375
@Test (timeout=300000)
372376
public void testlistCorruptFileBlocksDFS() throws Exception {
373377
Configuration conf = new Configuration();
378+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
374379
conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000);
375380
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); // datanode scans
376381
// directories
@@ -448,11 +453,12 @@ public void testMaxCorruptFiles() throws Exception {
448453
MiniDFSCluster cluster = null;
449454
try {
450455
Configuration conf = new HdfsConfiguration();
456+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 2 * 100);
451457
conf.setInt(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 3 * 1000); // datanode sends block reports
452458
cluster = new MiniDFSCluster.Builder(conf).build();
453459
FileSystem fs = cluster.getFileSystem();
454460
final int maxCorruptFileBlocks =
455-
FSNamesystem.DEFAULT_MAX_CORRUPT_FILEBLOCKS_RETURNED;
461+
conf.getInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
456462

457463
// create 110 files with one block each
458464
DFSTestUtil util = new DFSTestUtil.Builder().setName("testMaxCorruptFiles").
@@ -533,6 +539,7 @@ public void testMaxCorruptFiles() throws Exception {
533539
@Test(timeout = 60000)
534540
public void testListCorruptFileBlocksOnRelativePath() throws Exception {
535541
Configuration conf = new Configuration();
542+
conf.setInt(DFSConfigKeys.DFS_NAMENODE_MAX_CORRUPT_FILE_BLOCKS_RETURNED_KEY, 100);
536543
conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000);
537544
conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1);
538545

0 commit comments

Comments
 (0)