use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.
the class SCMBlockProtocolServer method deleteKeyBlocks.
/**
* Delete blocks for a set of object keys.
*
* @param keyBlocksInfoList list of block keys with object keys to delete.
* @return deletion results.
*/
@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("SCM is informed by OM to delete {} blocks", keyBlocksInfoList.size());
}
List<DeleteBlockGroupResult> results = new ArrayList<>();
Map<String, String> auditMap = Maps.newHashMap();
ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result resultCode;
Exception e = null;
try {
scm.getScmBlockManager().deleteBlocks(keyBlocksInfoList);
resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.success;
} catch (IOException ioe) {
e = ioe;
LOG.warn("Fail to delete {} keys", keyBlocksInfoList.size(), ioe);
switch(ioe instanceof SCMException ? ((SCMException) ioe).getResult() : IO_EXCEPTION) {
case SAFE_MODE_EXCEPTION:
resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.safeMode;
break;
case FAILED_TO_FIND_BLOCK:
resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.errorNotFound;
break;
default:
resultCode = ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result.unknownFailure;
}
}
for (BlockGroup bg : keyBlocksInfoList) {
auditMap.put("KeyBlockToDelete", bg.toString());
List<DeleteBlockResult> blockResult = new ArrayList<>();
for (BlockID b : bg.getBlockIDList()) {
blockResult.add(new DeleteBlockResult(b, resultCode));
}
results.add(new DeleteBlockGroupResult(bg.getGroupID(), blockResult));
}
if (e == null) {
AUDIT.logWriteSuccess(buildAuditMessageForSuccess(SCMAction.DELETE_KEY_BLOCK, auditMap));
} else {
AUDIT.logWriteFailure(buildAuditMessageForFailure(SCMAction.DELETE_KEY_BLOCK, auditMap, e));
}
return results;
}
use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.
the class ScmBlockLocationProtocolServerSideTranslatorPB method deleteScmKeyBlocks.
public DeleteScmKeyBlocksResponseProto deleteScmKeyBlocks(DeleteScmKeyBlocksRequestProto req) throws IOException {
DeleteScmKeyBlocksResponseProto.Builder resp = DeleteScmKeyBlocksResponseProto.newBuilder();
List<BlockGroup> infoList = req.getKeyBlocksList().stream().map(BlockGroup::getFromProto).collect(Collectors.toList());
final List<DeleteBlockGroupResult> results = impl.deleteKeyBlocks(infoList);
for (DeleteBlockGroupResult result : results) {
DeleteKeyBlocksResultProto.Builder deleteResult = DeleteKeyBlocksResultProto.newBuilder().setObjectKey(result.getObjectKey()).addAllBlockResults(result.getBlockResultProtoList());
resp.addResults(deleteResult.build());
}
return resp.build();
}
use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.
the class OmMetadataManagerImpl method getPendingDeletionKeys.
@Override
public List<BlockGroup> getPendingDeletionKeys(final int keyCount) throws IOException {
List<BlockGroup> keyBlocksList = Lists.newArrayList();
try (TableIterator<String, ? extends KeyValue<String, RepeatedOmKeyInfo>> keyIter = getDeletedTable().iterator()) {
int currentCount = 0;
while (keyIter.hasNext() && currentCount < keyCount) {
KeyValue<String, RepeatedOmKeyInfo> kv = keyIter.next();
if (kv != null) {
RepeatedOmKeyInfo infoList = kv.getValue();
// Get block keys as a list.
for (OmKeyInfo info : infoList.getOmKeyInfoList()) {
OmKeyLocationInfoGroup latest = info.getLatestVersionLocations();
List<BlockID> item = latest.getLocationList().stream().map(b -> new BlockID(b.getContainerID(), b.getLocalID())).collect(Collectors.toList());
BlockGroup keyBlocks = BlockGroup.newBuilder().setKeyName(kv.getKey()).addAllBlockIDs(item).build();
keyBlocksList.add(keyBlocks);
currentCount++;
}
}
}
}
return keyBlocksList;
}
use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.
the class BlockManagerImpl method deleteBlocks.
/**
* Deletes a list of blocks in an atomic operation. Internally, SCM writes
* these blocks into a
* {@link DeletedBlockLog} and deletes them from SCM DB. If this is
* successful, given blocks are
* entering pending deletion state and becomes invisible from SCM namespace.
*
* @param keyBlocksInfoList . This is the list of BlockGroup which contains
* groupID of keys and list of BlockIDs associated with them.
* @throws IOException if exception happens, non of the blocks is deleted.
*/
@Override
public void deleteBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
if (scm.getScmContext().isInSafeMode()) {
throw new SCMException("SafeModePrecheck failed for deleteBlocks", SCMException.ResultCodes.SAFE_MODE_EXCEPTION);
}
Map<Long, List<Long>> containerBlocks = new HashMap<>();
// TODO: used space when the block is deleted.
for (BlockGroup bg : keyBlocksInfoList) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting blocks {}", StringUtils.join(",", bg.getBlockIDList()));
}
for (BlockID block : bg.getBlockIDList()) {
long containerID = block.getContainerID();
if (containerBlocks.containsKey(containerID)) {
containerBlocks.get(containerID).add(block.getLocalID());
} else {
List<Long> item = new ArrayList<>();
item.add(block.getLocalID());
containerBlocks.put(containerID, item);
}
}
}
try {
deletedBlockLog.addTransactions(containerBlocks);
} catch (IOException e) {
throw new IOException("Skip writing the deleted blocks info to" + " the delLog because addTransaction fails. " + keyBlocksInfoList.size() + "Keys skipped", e);
}
// TODO: Container report handling of the deleted blocks:
// Remove tombstone and update open container usage.
// We will revisit this when the closed container replication is done.
}
use of org.apache.hadoop.ozone.common.BlockGroup in project ozone by apache.
the class ScmBlockLocationTestingClient method deleteKeyBlocks.
@Override
public List<DeleteBlockGroupResult> deleteKeyBlocks(List<BlockGroup> keyBlocksInfoList) throws IOException {
List<DeleteBlockGroupResult> results = new ArrayList<>();
List<DeleteBlockResult> blockResultList = new ArrayList<>();
Result result;
for (BlockGroup keyBlocks : keyBlocksInfoList) {
for (BlockID blockKey : keyBlocks.getBlockIDList()) {
currentCall++;
switch(this.failCallsFrequency) {
case 0:
result = success;
break;
case 1:
result = unknownFailure;
break;
default:
if (currentCall % this.failCallsFrequency == 0) {
result = unknownFailure;
} else {
result = success;
}
}
blockResultList.add(new DeleteBlockResult(blockKey, result));
}
results.add(new DeleteBlockGroupResult(keyBlocks.getGroupID(), blockResultList));
}
return results;
}
Aggregations