Search in sources :

Example 1 with ContainerNotFoundException

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

the class DeadNodeHandler method removeContainerReplicas.

/**
 * Removes the ContainerReplica of the dead datanode from the containers
 * which are hosted by that datanode.
 *
 * @param datanodeDetails DatanodeDetails
 * @throws NodeNotFoundException
 */
private void removeContainerReplicas(final DatanodeDetails datanodeDetails) throws NodeNotFoundException {
    nodeManager.getContainers(datanodeDetails).forEach(id -> {
        try {
            final ContainerInfo container = containerManager.getContainer(id);
            // Identify and remove the ContainerReplica of dead node
            containerManager.getContainerReplicas(id).stream().filter(r -> r.getDatanodeDetails().equals(datanodeDetails)).findFirst().ifPresent(replica -> {
                try {
                    containerManager.removeContainerReplica(id, replica);
                } catch (ContainerException ex) {
                    LOG.warn("Exception while removing container replica #{} " + "of container {}.", replica, container, ex);
                }
            });
        } catch (ContainerNotFoundException cnfe) {
            LOG.warn("Container {} is not managed by ContainerManager.", id, cnfe);
        }
    });
}
Also used : ContainerException(org.apache.hadoop.hdds.scm.container.ContainerException) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException)

Example 2 with ContainerNotFoundException

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

the class DatanodeAdminMonitorImpl method checkContainersReplicatedOnNode.

private boolean checkContainersReplicatedOnNode(DatanodeDetails dn) throws NodeNotFoundException {
    int sufficientlyReplicated = 0;
    int underReplicated = 0;
    int unhealthy = 0;
    List<ContainerID> underReplicatedIDs = new ArrayList<>();
    List<ContainerID> unhealthyIDs = new ArrayList<>();
    Set<ContainerID> containers = nodeManager.getContainers(dn);
    for (ContainerID cid : containers) {
        try {
            ContainerReplicaCount replicaSet = replicationManager.getContainerReplicaCount(cid);
            if (replicaSet.isSufficientlyReplicated()) {
                sufficientlyReplicated++;
            } else {
                if (LOG.isDebugEnabled()) {
                    underReplicatedIDs.add(cid);
                }
                if (underReplicated < CONTAINER_DETAILS_LOGGING_LIMIT || LOG.isDebugEnabled()) {
                    LOG.info("Under Replicated Container {} {}; {}", cid, replicaSet, replicaDetails(replicaSet.getReplica()));
                }
                underReplicated++;
            }
            if (!replicaSet.isHealthy()) {
                if (LOG.isDebugEnabled()) {
                    unhealthyIDs.add(cid);
                }
                if (unhealthy < CONTAINER_DETAILS_LOGGING_LIMIT || LOG.isDebugEnabled()) {
                    LOG.info("Unhealthy Container {} {}; {}", cid, replicaSet, replicaDetails(replicaSet.getReplica()));
                }
                unhealthy++;
            }
        } catch (ContainerNotFoundException e) {
            LOG.warn("ContainerID {} present in node list for {} but not found " + "in containerManager", cid, dn);
        }
    }
    LOG.info("{} has {} sufficientlyReplicated, {} underReplicated and {} " + "unhealthy containers", dn, sufficientlyReplicated, underReplicated, unhealthy);
    if (LOG.isDebugEnabled() && underReplicatedIDs.size() < 10000 && unhealthyIDs.size() < 10000) {
        LOG.debug("{} has {} underReplicated [{}] and {} unhealthy [{}] " + "containers", dn, underReplicated, underReplicatedIDs.stream().map(Object::toString).collect(Collectors.joining(", ")), unhealthy, unhealthyIDs.stream().map(Object::toString).collect(Collectors.joining(", ")));
    }
    return underReplicated == 0 && unhealthy == 0;
}
Also used : ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) ArrayList(java.util.ArrayList) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) ContainerReplicaCount(org.apache.hadoop.hdds.scm.container.ContainerReplicaCount)

Example 3 with ContainerNotFoundException

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

the class TestSCMContainerManagerMetrics method testContainerOpsMetrics.

@Test
public void testContainerOpsMetrics() throws IOException {
    MetricsRecordBuilder metrics;
    ContainerManager containerManager = scm.getContainerManager();
    metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
    long numSuccessfulCreateContainers = getLongCounter("NumSuccessfulCreateContainers", metrics);
    ContainerInfo containerInfo = containerManager.allocateContainer(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE), OzoneConsts.OZONE);
    metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
    Assert.assertEquals(getLongCounter("NumSuccessfulCreateContainers", metrics), ++numSuccessfulCreateContainers);
    try {
        containerManager.allocateContainer(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE), OzoneConsts.OZONE);
        fail("testContainerOpsMetrics failed");
    } catch (IOException ex) {
        // Here it should fail, so it should have the old metric value.
        metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
        Assert.assertEquals(getLongCounter("NumSuccessfulCreateContainers", metrics), numSuccessfulCreateContainers);
        Assert.assertEquals(getLongCounter("NumFailureCreateContainers", metrics), 1);
    }
    metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
    long numSuccessfulDeleteContainers = getLongCounter("NumSuccessfulDeleteContainers", metrics);
    containerManager.deleteContainer(ContainerID.valueOf(containerInfo.getContainerID()));
    metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
    Assert.assertEquals(getLongCounter("NumSuccessfulDeleteContainers", metrics), numSuccessfulDeleteContainers + 1);
    try {
        // Give random container to delete.
        containerManager.deleteContainer(ContainerID.valueOf(RandomUtils.nextLong(10000, 20000)));
        fail("testContainerOpsMetrics failed");
    } catch (ContainerNotFoundException ex) {
        // Here it should fail, so it should have the old metric value.
        metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
        Assert.assertEquals(getLongCounter("NumSuccessfulDeleteContainers", metrics), numSuccessfulCreateContainers);
        Assert.assertEquals(getLongCounter("NumFailureDeleteContainers", metrics), 1);
    }
    long currentValue = getLongCounter("NumListContainerOps", metrics);
    containerManager.getContainers(ContainerID.valueOf(containerInfo.getContainerID()), 1);
    metrics = getMetrics(SCMContainerManagerMetrics.class.getSimpleName());
    Assert.assertEquals(currentValue + 1, getLongCounter("NumListContainerOps", metrics));
}
Also used : ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) IOException(java.io.IOException) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 4 with ContainerNotFoundException

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

the class DeletedBlockLogImpl method getTransactions.

@Override
public DatanodeDeletedBlockTransactions getTransactions(int blockDeletionLimit) throws IOException {
    lock.lock();
    try {
        DatanodeDeletedBlockTransactions transactions = new DatanodeDeletedBlockTransactions();
        try (TableIterator<Long, ? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter = deletedBlockLogStateManager.getReadOnlyIterator()) {
            int numBlocksAdded = 0;
            ArrayList<Long> txIDs = new ArrayList<>();
            while (iter.hasNext() && numBlocksAdded < blockDeletionLimit) {
                Table.KeyValue<Long, DeletedBlocksTransaction> keyValue = iter.next();
                DeletedBlocksTransaction txn = keyValue.getValue();
                final ContainerID id = ContainerID.valueOf(txn.getContainerID());
                try {
                    if (txn.getCount() > -1 && txn.getCount() <= maxRetry && !containerManager.getContainer(id).isOpen()) {
                        numBlocksAdded += txn.getLocalIDCount();
                        getTransaction(txn, transactions);
                        transactionToDNsCommitMap.putIfAbsent(txn.getTxID(), new LinkedHashSet<>());
                    }
                } catch (ContainerNotFoundException ex) {
                    LOG.warn("Container: " + id + " was not found for the transaction: " + txn);
                    txIDs.add(txn.getTxID());
                }
            }
            if (!txIDs.isEmpty()) {
                deletedBlockLogStateManager.removeTransactionsFromDB(txIDs);
                metrics.incrBlockDeletionTransactionCompleted(txIDs.size());
            }
        }
        return transactions;
    } finally {
        lock.unlock();
    }
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) ArrayList(java.util.ArrayList) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) DeletedBlocksTransaction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction)

Example 5 with ContainerNotFoundException

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

the class AbstractFindTargetGreedy method findTargetForContainerMove.

/**
 * Find a {@link ContainerMoveSelection} consisting of a target and
 * container to move for a source datanode. Favours more under-utilized nodes.
 * @param source Datanode to find a target for
 * @param candidateContainers Set of candidate containers satisfying
 *                            selection criteria
 *                            {@link ContainerBalancerSelectionCriteria}
 * (DatanodeDetails, Long) method returns true if the size specified in the
 * second argument can enter the specified DatanodeDetails node
 * @return Found target and container
 */
@Override
public ContainerMoveSelection findTargetForContainerMove(DatanodeDetails source, Set<ContainerID> candidateContainers) {
    sortTargetForSource(source);
    for (DatanodeUsageInfo targetInfo : potentialTargets) {
        DatanodeDetails target = targetInfo.getDatanodeDetails();
        for (ContainerID container : candidateContainers) {
            Set<ContainerReplica> replicas;
            ContainerInfo containerInfo;
            try {
                replicas = containerManager.getContainerReplicas(container);
                containerInfo = containerManager.getContainer(container);
            } catch (ContainerNotFoundException e) {
                logger.warn("Could not get Container {} from Container Manager for " + "obtaining replicas in Container Balancer.", container, e);
                continue;
            }
            if (replicas.stream().noneMatch(replica -> replica.getDatanodeDetails().equals(target)) && containerMoveSatisfiesPlacementPolicy(container, replicas, source, target) && canSizeEnterTarget(target, containerInfo.getUsedBytes())) {
                return new ContainerMoveSelection(target, container);
            }
        }
    }
    logger.info("Container Balancer could not find a target for " + "source datanode {}", source.getUuidString());
    return null;
}
Also used : ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) ContainerReplica(org.apache.hadoop.hdds.scm.container.ContainerReplica) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) DatanodeUsageInfo(org.apache.hadoop.hdds.scm.node.DatanodeUsageInfo) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException)

Aggregations

ContainerNotFoundException (org.apache.hadoop.hdds.scm.container.ContainerNotFoundException)17 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)8 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)8 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)4 IOException (java.io.IOException)3 ContainerManager (org.apache.hadoop.hdds.scm.container.ContainerManager)3 ContainerReplica (org.apache.hadoop.hdds.scm.container.ContainerReplica)3 NodeNotFoundException (org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ReplicationManager (org.apache.hadoop.hdds.scm.container.ReplicationManager)2 DatanodeUsageInfo (org.apache.hadoop.hdds.scm.node.DatanodeUsageInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1