|
@@ -41,6 +41,8 @@ import java.util.List;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.LEAF_SCHEMA;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.LEAF_SCHEMA;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.RACK_SCHEMA;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.RACK_SCHEMA;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.ROOT_SCHEMA;
|
|
import static org.apache.hadoop.hdds.scm.net.NetConstants.ROOT_SCHEMA;
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
+import static org.junit.Assert.fail;
|
|
import static org.mockito.Matchers.anyObject;
|
|
import static org.mockito.Matchers.anyObject;
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
@@ -58,6 +60,7 @@ public class TestSCMContainerPlacementRackAware {
|
|
private SCMContainerPlacementRackAware policyNoFallback;
|
|
private SCMContainerPlacementRackAware policyNoFallback;
|
|
// node storage capacity
|
|
// node storage capacity
|
|
private static final long STORAGE_CAPACITY = 100L;
|
|
private static final long STORAGE_CAPACITY = 100L;
|
|
|
|
+ private SCMContainerPlacementMetrics metrics;
|
|
|
|
|
|
@Before
|
|
@Before
|
|
public void setup() {
|
|
public void setup() {
|
|
@@ -93,10 +96,11 @@ public class TestSCMContainerPlacementRackAware {
|
|
.thenReturn(new SCMNodeMetric(STORAGE_CAPACITY, 70L, 30L));
|
|
.thenReturn(new SCMNodeMetric(STORAGE_CAPACITY, 70L, 30L));
|
|
|
|
|
|
// create placement policy instances
|
|
// create placement policy instances
|
|
- policy =
|
|
|
|
- new SCMContainerPlacementRackAware(nodeManager, conf, cluster, true);
|
|
|
|
- policyNoFallback =
|
|
|
|
- new SCMContainerPlacementRackAware(nodeManager, conf, cluster, false);
|
|
|
|
|
|
+ metrics = SCMContainerPlacementMetrics.create();
|
|
|
|
+ policy = new SCMContainerPlacementRackAware(
|
|
|
|
+ nodeManager, conf, cluster, true, metrics);
|
|
|
|
+ policyNoFallback = new SCMContainerPlacementRackAware(
|
|
|
|
+ nodeManager, conf, cluster, false, metrics);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -181,7 +185,6 @@ public class TestSCMContainerPlacementRackAware {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testFallback() throws SCMException {
|
|
public void testFallback() throws SCMException {
|
|
-
|
|
|
|
// 5 replicas. there are only 3 racks. policy with fallback should
|
|
// 5 replicas. there are only 3 racks. policy with fallback should
|
|
// allocate the 5th datanode though it will break the rack rule(first
|
|
// allocate the 5th datanode though it will break the rack rule(first
|
|
// 2 replicas on same rack, others on different racks).
|
|
// 2 replicas on same rack, others on different racks).
|
|
@@ -195,14 +198,45 @@ public class TestSCMContainerPlacementRackAware {
|
|
datanodeDetails.get(2)));
|
|
datanodeDetails.get(2)));
|
|
Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(1),
|
|
Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(1),
|
|
datanodeDetails.get(2)));
|
|
datanodeDetails.get(2)));
|
|
- }
|
|
|
|
|
|
+ Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(0),
|
|
|
|
+ datanodeDetails.get(3)));
|
|
|
|
+ Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(2),
|
|
|
|
+ datanodeDetails.get(3)));
|
|
|
|
|
|
|
|
+ // get metrics
|
|
|
|
+ long totalRequest = metrics.getDatanodeRequestCount();
|
|
|
|
+ long successCount = metrics.getDatanodeChooseSuccessCount();
|
|
|
|
+ long tryCount = metrics.getDatanodeChooseAttemptCount();
|
|
|
|
+ long compromiseCount = metrics.getDatanodeChooseFallbackCount();
|
|
|
|
|
|
- @Test(expected = SCMException.class)
|
|
|
|
|
|
+ // verify metrics
|
|
|
|
+ Assert.assertTrue(totalRequest == nodeNum);
|
|
|
|
+ Assert.assertTrue(successCount == nodeNum);
|
|
|
|
+ Assert.assertTrue(tryCount > nodeNum);
|
|
|
|
+ Assert.assertTrue(compromiseCount >= 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
public void testNoFallback() throws SCMException {
|
|
public void testNoFallback() throws SCMException {
|
|
// 5 replicas. there are only 3 racks. policy prohibit fallback should fail.
|
|
// 5 replicas. there are only 3 racks. policy prohibit fallback should fail.
|
|
int nodeNum = 5;
|
|
int nodeNum = 5;
|
|
- policyNoFallback.chooseDatanodes(null, null, nodeNum, 15);
|
|
|
|
|
|
+ try {
|
|
|
|
+ policyNoFallback.chooseDatanodes(null, null, nodeNum, 15);
|
|
|
|
+ fail("Fallback prohibited, this call should fail");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ assertTrue(e.getClass().getSimpleName().equals("SCMException"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // get metrics
|
|
|
|
+ long totalRequest = metrics.getDatanodeRequestCount();
|
|
|
|
+ long successCount = metrics.getDatanodeChooseSuccessCount();
|
|
|
|
+ long tryCount = metrics.getDatanodeChooseAttemptCount();
|
|
|
|
+ long compromiseCount = metrics.getDatanodeChooseFallbackCount();
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(totalRequest == nodeNum);
|
|
|
|
+ Assert.assertTrue(successCount >= 3);
|
|
|
|
+ Assert.assertTrue(tryCount >= nodeNum);
|
|
|
|
+ Assert.assertTrue(compromiseCount == 0);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -244,11 +278,28 @@ public class TestSCMContainerPlacementRackAware {
|
|
.equals(favoredNodes.get(0).getNetworkFullPath()));
|
|
.equals(favoredNodes.get(0).getNetworkFullPath()));
|
|
}
|
|
}
|
|
|
|
|
|
- @Test(expected = SCMException.class)
|
|
|
|
|
|
+ @Test
|
|
public void testNoInfiniteLoop() throws SCMException {
|
|
public void testNoInfiniteLoop() throws SCMException {
|
|
int nodeNum = 1;
|
|
int nodeNum = 1;
|
|
- // request storage space larger than node capability
|
|
|
|
- policy.chooseDatanodes(null, null, nodeNum, STORAGE_CAPACITY + 15);
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // request storage space larger than node capability
|
|
|
|
+ policy.chooseDatanodes(null, null, nodeNum, STORAGE_CAPACITY + 15);
|
|
|
|
+ fail("Storage requested exceeds capacity, this call should fail");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ assertTrue(e.getClass().getSimpleName().equals("SCMException"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // get metrics
|
|
|
|
+ long totalRequest = metrics.getDatanodeRequestCount();
|
|
|
|
+ long successCount = metrics.getDatanodeChooseSuccessCount();
|
|
|
|
+ long tryCount = metrics.getDatanodeChooseAttemptCount();
|
|
|
|
+ long compromiseCount = metrics.getDatanodeChooseFallbackCount();
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(totalRequest == nodeNum);
|
|
|
|
+ Assert.assertTrue(successCount == 0);
|
|
|
|
+ Assert.assertTrue(tryCount > nodeNum);
|
|
|
|
+ Assert.assertTrue(compromiseCount == 0);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -270,7 +321,8 @@ public class TestSCMContainerPlacementRackAware {
|
|
// choose nodes to host 3 replica
|
|
// choose nodes to host 3 replica
|
|
int nodeNum = 3;
|
|
int nodeNum = 3;
|
|
SCMContainerPlacementRackAware newPolicy =
|
|
SCMContainerPlacementRackAware newPolicy =
|
|
- new SCMContainerPlacementRackAware(nodeManager, conf, clusterMap, true);
|
|
|
|
|
|
+ new SCMContainerPlacementRackAware(nodeManager, conf, clusterMap, true,
|
|
|
|
+ metrics);
|
|
List<DatanodeDetails> datanodeDetails =
|
|
List<DatanodeDetails> datanodeDetails =
|
|
newPolicy.chooseDatanodes(null, null, nodeNum, 15);
|
|
newPolicy.chooseDatanodes(null, null, nodeNum, 15);
|
|
Assert.assertEquals(nodeNum, datanodeDetails.size());
|
|
Assert.assertEquals(nodeNum, datanodeDetails.size());
|