Skip to content

Commit 8559ba4

Browse files
tomscuttasanuma
authored andcommitted
HDFS-16327. Make DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY reconfigurable (#3716)
(cherry picked from commit c56a07f)
1 parent b0c1158 commit 8559ba4

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public class DatanodeManager {
214214
private static Set<String> slowNodesUuidSet = Sets.newConcurrentHashSet();
215215
private Daemon slowPeerCollectorDaemon;
216216
private final long slowPeerCollectionInterval;
217-
private final int maxSlowPeerReportNodes;
217+
private volatile int maxSlowPeerReportNodes;
218218

219219
@Nullable
220220
private final SlowDiskTracker slowDiskTracker;
@@ -515,6 +515,15 @@ public boolean getEnableAvoidSlowDataNodesForRead() {
515515
return this.avoidSlowDataNodesForRead;
516516
}
517517

518+
public void setMaxSlowpeerCollectNodes(int maxNodes) {
519+
this.maxSlowPeerReportNodes = maxNodes;
520+
}
521+
522+
@VisibleForTesting
523+
public int getMaxSlowpeerCollectNodes() {
524+
return this.maxSlowPeerReportNodes;
525+
}
526+
518527
/**
519528
* Sort the non-striped located blocks by the distance to the target host.
520529
*

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_DEFAULT;
191191
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY;
192192
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_DEFAULT;
193+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY;
194+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_DEFAULT;
193195

194196
import static org.apache.hadoop.util.ExitUtil.terminate;
195197
import static org.apache.hadoop.util.ToolRunner.confirmPrompt;
@@ -333,7 +335,8 @@ public enum OperationCategory {
333335
DFS_BLOCK_PLACEMENT_EC_CLASSNAME_KEY,
334336
DFS_IMAGE_PARALLEL_LOAD_KEY,
335337
DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_KEY,
336-
DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY));
338+
DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY,
339+
DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY));
337340

338341
private static final String USAGE = "Usage: hdfs namenode ["
339342
+ StartupOption.BACKUP.getName() + "] | \n\t["
@@ -2200,7 +2203,8 @@ protected String reconfigurePropertyImpl(String property, String newVal)
22002203
} else if (property.equals(DFS_IMAGE_PARALLEL_LOAD_KEY)) {
22012204
return reconfigureParallelLoad(newVal);
22022205
} else if (property.equals(DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_KEY)
2203-
|| (property.equals(DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY))) {
2206+
|| (property.equals(DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY))
2207+
|| (property.equals(DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY))) {
22042208
return reconfigureSlowNodesParameters(datanodeManager, property, newVal);
22052209
} else {
22062210
throw new ReconfigurationException(property, newVal, getConf().get(
@@ -2392,24 +2396,32 @@ String reconfigureSlowNodesParameters(final DatanodeManager datanodeManager,
23922396
final String property, final String newVal) throws ReconfigurationException {
23932397
BlockManager bm = namesystem.getBlockManager();
23942398
namesystem.writeLock();
2395-
boolean enable;
2399+
String result;
23962400
try {
23972401
if (property.equals(DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_KEY)) {
2398-
enable = (newVal == null ? DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_DEFAULT :
2402+
boolean enable = (newVal == null ? DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_DEFAULT :
23992403
Boolean.parseBoolean(newVal));
2404+
result = Boolean.toString(enable);
24002405
datanodeManager.setAvoidSlowDataNodesForReadEnabled(enable);
24012406
} else if (property.equals(
24022407
DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY)) {
2403-
enable = (newVal == null ?
2408+
boolean enable = (newVal == null ?
24042409
DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_DEFAULT :
24052410
Boolean.parseBoolean(newVal));
2411+
result = Boolean.toString(enable);
24062412
bm.setExcludeSlowNodesEnabled(enable);
2413+
} else if (property.equals(DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY)) {
2414+
int maxSlowpeerCollectNodes = (newVal == null ?
2415+
DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_DEFAULT :
2416+
Integer.parseInt(newVal));
2417+
result = Integer.toString(maxSlowpeerCollectNodes);
2418+
datanodeManager.setMaxSlowpeerCollectNodes(maxSlowpeerCollectNodes);
24072419
} else {
24082420
throw new IllegalArgumentException("Unexpected property " +
24092421
property + " in reconfigureSlowNodesParameters");
24102422
}
24112423
LOG.info("RECONFIGURE* changed {} to {}", property, newVal);
2412-
return Boolean.toString(enable);
2424+
return result;
24132425
} catch (IllegalArgumentException e) {
24142426
throw new ReconfigurationException(property, newVal, getConf().get(
24152427
property), e);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_INVALIDATE_LIMIT_KEY;
5656
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_KEY;
5757
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY;
58+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY;
5859
import static org.apache.hadoop.fs.CommonConfigurationKeys.IPC_BACKOFF_ENABLE_DEFAULT;
5960

6061
public class TestNameNodeReconfigure {
@@ -430,6 +431,24 @@ public void testEnableSlowNodesParametersAfterReconfigured()
430431
getExcludeSlowNodesEnabled(BlockType.STRIPED));
431432
}
432433

434+
@Test
435+
public void testReconfigureMaxSlowpeerCollectNodes()
436+
throws ReconfigurationException {
437+
final NameNode nameNode = cluster.getNameNode();
438+
final DatanodeManager datanodeManager = nameNode.namesystem
439+
.getBlockManager().getDatanodeManager();
440+
441+
// By default, DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is 5.
442+
assertEquals(5, datanodeManager.getMaxSlowpeerCollectNodes());
443+
444+
// Reconfigure.
445+
nameNode.reconfigureProperty(
446+
DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY, Integer.toString(10));
447+
448+
// Assert DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY is 10.
449+
assertEquals(10, datanodeManager.getMaxSlowpeerCollectNodes());
450+
}
451+
433452
@After
434453
public void shutDown() throws IOException {
435454
if (cluster != null) {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdmin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import java.util.Scanner;
8888
import java.util.concurrent.TimeoutException;
8989

90+
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY;
9091
import static org.hamcrest.CoreMatchers.allOf;
9192
import static org.hamcrest.CoreMatchers.anyOf;
9293
import static org.hamcrest.CoreMatchers.is;
@@ -424,14 +425,15 @@ public void testNameNodeGetReconfigurableProperties() throws IOException {
424425
final List<String> outs = Lists.newArrayList();
425426
final List<String> errs = Lists.newArrayList();
426427
getReconfigurableProperties("namenode", address, outs, errs);
427-
assertEquals(15, outs.size());
428+
assertEquals(16, outs.size());
428429
assertEquals(DFS_BLOCK_PLACEMENT_EC_CLASSNAME_KEY, outs.get(1));
429430
assertEquals(DFS_BLOCK_REPLICATOR_CLASSNAME_KEY, outs.get(2));
430431
assertEquals(DFS_HEARTBEAT_INTERVAL_KEY, outs.get(3));
431432
assertEquals(DFS_IMAGE_PARALLEL_LOAD_KEY, outs.get(4));
432433
assertEquals(DFS_NAMENODE_AVOID_SLOW_DATANODE_FOR_READ_KEY, outs.get(5));
433434
assertEquals(DFS_NAMENODE_BLOCKPLACEMENTPOLICY_EXCLUDE_SLOW_NODES_ENABLED_KEY, outs.get(6));
434435
assertEquals(DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, outs.get(7));
436+
assertEquals(DFS_NAMENODE_MAX_SLOWPEER_COLLECT_NODES_KEY, outs.get(8));
435437
assertEquals(errs.size(), 0);
436438
}
437439

0 commit comments

Comments
 (0)