Skip to content

Commit cf7d519

Browse files
committed
HDFS-17655. Cannot run HDFS balancer with BlockPlacementPolicyWithNodeGroup
1 parent 7a7b346 commit cf7d519

File tree

2 files changed

+22
-1
lines changed
  • hadoop-hdfs-project/hadoop-hdfs/src

2 files changed

+22
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Balancer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.hadoop.metrics2.source.JvmMetrics;
4444
import org.apache.hadoop.classification.VisibleForTesting;
4545
import org.apache.hadoop.hdfs.DFSUtilClient;
46+
import org.apache.hadoop.net.NetworkTopology;
4647
import org.slf4j.Logger;
4748
import org.slf4j.LoggerFactory;
4849
import org.apache.hadoop.HadoopIllegalArgumentException;
@@ -243,7 +244,7 @@ public class Balancer {
243244
private static void checkReplicationPolicyCompatibility(Configuration conf
244245
) throws UnsupportedActionException {
245246
BlockPlacementPolicies placementPolicies =
246-
new BlockPlacementPolicies(conf, null, null, null);
247+
new BlockPlacementPolicies(conf, null, NetworkTopology.getInstance(conf), null);
247248
if (!(placementPolicies.getPolicy(CONTIGUOUS) instanceof
248249
BlockPlacementPolicyDefault)) {
249250
throw new UnsupportedActionException(

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hdfs.server.balancer;
1919

2020
import static org.apache.hadoop.fs.CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SASL_KEY;
21+
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.NET_TOPOLOGY_IMPL_KEY;
2122
import static org.apache.hadoop.fs.StorageType.DEFAULT;
2223
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY;
2324
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY;
@@ -40,6 +41,8 @@
4041

4142
import java.lang.reflect.Field;
4243
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
44+
import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyWithNodeGroup;
45+
import org.apache.hadoop.net.NetworkTopologyWithNodeGroup;
4346
import org.junit.AfterClass;
4447

4548
import static org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset.CONFIG_PROPERTY_NONDFSUSED;
@@ -1510,6 +1513,23 @@ public void testBalancerCliWithIncludeListWithPortsInAFile() throws Exception {
15101513
CAPACITY, RACK2, new PortNumberBasedNodes(3, 0, 1), true, true);
15111514
}
15121515

1516+
/**
1517+
* Test a cluster with BlockPlacementPolicyWithNodeGroup
1518+
*/
1519+
@Test(timeout=100000)
1520+
public void testBalancerCliWithBlockPlacementPolicyWithNodeGroup() throws Exception {
1521+
Configuration conf = new HdfsConfiguration();
1522+
initConf(conf);
1523+
conf.setBoolean(DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_KEY, false);
1524+
conf.set(NET_TOPOLOGY_IMPL_KEY,
1525+
NetworkTopologyWithNodeGroup.class.getName());
1526+
conf.set(DFSConfigKeys.DFS_BLOCK_REPLICATOR_CLASSNAME_KEY,
1527+
BlockPlacementPolicyWithNodeGroup.class.getName());
1528+
String rackWithNodeGroup = "/rack0/nodegroup0";
1529+
doTest(conf, new long[]{CAPACITY}, new String[]{rackWithNodeGroup}, CAPACITY/2,
1530+
rackWithNodeGroup, true);
1531+
}
1532+
15131533
/**
15141534
* Check that the balancer exits when there is an unfinalized upgrade.
15151535
*/

0 commit comments

Comments
 (0)