Search in sources :

Example 16 with ContainerKeyPrefix

use of org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix in project ozone by apache.

the class ContainerKeyMapperTask method deleteOMKeyFromContainerDB.

/**
 * Delete an OM Key from Container DB and update containerID -> no. of keys
 * count.
 *
 * @param key key String.
 * @throws IOException If Unable to write to container DB.
 */
private void deleteOMKeyFromContainerDB(String key) throws IOException {
    TableIterator<ContainerKeyPrefix, ? extends Table.KeyValue<ContainerKeyPrefix, Integer>> containerIterator = reconContainerMetadataManager.getContainerTableIterator();
    Set<ContainerKeyPrefix> keysToBeDeleted = new HashSet<>();
    while (containerIterator.hasNext()) {
        Table.KeyValue<ContainerKeyPrefix, Integer> keyValue = containerIterator.next();
        String keyPrefix = keyValue.getKey().getKeyPrefix();
        if (keyPrefix.equals(key)) {
            keysToBeDeleted.add(keyValue.getKey());
        }
    }
    for (ContainerKeyPrefix containerKeyPrefix : keysToBeDeleted) {
        reconContainerMetadataManager.deleteContainerMapping(containerKeyPrefix);
        // decrement count and update containerKeyCount.
        Long containerID = containerKeyPrefix.getContainerId();
        long keyCount = reconContainerMetadataManager.getKeyCountForContainer(containerID);
        if (keyCount > 0) {
            reconContainerMetadataManager.storeContainerKeyCount(containerID, --keyCount);
        }
    }
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) HashSet(java.util.HashSet)

Aggregations

ContainerKeyPrefix (org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix)16 Test (org.junit.Test)10 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)4 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 BlockID (org.apache.hadoop.hdds.client.BlockID)2 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)2 Table (org.apache.hadoop.hdds.utils.db.Table)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 OMMetadataManagerTestUtils.getOmKeyLocationInfo (org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getOmKeyLocationInfo)2 OMMetadataManagerTestUtils.getRandomPipeline (org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getRandomPipeline)2 ContainerMetadata (org.apache.hadoop.ozone.recon.api.types.ContainerMetadata)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 HashSet (java.util.HashSet)1 List (java.util.List)1 UUID (java.util.UUID)1