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);
}
});
}
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;
}
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));
}
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();
}
}
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;
}
Aggregations