Search in sources :

Example 1 with PlacementPolicy

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

the class TestContainerHealthTaskRecordGenerator method setup.

@Before
public void setup() {
    placementPolicy = mock(PlacementPolicy.class);
    container = mock(ContainerInfo.class);
    when(container.getReplicationConfig()).thenReturn(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE));
    when(container.containerID()).thenReturn(ContainerID.valueOf(123456));
    when(container.getContainerID()).thenReturn((long) 123456);
    when(placementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenReturn(new ContainerPlacementStatusDefault(1, 1, 1));
}
Also used : PlacementPolicy(org.apache.hadoop.hdds.scm.PlacementPolicy) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) ContainerPlacementStatusDefault(org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault) Before(org.junit.Before)

Example 2 with PlacementPolicy

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

the class TestContainerPlacementFactory method testRackAwarePolicy.

@Test
public void testRackAwarePolicy() throws IOException {
    conf.set(ScmConfigKeys.OZONE_SCM_CONTAINER_PLACEMENT_IMPL_KEY, SCMContainerPlacementRackAware.class.getName());
    conf.setStorageSize(OZONE_DATANODE_RATIS_VOLUME_FREE_SPACE_MIN, 0, StorageUnit.MB);
    NodeSchema[] schemas = new NodeSchema[] { ROOT_SCHEMA, RACK_SCHEMA, LEAF_SCHEMA };
    NodeSchemaManager.getInstance().init(schemas, true);
    cluster = new NetworkTopologyImpl(NodeSchemaManager.getInstance());
    // build datanodes, and network topology
    String rack = "/rack";
    String hostname = "node";
    for (int i = 0; i < 15; i++) {
        // Totally 3 racks, each has 5 datanodes
        DatanodeDetails datanodeDetails = MockDatanodeDetails.createDatanodeDetails(hostname + i, rack + (i / 5));
        DatanodeInfo datanodeInfo = new DatanodeInfo(datanodeDetails, NodeStatus.inServiceHealthy(), UpgradeUtils.defaultLayoutVersionProto());
        StorageReportProto storage1 = HddsTestUtils.createStorageReport(datanodeInfo.getUuid(), "/data1-" + datanodeInfo.getUuidString(), STORAGE_CAPACITY, 0, 100L, null);
        MetadataStorageReportProto metaStorage1 = HddsTestUtils.createMetadataStorageReport("/metadata1-" + datanodeInfo.getUuidString(), STORAGE_CAPACITY, 0, 100L, null);
        datanodeInfo.updateStorageReports(new ArrayList<>(Arrays.asList(storage1)));
        datanodeInfo.updateMetaDataStorageReports(new ArrayList<>(Arrays.asList(metaStorage1)));
        datanodes.add(datanodeDetails);
        cluster.add(datanodeDetails);
        dnInfos.add(datanodeInfo);
    }
    StorageReportProto storage2 = HddsTestUtils.createStorageReport(dnInfos.get(2).getUuid(), "/data1-" + dnInfos.get(2).getUuidString(), STORAGE_CAPACITY, 90L, 10L, null);
    dnInfos.get(2).updateStorageReports(new ArrayList<>(Arrays.asList(storage2)));
    StorageReportProto storage3 = HddsTestUtils.createStorageReport(dnInfos.get(3).getUuid(), "/data1-" + dnInfos.get(3).getUuidString(), STORAGE_CAPACITY, 80L, 20L, null);
    dnInfos.get(3).updateStorageReports(new ArrayList<>(Arrays.asList(storage3)));
    StorageReportProto storage4 = HddsTestUtils.createStorageReport(dnInfos.get(4).getUuid(), "/data1-" + dnInfos.get(4).getUuidString(), STORAGE_CAPACITY, 70L, 30L, null);
    dnInfos.get(4).updateStorageReports(new ArrayList<>(Arrays.asList(storage4)));
    // create mock node manager
    nodeManager = Mockito.mock(NodeManager.class);
    when(nodeManager.getNodes(NodeStatus.inServiceHealthy())).thenReturn(new ArrayList<>(datanodes));
    for (DatanodeInfo dn : dnInfos) {
        when(nodeManager.getNodeByUuid(dn.getUuidString())).thenReturn(dn);
    }
    PlacementPolicy policy = ContainerPlacementPolicyFactory.getPolicy(conf, nodeManager, cluster, true, SCMContainerPlacementMetrics.create());
    int nodeNum = 3;
    List<DatanodeDetails> datanodeDetails = policy.chooseDatanodes(null, null, nodeNum, 15, 15);
    Assert.assertEquals(nodeNum, datanodeDetails.size());
    Assert.assertTrue(cluster.isSameParent(datanodeDetails.get(0), datanodeDetails.get(1)));
    Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(0), datanodeDetails.get(2)));
    Assert.assertFalse(cluster.isSameParent(datanodeDetails.get(1), datanodeDetails.get(2)));
}
Also used : DatanodeInfo(org.apache.hadoop.hdds.scm.node.DatanodeInfo) MetadataStorageReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto) StorageReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto) NetworkTopologyImpl(org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) PlacementPolicy(org.apache.hadoop.hdds.scm.PlacementPolicy) NodeSchema(org.apache.hadoop.hdds.scm.net.NodeSchema) MetadataStorageReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto) Test(org.junit.Test)

Example 3 with PlacementPolicy

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

the class TestContainerPlacementFactory method testDefaultPolicy.

@Test
public void testDefaultPolicy() throws IOException {
    PlacementPolicy policy = ContainerPlacementPolicyFactory.getPolicy(conf, null, null, true, null);
    Assert.assertSame(SCMContainerPlacementRandom.class, policy.getClass());
}
Also used : PlacementPolicy(org.apache.hadoop.hdds.scm.PlacementPolicy) Test(org.junit.Test)

Example 4 with PlacementPolicy

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

the class TestContainerHealthStatus method setup.

@Before
public void setup() {
    placementPolicy = mock(PlacementPolicy.class);
    container = mock(ContainerInfo.class);
    when(container.getReplicationConfig()).thenReturn(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE));
    when(container.containerID()).thenReturn(ContainerID.valueOf(123456));
    when(container.getContainerID()).thenReturn((long) 123456);
    when(placementPolicy.validateContainerPlacement(Mockito.anyList(), Mockito.anyInt())).thenReturn(new ContainerPlacementStatusDefault(1, 1, 1));
}
Also used : PlacementPolicy(org.apache.hadoop.hdds.scm.PlacementPolicy) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) ContainerPlacementStatusDefault(org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault) Before(org.junit.Before)

Example 5 with PlacementPolicy

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

the class ReplicationManager method handleUnderReplicatedContainer.

/**
 * If the given container is under replicated, identify a new set of
 * datanode(s) to replicate the container using PlacementPolicy
 * and send replicate container command to the identified datanode(s).
 *
 * @param container ContainerInfo
 * @param replicaSet An instance of ContainerReplicaCount, containing the
 *                   current replica count and inflight adds and deletes
 */
private void handleUnderReplicatedContainer(final ContainerInfo container, final ContainerReplicaCount replicaSet, final ContainerPlacementStatus placementStatus) {
    LOG.debug("Handling under-replicated container: {}", container);
    Set<ContainerReplica> replicas = replicaSet.getReplica();
    try {
        if (replicaSet.isSufficientlyReplicated() && placementStatus.isPolicySatisfied()) {
            LOG.info("The container {} with replicas {} is sufficiently " + "replicated and is not mis-replicated", container.getContainerID(), replicaSet);
            return;
        }
        int repDelta = replicaSet.additionalReplicaNeeded();
        final ContainerID id = container.containerID();
        final List<DatanodeDetails> deletionInFlight = inflightDeletion.getOrDefault(id, Collections.emptyList()).stream().map(action -> action.datanode).collect(Collectors.toList());
        final List<DatanodeDetails> replicationInFlight = inflightReplication.getOrDefault(id, Collections.emptyList()).stream().map(action -> action.datanode).collect(Collectors.toList());
        final List<DatanodeDetails> source = replicas.stream().filter(r -> r.getState() == State.QUASI_CLOSED || r.getState() == State.CLOSED).filter(r -> getNodeStatus(r.getDatanodeDetails()).isHealthy()).filter(r -> !deletionInFlight.contains(r.getDatanodeDetails())).sorted((r1, r2) -> r2.getSequenceId().compareTo(r1.getSequenceId())).map(ContainerReplica::getDatanodeDetails).collect(Collectors.toList());
        if (source.size() > 0) {
            final int replicationFactor = container.getReplicationConfig().getRequiredNodes();
            // Want to check if the container is mis-replicated after considering
            // inflight add and delete.
            // Create a new list from source (healthy replicas minus pending delete)
            List<DatanodeDetails> targetReplicas = new ArrayList<>(source);
            // Then add any pending additions
            targetReplicas.addAll(replicationInFlight);
            final ContainerPlacementStatus inFlightplacementStatus = containerPlacement.validateContainerPlacement(targetReplicas, replicationFactor);
            final int misRepDelta = inFlightplacementStatus.misReplicationCount();
            final int replicasNeeded = repDelta < misRepDelta ? misRepDelta : repDelta;
            if (replicasNeeded <= 0) {
                LOG.debug("Container {} meets replication requirement with " + "inflight replicas", id);
                return;
            }
            // We should ensure that the target datanode has enough space
            // for a complete container to be created, but since the container
            // size may be changed smaller than origin, we should be defensive.
            final long dataSizeRequired = Math.max(container.getUsedBytes(), currentContainerSize);
            final List<DatanodeDetails> excludeList = replicas.stream().map(ContainerReplica::getDatanodeDetails).collect(Collectors.toList());
            excludeList.addAll(replicationInFlight);
            final List<DatanodeDetails> selectedDatanodes = containerPlacement.chooseDatanodes(excludeList, null, replicasNeeded, 0, dataSizeRequired);
            if (repDelta > 0) {
                LOG.info("Container {} is under replicated. Expected replica count" + " is {}, but found {}.", id, replicationFactor, replicationFactor - repDelta);
            }
            int newMisRepDelta = misRepDelta;
            if (misRepDelta > 0) {
                LOG.info("Container: {}. {}", id, placementStatus.misReplicatedReason());
                // Check if the new target nodes (original plus newly selected nodes)
                // makes the placement policy valid.
                targetReplicas.addAll(selectedDatanodes);
                newMisRepDelta = containerPlacement.validateContainerPlacement(targetReplicas, replicationFactor).misReplicationCount();
            }
            if (repDelta > 0 || newMisRepDelta < misRepDelta) {
                // improves things.
                for (DatanodeDetails datanode : selectedDatanodes) {
                    sendReplicateCommand(container, datanode, source);
                }
            } else {
                LOG.warn("Container {} is mis-replicated, requiring {} additional " + "replicas. After selecting new nodes, mis-replication has not " + "improved. No additional replicas will be scheduled", id, misRepDelta);
            }
        } else {
            LOG.warn("Cannot replicate container {}, no healthy replica found.", container.containerID());
        }
    } catch (IOException | IllegalStateException ex) {
        LOG.warn("Exception while replicating container {}.", container.getContainerID(), ex);
    }
}
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) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerPlacementStatus(org.apache.hadoop.hdds.scm.ContainerPlacementStatus)

Aggregations

PlacementPolicy (org.apache.hadoop.hdds.scm.PlacementPolicy)5 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GeneratedMessage (com.google.protobuf.GeneratedMessage)1 IOException (java.io.IOException)1 Proxy (java.lang.reflect.Proxy)1 Clock (java.time.Clock)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1