Search in sources :

Example 1 with ContainerPlacementStatus

use of org.apache.hadoop.hdds.scm.ContainerPlacementStatus in project ozone by apache.

the class ReplicationManager method deleteSrcDnForMove.

/**
 * if the container is in inflightMove, handle move.
 * This function assumes replication has been completed
 *
 * @param cif ContainerInfo
 * @param replicaSet An Set of replicas, which may have excess replicas
 */
private void deleteSrcDnForMove(final ContainerInfo cif, final Set<ContainerReplica> replicaSet) {
    final ContainerID cid = cif.containerID();
    MoveDataNodePair movePair = moveScheduler.getMoveDataNodePair(cid);
    if (movePair == null) {
        return;
    }
    final DatanodeDetails srcDn = movePair.getSrc();
    ContainerReplicaCount replicaCount = getContainerReplicaCount(cif, replicaSet);
    if (!replicaSet.stream().anyMatch(r -> r.getDatanodeDetails().equals(srcDn))) {
        // if the target is present but source disappears somehow,
        // we can consider move is successful.
        compleleteMoveFutureWithResult(cid, MoveResult.COMPLETED);
        moveScheduler.completeMove(cid.getProtobuf());
        return;
    }
    int replicationFactor = cif.getReplicationConfig().getRequiredNodes();
    ContainerPlacementStatus currentCPS = getPlacementStatus(replicaSet, replicationFactor);
    Set<ContainerReplica> newReplicaSet = replicaSet.stream().collect(Collectors.toSet());
    newReplicaSet.removeIf(r -> r.getDatanodeDetails().equals(srcDn));
    ContainerPlacementStatus newCPS = getPlacementStatus(newReplicaSet, replicationFactor);
    if (replicaCount.isOverReplicated() && isPlacementStatusActuallyEqual(currentCPS, newCPS)) {
        sendDeleteCommand(cif, srcDn, true);
    } else {
        // if source and target datanode are both in the replicaset,
        // but we can not delete source datanode for now (e.g.,
        // there is only 3 replicas or not policy-statisfied , etc.),
        // we just complete the future without sending a delete command.
        LOG.info("can not remove source replica after successfully " + "replicated to target datanode");
        compleleteMoveFutureWithResult(cid, MoveResult.DELETE_FAIL_POLICY);
        moveScheduler.completeMove(cid.getProtobuf());
    }
}
Also used : ConfigGroup(org.apache.hadoop.hdds.conf.ConfigGroup) ScmConfigKeys(org.apache.hadoop.hdds.scm.ScmConfigKeys) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) NodeStatus(org.apache.hadoop.hdds.scm.node.NodeStatus) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand) LoggerFactory(org.slf4j.LoggerFactory) ConfigurationSource(org.apache.hadoop.hdds.conf.ConfigurationSource) EventPublisher(org.apache.hadoop.hdds.server.events.EventPublisher) Duration(java.time.Duration) Map(java.util.Map) SCMHAManager(org.apache.hadoop.hdds.scm.ha.SCMHAManager) ReplicateContainerCommand(org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand) HddsConfigKeys(org.apache.hadoop.hdds.HddsConfigKeys) ConfigType(org.apache.hadoop.hdds.conf.ConfigType) Predicate(java.util.function.Predicate) MOVE(org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType.MOVE) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ExitUtil(org.apache.hadoop.util.ExitUtil) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus) CommandForDatanode(org.apache.hadoop.ozone.protocol.commands.CommandForDatanode) List(java.util.List) StorageUnit(org.apache.hadoop.hdds.conf.StorageUnit) PlacementPolicy(org.apache.hadoop.hdds.scm.PlacementPolicy) Config(org.apache.hadoop.hdds.conf.Config) MoveDataNodePair(org.apache.hadoop.hdds.scm.container.common.helpers.MoveDataNodePair) SCMServiceManager(org.apache.hadoop.hdds.scm.ha.SCMServiceManager) SCMHAInvocationHandler(org.apache.hadoop.hdds.scm.ha.SCMHAInvocationHandler) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) Proxy(java.lang.reflect.Proxy) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) HealthState(org.apache.hadoop.hdds.scm.container.ReplicationManagerReport.HealthState) CURRENT_VERSION(org.apache.hadoop.ozone.ClientVersions.CURRENT_VERSION) Preconditions(org.apache.ratis.util.Preconditions) Replicate(org.apache.hadoop.hdds.scm.metadata.Replicate) NodeOperationalState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState) CompletableFuture(java.util.concurrent.CompletableFuture) SCMContext(org.apache.hadoop.hdds.scm.ha.SCMContext) SCMRatisServer(org.apache.hadoop.hdds.scm.ha.SCMRatisServer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) LifeCycleState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState) NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) SCMService(org.apache.hadoop.hdds.scm.ha.SCMService) NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException) CloseContainerCommand(org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand) GeneratedMessage(com.google.protobuf.GeneratedMessage) LinkedList(java.util.LinkedList) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) DBTransactionBuffer(org.apache.hadoop.hdds.scm.metadata.DBTransactionBuffer) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) State(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto.State) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) IOException(java.io.IOException) SCMEvents(org.apache.hadoop.hdds.scm.events.SCMEvents) NodeState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Lock(java.util.concurrent.locks.Lock) OZONE(org.apache.hadoop.hdds.conf.ConfigTag.OZONE) Table(org.apache.hadoop.hdds.utils.db.Table) SCM(org.apache.hadoop.hdds.conf.ConfigTag.SCM) Clock(java.time.Clock) ReplicationManagerMetrics(org.apache.hadoop.hdds.scm.container.replication.ReplicationManagerMetrics) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) TableIterator(org.apache.hadoop.hdds.utils.db.TableIterator) Collections(java.util.Collections) SCMCommand(org.apache.hadoop.ozone.protocol.commands.SCMCommand) MoveDataNodePair(org.apache.hadoop.hdds.scm.container.common.helpers.MoveDataNodePair) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus)

Example 2 with ContainerPlacementStatus

use of org.apache.hadoop.hdds.scm.ContainerPlacementStatus in project ozone by apache.

the class ReplicationManager method removeExcessReplicasIfNeeded.

/**
 * remove execess replicas if needed, replicationFactor and placement policy
 * will be take into consideration.
 *
 * @param excess the excess number after subtracting replicationFactor
 * @param container ContainerInfo
 * @param eligibleReplicas An list of replicas, which may have excess replicas
 */
private void removeExcessReplicasIfNeeded(int excess, final ContainerInfo container, final List<ContainerReplica> eligibleReplicas) {
    // make the container become mis-replicated.
    if (excess > 0) {
        Set<ContainerReplica> eligibleSet = new HashSet<>(eligibleReplicas);
        final int replicationFactor = container.getReplicationConfig().getRequiredNodes();
        ContainerPlacementStatus ps = getPlacementStatus(eligibleSet, replicationFactor);
        for (ContainerReplica r : eligibleReplicas) {
            if (excess <= 0) {
                break;
            }
            // First remove the replica we are working on from the set, and then
            // check if the set is now mis-replicated.
            eligibleSet.remove(r);
            ContainerPlacementStatus nowPS = getPlacementStatus(eligibleSet, replicationFactor);
            if (isPlacementStatusActuallyEqual(ps, nowPS)) {
                // Remove the replica if the container was already unsatisfied
                // and losing this replica keep actual placement count unchanged.
                // OR if losing this replica still keep satisfied
                sendDeleteCommand(container, r.getDatanodeDetails(), true);
                excess -= 1;
                continue;
            }
            // If we decided not to remove this replica, put it back into the set
            eligibleSet.add(r);
        }
        if (excess > 0) {
            LOG.info("The container {} is over replicated with {} excess " + "replica. The excess replicas cannot be removed without " + "violating the placement policy", container, excess);
        }
    }
}
Also used : ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus) HashSet(java.util.HashSet)

Example 3 with ContainerPlacementStatus

use of org.apache.hadoop.hdds.scm.ContainerPlacementStatus in project ozone by apache.

the class TestPipelinePlacementPolicy method testValidatePlacementPolicyOK.

@Test
public void testValidatePlacementPolicyOK() {
    cluster = initTopology();
    nodeManager = new MockNodeManager(cluster, getNodesWithRackAwareness(), false, PIPELINE_PLACEMENT_MAX_NODES_COUNT);
    placementPolicy = new PipelinePlacementPolicy(nodeManager, stateManager, conf);
    List<DatanodeDetails> dns = new ArrayList<>();
    dns.add(MockDatanodeDetails.createDatanodeDetails("host1", "/rack1"));
    dns.add(MockDatanodeDetails.createDatanodeDetails("host2", "/rack1"));
    dns.add(MockDatanodeDetails.createDatanodeDetails("host3", "/rack2"));
    for (DatanodeDetails dn : dns) {
        cluster.add(dn);
    }
    ContainerPlacementStatus status = placementPolicy.validateContainerPlacement(dns, 3);
    assertTrue(status.isPolicySatisfied());
    assertEquals(0, status.misReplicationCount());
    List<DatanodeDetails> subSet = new ArrayList<>();
    // Cut it down to two nodes, two racks
    subSet.add(dns.get(0));
    subSet.add(dns.get(2));
    status = placementPolicy.validateContainerPlacement(subSet, 3);
    assertTrue(status.isPolicySatisfied());
    assertEquals(0, status.misReplicationCount());
    // Cut it down to two nodes, one racks
    subSet = new ArrayList<>();
    subSet.add(dns.get(0));
    subSet.add(dns.get(1));
    status = placementPolicy.validateContainerPlacement(subSet, 3);
    assertFalse(status.isPolicySatisfied());
    assertEquals(1, status.misReplicationCount());
    // One node, but only one replica
    subSet = new ArrayList<>();
    subSet.add(dns.get(0));
    status = placementPolicy.validateContainerPlacement(subSet, 1);
    assertTrue(status.isPolicySatisfied());
}
Also used : MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ArrayList(java.util.ArrayList) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus) MockNodeManager(org.apache.hadoop.hdds.scm.container.MockNodeManager) Test(org.junit.Test)

Example 4 with ContainerPlacementStatus

use of org.apache.hadoop.hdds.scm.ContainerPlacementStatus in project ozone by apache.

the class TestPipelinePlacementPolicy method testValidatePlacementPolicySingleRackInCluster.

@Test
public void testValidatePlacementPolicySingleRackInCluster() {
    cluster = initTopology();
    nodeManager = new MockNodeManager(cluster, new ArrayList<>(), false, PIPELINE_PLACEMENT_MAX_NODES_COUNT);
    placementPolicy = new PipelinePlacementPolicy(nodeManager, stateManager, conf);
    List<DatanodeDetails> dns = new ArrayList<>();
    dns.add(MockDatanodeDetails.createDatanodeDetails("host1", "/rack1"));
    dns.add(MockDatanodeDetails.createDatanodeDetails("host2", "/rack1"));
    dns.add(MockDatanodeDetails.createDatanodeDetails("host3", "/rack1"));
    for (DatanodeDetails dn : dns) {
        cluster.add(dn);
    }
    ContainerPlacementStatus status = placementPolicy.validateContainerPlacement(dns, 3);
    assertTrue(status.isPolicySatisfied());
    assertEquals(0, status.misReplicationCount());
}
Also used : MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ArrayList(java.util.ArrayList) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus) MockNodeManager(org.apache.hadoop.hdds.scm.container.MockNodeManager) Test(org.junit.Test)

Example 5 with ContainerPlacementStatus

use of org.apache.hadoop.hdds.scm.ContainerPlacementStatus in project ozone by apache.

the class TestContainerBalancer method containerMoveSelectionShouldFollowPlacementPolicy.

@Test
public void containerMoveSelectionShouldFollowPlacementPolicy() {
    balancerConfiguration.setThreshold(10);
    balancerConfiguration.setMaxSizeToMovePerIteration(50 * OzoneConsts.GB);
    balancerConfiguration.setMaxDatanodesPercentageToInvolvePerIteration(100);
    containerBalancer.start(balancerConfiguration);
    // modify this after balancer is fully completed
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    containerBalancer.stop();
    Map<DatanodeDetails, ContainerMoveSelection> sourceToTargetMap = containerBalancer.getSourceToTargetMap();
    // satisfies placement policy
    for (Map.Entry<DatanodeDetails, ContainerMoveSelection> entry : sourceToTargetMap.entrySet()) {
        ContainerMoveSelection moveSelection = entry.getValue();
        ContainerID container = moveSelection.getContainerID();
        DatanodeDetails target = moveSelection.getTargetNode();
        List<DatanodeDetails> replicas = cidToReplicasMap.get(container).stream().map(ContainerReplica::getDatanodeDetails).collect(Collectors.toList());
        replicas.remove(entry.getKey());
        replicas.add(target);
        ContainerInfo containerInfo = cidToInfoMap.get(container);
        ContainerPlacementStatus placementStatus = placementPolicy.validateContainerPlacement(replicas, containerInfo.getReplicationConfig().getRequiredNodes());
        Assert.assertTrue(placementStatus.isPolicySatisfied());
    }
}
Also used : ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ContainerPlacementStatus (org.apache.hadoop.hdds.scm.ContainerPlacementStatus)12 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)10 ArrayList (java.util.ArrayList)8 Map (java.util.Map)5 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)5 NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)5 Test (org.junit.Test)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)3 IOException (java.io.IOException)3 Proxy (java.lang.reflect.Proxy)3 Clock (java.time.Clock)3 Duration (java.time.Duration)3 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3