ChenSammi commented on code in PR #4913:
URL: https://github.com/apache/ozone/pull/4913#discussion_r1331075094
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -346,10 +370,75 @@ private void processCmd(DeleteCmdInfo cmd) {
}
}
+ @VisibleForTesting
+ public List<DeleteBlockTransactionResult> executeCmdWithRetry(
+ List<DeletedBlocksTransaction> transactions) {
+ List<DeleteBlockTransactionResult> results =
+ new ArrayList<>(transactions.size());
+ Map<Long, DeletedBlocksTransaction> idToTransaction =
+ new HashMap<>(transactions.size());
+ transactions.forEach(tx -> idToTransaction.put(tx.getTxID(), tx));
+ List<DeletedBlocksTransaction> retryTransaction = new ArrayList<>();
+
+ List<Future<DeleteBlockTransactionExecutionResult>> futures =
+ submitTasks(transactions);
+ // Wait for tasks to finish
+ handleTasksResults(futures, result -> {
+ if (result.isLockAcquisitionFailed()) {
+
retryTransaction.add(idToTransaction.get(result.getResult().getTxID()));
+ } else {
+ results.add(result.getResult());
+ }
+ });
+
+ idToTransaction.clear();
+ // Wait for all tasks to complete before retrying, usually it takes
+ // some time for all tasks to complete, then the retry may be successful.
+ // We will only retry once
+ if (!retryTransaction.isEmpty()) {
+ futures = submitTasks(retryTransaction);
+ handleTasksResults(futures, result -> {
+ if (result.isLockAcquisitionFailed()) {
+ blockDeleteMetrics.incrTotalLockTimeoutTransactionCount();
+ }
+ results.add(result.getResult());
+ });
+ }
+ return results;
+ }
+
+ @VisibleForTesting
+ public List<Future<DeleteBlockTransactionExecutionResult>> submitTasks(
+ List<DeletedBlocksTransaction> deletedBlocksTransactions) {
+ List<Future<DeleteBlockTransactionExecutionResult>> futures =
+ new ArrayList<>(deletedBlocksTransactions.size());
+
+ for (DeletedBlocksTransaction tx : deletedBlocksTransactions) {
+ Future<DeleteBlockTransactionExecutionResult> future =
+ executor.submit(new ProcessTransactionTask(tx));
+ futures.add(future);
+ }
+ return futures;
+ }
+
+ public void handleTasksResults(
+ List<Future<DeleteBlockTransactionExecutionResult>> futures,
+ Consumer<DeleteBlockTransactionExecutionResult> handler) {
+ futures.forEach(f -> {
+ try {
+ DeleteBlockTransactionExecutionResult result = f.get();
+ handler.accept(result);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("task failed.", e);
+ Thread.currentThread().interrupt();
+ }
+ });
+ }
+
private void markBlocksForDeletionSchemaV3(
- KeyValueContainerData containerData, DeletedBlocksTransaction delTX,
- int newDeletionBlocks, long txnID)
+ KeyValueContainerData containerData, DeletedBlocksTransaction delTX)
throws IOException {
+ int newDeletionBlocks = 0;
Review Comment:
Could you do some refactor on markBlocksForDeletionTransaction too? This
newDeletionBlocks is always 0. It's better to be declared in
markBlocksForDeletionTransaction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]