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