morningman commented on a change in pull request #2182: Sending clear txn task explicitly after transaction being aborted URL: https://github.com/apache/incubator-doris/pull/2182#discussion_r345208187
########## File path: fe/src/main/java/org/apache/doris/transaction/GlobalTransactionMgr.java ########## @@ -532,9 +538,42 @@ public void abortTransaction(long transactionId, String reason, TxnCommitAttachm writeUnlock(); transactionState.afterStateTransform(TransactionStatus.ABORTED, txnOperated, reason); } + + // send clear txn task to BE to clear the transactions on BE. + // This is because parts of a txn may succeed in some BE, and these parts of txn should be cleared + // explicitly, or it will be remained on BE forever + // (However the report process will do the diff and send clear txn tasks to BE, but that is our + // last defense) + if (txnOperated && transactionState.getTransactionStatus() == TransactionStatus.ABORTED) { + clearBackendTransactions(transactionState); + } + return; } + private void clearBackendTransactions(TransactionState transactionState) { + Preconditions.checkState(transactionState.getTransactionStatus() == TransactionStatus.ABORTED); + // for aborted transaction, we don't know which backends are involved, so we have to send clear task + // to all backends. + List<Long> allBeIds = Catalog.getCurrentSystemInfo().getBackendIds(false); + synchronized (clearTransactionTasks) { + for (Long beId : allBeIds) { + ClearTransactionTask task = new ClearTransactionTask(beId, transactionState.getTransactionId(), null); + clearTransactionTasks.add(task); + } + + // try to group send tasks, not sending every time a txn is aborted. to avoid too many task rpc. + if (clearTransactionTasks.size() > allBeIds.size() * 2) { + AgentBatchTask batchTask = new AgentBatchTask(); + for (ClearTransactionTask clearTransactionTask : clearTransactionTasks) { + batchTask.addTask(clearTransactionTask); + } + AgentTaskExecutor.submit(batchTask); Review comment: Just want one thread to submit the clear task, or if there are lots of aborted txn, there will be lots of clear tasks being submitted concurrently. AgentTaskExecutor.submit is a async method, no need to worry about it. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org