Skip to content

Commit 4d22d1c

Browse files
committed
HDFS-15363. BlockPlacementPolicyWithNodeGroup should validate if it is initialized by NetworkTopologyWithNodeGroup. Contributed by hemanthboyina.
1 parent 9685314 commit 4d22d1c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ protected BlockPlacementPolicyWithNodeGroup() {
4646
public void initialize(Configuration conf, FSClusterStats stats,
4747
NetworkTopology clusterMap,
4848
Host2NodesMap host2datanodeMap) {
49+
if (!(clusterMap instanceof NetworkTopologyWithNodeGroup)) {
50+
throw new IllegalArgumentException(
51+
"Configured cluster topology should be "
52+
+ NetworkTopologyWithNodeGroup.class.getName());
53+
}
4954
super.initialize(conf, stats, clusterMap, host2datanodeMap);
5055
}
5156

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyWithNodeGroup;
4848
import org.apache.hadoop.net.NetworkTopology;
4949
import org.apache.hadoop.net.NetworkTopologyWithNodeGroup;
50+
import org.apache.hadoop.test.LambdaTestUtils;
5051
import org.junit.Assert;
5152
import org.junit.Test;
5253

@@ -361,4 +362,30 @@ public void testBalancerEndInNoMoveProgress() throws Exception {
361362
cluster.shutdown();
362363
}
363364
}
365+
366+
/**
367+
* verify BlockPlacementPolicyNodeGroup uses NetworkTopologyWithNodeGroup.
368+
*/
369+
370+
@Test
371+
public void testBPPNodeGroup() throws Exception {
372+
Configuration conf = createConf();
373+
conf.setBoolean(DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_KEY, true);
374+
long[] capacities = new long[] {CAPACITY, CAPACITY, CAPACITY, CAPACITY};
375+
String[] racks = new String[] {RACK0, RACK0, RACK1, RACK1};
376+
String[] nodeGroups =
377+
new String[] {NODEGROUP0, NODEGROUP0, NODEGROUP1, NODEGROUP2};
378+
379+
int numOfDatanodes = capacities.length;
380+
assertEquals(numOfDatanodes, racks.length);
381+
assertEquals(numOfDatanodes, nodeGroups.length);
382+
MiniDFSCluster.Builder builder =
383+
new MiniDFSCluster.Builder(conf).numDataNodes(capacities.length)
384+
.racks(racks).simulatedCapacities(capacities);
385+
MiniDFSClusterWithNodeGroup.setNodeGroups(nodeGroups);
386+
LambdaTestUtils.intercept(IllegalArgumentException.class,
387+
"Configured cluster topology should be "
388+
+ "org.apache.hadoop.net.NetworkTopologyWithNodeGroup",
389+
() -> new MiniDFSClusterWithNodeGroup(builder));
390+
}
364391
}

0 commit comments

Comments
 (0)