use of org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState.HEALTHY in project ozone by apache.
the class TestReplicationManager method additionalReplicaScheduledWhenMisReplicated.
@Test
public void additionalReplicaScheduledWhenMisReplicated() throws IOException {
final ContainerInfo container = getContainer(LifeCycleState.CLOSED);
container.setUsedBytes(100);
final ContainerID id = container.containerID();
final UUID originNodeId = UUID.randomUUID();
final ContainerReplica replicaOne = getReplicas(id, State.CLOSED, 1000L, originNodeId, randomDatanodeDetails());
final ContainerReplica replicaTwo = getReplicas(id, State.CLOSED, 1000L, originNodeId, randomDatanodeDetails());
final ContainerReplica replicaThree = getReplicas(id, State.CLOSED, 1000L, originNodeId, randomDatanodeDetails());
containerStateManager.addContainer(container.getProtobuf());
containerStateManager.updateContainerReplica(id, replicaOne);
containerStateManager.updateContainerReplica(id, replicaTwo);
containerStateManager.updateContainerReplica(id, replicaThree);
// Ensure a mis-replicated status is returned for any containers in this
// test where there are 3 replicas. When there are 2 or 4 replicas
// the status returned will be healthy.
Mockito.when(containerPlacementPolicy.validateContainerPlacement(Mockito.argThat(list -> list.size() == 3), Mockito.anyInt())).thenAnswer(invocation -> {
return new ContainerPlacementStatusDefault(1, 2, 3);
});
int currentReplicateCommandCount = datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.replicateContainerCommand);
final long currentBytesToReplicate = replicationManager.getMetrics().getNumReplicationBytesTotal();
replicationManager.processAll();
eventQueue.processAll(1000);
// At this stage, due to the mocked calls to validateContainerPlacement
// the policy will not be satisfied, and replication will be triggered.
Assert.assertEquals(currentReplicateCommandCount + 1, datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.replicateContainerCommand));
Assert.assertEquals(currentReplicateCommandCount + 1, replicationManager.getMetrics().getNumReplicationCmdsSent());
Assert.assertEquals(currentBytesToReplicate + 100, replicationManager.getMetrics().getNumReplicationBytesTotal());
Assert.assertEquals(1, replicationManager.getInflightReplication().size());
Assert.assertEquals(1, replicationManager.getMetrics().getInflightReplication());
ReplicationManagerReport report = replicationManager.getContainerReport();
Assert.assertEquals(1, report.getStat(LifeCycleState.CLOSED));
Assert.assertEquals(1, report.getStat(ReplicationManagerReport.HealthState.MIS_REPLICATED));
// Now make it so that all containers seem mis-replicated no matter how
// many replicas. This will test replicas are not scheduled if the new
// replica does not fix the mis-replication.
Mockito.when(containerPlacementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenAnswer(invocation -> {
return new ContainerPlacementStatusDefault(1, 2, 3);
});
currentReplicateCommandCount = datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.replicateContainerCommand);
replicationManager.processAll();
eventQueue.processAll(1000);
// At this stage, due to the mocked calls to validateContainerPlacement
// the mis-replicated racks will not have improved, so expect to see nothing
// scheduled.
Assert.assertEquals(currentReplicateCommandCount, datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.replicateContainerCommand));
Assert.assertEquals(currentReplicateCommandCount, replicationManager.getMetrics().getNumReplicationCmdsSent());
Assert.assertEquals(1, replicationManager.getInflightReplication().size());
Assert.assertEquals(1, replicationManager.getMetrics().getInflightReplication());
}
use of org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState.HEALTHY in project ozone by apache.
the class TestReplicationManager method testOverReplicatedClosedContainerWithDecomAndMaint.
/**
* When a CLOSED container is over replicated, ReplicationManager
* deletes the excess replicas. While choosing the replica for deletion
* ReplicationManager should not attempt to remove a DECOMMISSION or
* MAINTENANCE replica.
*/
@Test
public void testOverReplicatedClosedContainerWithDecomAndMaint() throws IOException {
final ContainerInfo container = createContainer(LifeCycleState.CLOSED);
addReplica(container, NodeStatus.inServiceHealthy(), CLOSED);
addReplica(container, new NodeStatus(DECOMMISSIONED, HEALTHY), CLOSED);
addReplica(container, new NodeStatus(IN_MAINTENANCE, HEALTHY), CLOSED);
addReplica(container, NodeStatus.inServiceHealthy(), CLOSED);
addReplica(container, NodeStatus.inServiceHealthy(), CLOSED);
addReplica(container, NodeStatus.inServiceHealthy(), CLOSED);
addReplica(container, NodeStatus.inServiceHealthy(), CLOSED);
final int currentDeleteCommandCount = datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.deleteContainerCommand);
replicationManager.processAll();
eventQueue.processAll(1000);
Assert.assertEquals(currentDeleteCommandCount + 2, datanodeCommandHandler.getInvocationCount(SCMCommandProto.Type.deleteContainerCommand));
Assert.assertEquals(currentDeleteCommandCount + 2, replicationManager.getMetrics().getNumDeletionCmdsSent());
Assert.assertEquals(1, replicationManager.getInflightDeletion().size());
Assert.assertEquals(1, replicationManager.getMetrics().getInflightDeletion());
// Get the DECOM and Maint replica and ensure none of them are scheduled
// for removal
Set<ContainerReplica> decom = containerStateManager.getContainerReplicas(container.containerID()).stream().filter(r -> r.getDatanodeDetails().getPersistedOpState() != IN_SERVICE).collect(Collectors.toSet());
for (ContainerReplica r : decom) {
Assert.assertFalse(datanodeCommandHandler.received(SCMCommandProto.Type.deleteContainerCommand, r.getDatanodeDetails()));
}
assertOverReplicatedCount(1);
}
Aggregations