use of org.apache.hadoop.ozone.protocol.commands.DeleteBlockCommandStatus in project ozone by apache.
the class DeleteBlocksCommandHandler method processCmd.
private void processCmd(DeleteCmdInfo cmd) {
LOG.debug("Processing block deletion command.");
ContainerBlocksDeletionACKProto blockDeletionACK = null;
long startTime = Time.monotonicNow();
boolean cmdExecuted = false;
try {
// move blocks to deleting state.
// this is a metadata update, the actual deletion happens in another
// recycling thread.
List<DeletedBlocksTransaction> containerBlocks = cmd.getCmd().blocksTobeDeleted();
DeletedContainerBlocksSummary summary = DeletedContainerBlocksSummary.getFrom(containerBlocks);
LOG.info("Start to delete container blocks, TXIDs={}, " + "numOfContainers={}, numOfBlocks={}", summary.getTxIDSummary(), summary.getNumOfContainers(), summary.getNumOfBlocks());
ContainerBlocksDeletionACKProto.Builder resultBuilder = ContainerBlocksDeletionACKProto.newBuilder();
List<Future> futures = new ArrayList<>();
for (int i = 0; i < containerBlocks.size(); i++) {
DeletedBlocksTransaction tx = containerBlocks.get(i);
Future future = executor.submit(new ProcessTransactionTask(tx, resultBuilder));
futures.add(future);
}
// Wait for tasks to finish
futures.forEach(f -> {
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("task failed.", e);
Thread.currentThread().interrupt();
}
});
resultBuilder.setDnId(cmd.getContext().getParent().getDatanodeDetails().getUuid().toString());
blockDeletionACK = resultBuilder.build();
// TODO Or we should wait until the blocks are actually deleted?
if (!containerBlocks.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Sending following block deletion ACK to SCM");
for (DeleteBlockTransactionResult result : blockDeletionACK.getResultsList()) {
LOG.debug("{} : {}", result.getTxID(), result.getSuccess());
}
}
}
cmdExecuted = true;
} finally {
final ContainerBlocksDeletionACKProto deleteAck = blockDeletionACK;
final boolean status = cmdExecuted;
Consumer<CommandStatus> statusUpdater = (cmdStatus) -> {
cmdStatus.setStatus(status);
((DeleteBlockCommandStatus) cmdStatus).setBlocksDeletionAck(deleteAck);
};
updateCommandStatus(cmd.getContext(), cmd.getCmd(), statusUpdater, LOG);
long endTime = Time.monotonicNow();
totalTime += endTime - startTime;
invocationCount++;
}
}
Aggregations