github-actions[bot] commented on code in PR #61881:
URL: https://github.com/apache/doris/pull/61881#discussion_r3109000622


##########
regression-test/suites/load_p0/routine_load/test_routine_load_be_restart.groovy:
##########
@@ -78,6 +78,23 @@ suite("test_routine_load_be_restart","nonConcurrent") {
                 GetDebugPoint().disableDebugPointForAllFEs(injection_load_hang)
             }
 
+            // After the simulated BE restart, the routine load must recover: 
new tasks are
+            // scheduled (afterAborted callback ran without exception) and 
data is loaded.
+            // If handleAfterAbort threw IllegalMonitorStateException the job 
would be stuck.
+            def count = RoutineLoadTestUtils.waitForTaskFinish(runSql, job, 
tableName, 0)

Review Comment:
   This block is still a false positive for the original bug. In the buggy 
path, `RoutineLoadJob.afterAborted()` renews and enqueues the replacement task 
in `executeTaskOnTxnStatusChanged(...)` before the unconditional 
`writeUnlock()` in `finally`, so rows can continue loading and the job can stay 
`RUNNING` even if `afterAborted()` still ends with 
`IllegalMonitorStateException`. `waitForTaskFinish()` plus the `RUNNING` 
assertion does not actually prove the lock-handoff fix.



##########
fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java:
##########
@@ -1803,29 +1804,62 @@ public void abortTransaction(Long dbId, Long 
transactionId, String reason) throw
     @Override
     public void abortTransaction(Long dbId, Long transactionId, String reason,
             TxnCommitAttachment txnCommitAttachment, List<Table> tableList) 
throws UserException {
-        if (txnCommitAttachment != null) {
-            if (txnCommitAttachment instanceof RLTaskTxnCommitAttachment) {
-                RLTaskTxnCommitAttachment rlTaskTxnCommitAttachment = 
(RLTaskTxnCommitAttachment) txnCommitAttachment;
-                TxnStateChangeCallback cb = 
callbackFactory.getCallback(rlTaskTxnCommitAttachment.getJobId());
-                if (cb != null) {
-                    // use a temporary transaction state to do before commit 
check,
-                    // what actually works is the transactionId
-                    TransactionState tmpTxnState = new TransactionState();
-                    tmpTxnState.setTransactionId(transactionId);
-                    cb.beforeAborted(tmpTxnState);
-                }
-            }
-        }
+        Pair<Long, TxnStateChangeCallback> callbackInfo =
+                handleBeforeAbort(dbId, transactionId, txnCommitAttachment);
 
         AbortTxnResponse abortTxnResponse = null;
         try {
             abortTxnResponse = abortTransactionImpl(dbId, transactionId, 
reason, null);
         } finally {
-            handleAfterAbort(abortTxnResponse, txnCommitAttachment, 
transactionId);
+            handleAfterAbort(abortTxnResponse, txnCommitAttachment, 
transactionId,
+                    callbackInfo.first, callbackInfo.second);
             clearTxnLastSignature(dbId, transactionId);
         }
     }
 
+    /**
+     * Resolves the transaction callback and calls beforeAborted() before the 
abort RPC,
+     * so the lock-handoff pattern (beforeAborted acquires, afterAborted 
releases) wraps
+     * the correct scope.
+     *
+     * @return a Pair of (callbackId, callback); callback is null if no 
callback is registered
+     *         or if beforeAborted failed (in either case handleAfterAbort 
will skip afterAborted)
+     */
+    private Pair<Long, TxnStateChangeCallback> handleBeforeAbort(Long dbId, 
long transactionId,
+            TxnCommitAttachment txnCommitAttachment) throws UserException {
+        long callbackId = 0L;
+        if (txnCommitAttachment instanceof RLTaskTxnCommitAttachment) {
+            callbackId = ((RLTaskTxnCommitAttachment) 
txnCommitAttachment).getJobId();
+        } else if (txnCommitAttachment == null) {
+            // txnCommitAttachment is null (e.g. BE restart abort): the 
callbackId is only
+            // stored in the meta service, so do a pre-query to fetch it 
before the abort RPC,
+            // ensuring beforeAborted is called before the transaction is 
actually aborted.

Review Comment:
   `handleBeforeAbort()` makes this pre-read a hard dependency for every 
null-attachment cloud abort. `getTransactionState()` returns `null` on any 
`getTxn()` RPC error or non-`OK` status, so a transient meta-service failure 
here now throws before `abortTransactionImpl()` is even sent. That changes 
`abortTxnWhenCoordinateBeRestart()` / `abortTxnWhenCoordinateBeDown()` from 
best-effort cleanup into `leave the PREPARE txn running until timeout`. Falling 
back to `callbackId = 0` and skipping `beforeAborted()` when the pre-read fails 
would preserve the original abort semantics.



##########
regression-test/suites/load_p0/routine_load/test_routine_load_be_restart.groovy:
##########
@@ -78,6 +78,23 @@ suite("test_routine_load_be_restart","nonConcurrent") {
                 GetDebugPoint().disableDebugPointForAllFEs(injection_load_hang)
             }
 
+            // After the simulated BE restart, the routine load must recover: 
new tasks are
+            // scheduled (afterAborted callback ran without exception) and 
data is loaded.
+            // If handleAfterAbort threw IllegalMonitorStateException the job 
would be stuck.
+            def count = RoutineLoadTestUtils.waitForTaskFinish(runSql, job, 
tableName, 0)
+            logger.info("rows loaded after be-restart abort, wait iterations: 
" + count)
+
+            // Verify job is still RUNNING (not PAUSED due to an exception in 
afterAborted).
+            def res = sql "show routine load for ${job}"
+            assertEquals("RUNNING", res[0][8].toString())
+
+            // Send additional data and confirm it is loaded to prove ongoing 
task scheduling
+            // works correctly after the abort — this would time-out if the 
replacement task
+            // was never enqueued due to the missing beforeAborted() call.
+            def rowsAfterFirstLoad = sql("select count(*) from 
${tableName}")[0][0] as int

Review Comment:
   `rowsAfterFirstLoad` is not a reliable proof that the second 
`sendTestDataToKafka()` batch was consumed. This table is `DUPLICATE KEY`, and 
for FE-aborted routine-load txns with `txnCommitAttachment == null`, the 
renewed task can re-consume the original Kafka batch without advancing 
progress. That can push `count(*)` past `rowsAfterFirstLoad` even if the second 
batch is never read. Using distinct payload for the second send and asserting 
those specific rows appear would avoid the false positive.



-- 
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]

Reply via email to