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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/AbstractInsertExecutor.java:
##########
@@ -267,13 +267,32 @@ private void checkStrictModeAndFilterRatio() throws 
Exception {
      */
     public void executeSingleInsert(StmtExecutor executor) throws Exception {
         try {
+            // Every statement-owned insert coordinator is published at the 
common execution boundary.
+            // Cancellation retained during planning is replayed before any 
executor-specific setup or dispatch.
+            executor.setCoord(coordinator);
+            // Publication synchronously replays any cancellation retained 
during planning. Fence on that
+            // terminal status before executor-specific setup runs, so a later 
setup failure cannot mask the
+            // original timeout/cancel reason.
+            Status execStatus = coordinator.getExecStatus();
+            if (!execStatus.ok()) {
+                throw new UserException(execStatus.getErrorMsg());
+            }
+            // Pre-execution work may register external resources, so it must 
share the transaction cleanup scope.
             beforeExec();
             executor.updateProfile(false);
             execImpl(executor);
             checkStrictModeAndFilterRatio();
             for (InsertExecutorListener listener : listeners) {
                 listener.beforeComplete(this, executor, jobId);
             }
+            // Every transaction-owning executor commits inside onComplete(). 
Re-fence the first terminal
+            // status here so a cancellation/TIMEOUT that landed after 
execImpl()'s last status read cannot
+            // be committed by a path such as row-level UPDATE/DELETE/MERGE, 
which has no command-level
+            // cancellation listener of its own.
+            Status preCommitStatus = coordinator.getExecStatus();

Review Comment:
   [P1] Make the cancellation-to-commit handoff atomic. This status read is 
separate from `onComplete()`: a timeout/KILL can arrive immediately after line 
292, while `OlapInsertExecutor.onComplete()` still sees an OK `ConnectContext` 
and calls `commitAndPublishTransaction()` (external executors have the same 
gap). The added regression test cancels before this read, so the post-read race 
remains able to commit a terminated statement. Guard the terminal-status/commit 
decision with a shared completion gate or a transaction API that rejects a 
newly published cancellation.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java:
##########
@@ -352,9 +352,8 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, 
StmtExecutor stmtExec
             }
             stmtExecutor.setProfileType(ProfileType.LOAD);
             // We exposed @StmtExecutor#cancel as a unified entry point for 
statement interruption,
-            // so we need to set this here
+            // so executeSingleInsert publishes the coordinator at its common 
execution boundary.

Review Comment:
   [P1] Publish and fence the coordinator for empty overwrites too. 
`initPlan()` begins the Iceberg transaction, then `runInternal()` calls 
`executeEmptyInsert()`, which never invokes `setCoord()` or reads the retained 
terminal status before `BaseExternalTableInsertExecutor.onComplete()` commits. 
A timeout/KILL during planning is therefore recorded by `StmtExecutor` but the 
empty overwrite can still commit. Keep publication before the empty/non-empty 
split or add the same cancellation fence to `executeEmptyInsert()` and abort 
the transaction on failure.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/AbstractInsertExecutor.java:
##########
@@ -267,13 +267,32 @@ private void checkStrictModeAndFilterRatio() throws 
Exception {
      */
     public void executeSingleInsert(StmtExecutor executor) throws Exception {
         try {
+            // Every statement-owned insert coordinator is published at the 
common execution boundary.
+            // Cancellation retained during planning is replayed before any 
executor-specific setup or dispatch.
+            executor.setCoord(coordinator);
+            // Publication synchronously replays any cancellation retained 
during planning. Fence on that
+            // terminal status before executor-specific setup runs, so a later 
setup failure cannot mask the
+            // original timeout/cancel reason.
+            Status execStatus = coordinator.getExecStatus();
+            if (!execStatus.ok()) {
+                throw new UserException(execStatus.getErrorMsg());

Review Comment:
   [P2] Preserve the Dictionary insert error code when fencing a cancelled 
coordinator. `new UserException(status.getErrorMsg())` defaults to 
`ERR_UNKNOWN_ERROR`, and the new `DictionaryInsertExecutor.onFail()` now 
forwards that code to the client. The former `execImpl()` status path used 
`ERR_FAILED_WHEN_INSERT`, so TIMEOUT/CANCELLED during publication now loses the 
intended DDL error classification. Map the coordinator status to the existing 
insert error code (or throw a coded `DdlException`) and assert it in the 
regression test.



##########
fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java:
##########
@@ -795,8 +799,12 @@ public void exec() throws Exception {
                     // AllBackendComputeGroup may assocatiate with multiple 
workload groups
                     queryQueue = wgs.get(0).getQueryQueue();
                     queueToken = 
queryQueue.getToken(context.getSessionVariable().wgQuerySlotCount);
-                    queueToken.get(DebugUtil.printId(queryId),
-                            this.queryOptions.getExecutionTimeout() * 1000);
+                    try {
+                        queueToken.get(DebugUtil.printId(queryId),

Review Comment:
   [P2] Recheck terminal status when publishing the queue token. A timeout/KILL 
can run after the initial status fence but before `queueToken` is assigned; 
`cancel()` then sees null, while this thread assigns a fresh token and enters 
`QueueToken.get()` without another check. The cancelled query can remain 
blocked until `executionTimeout` because no one cancels that token. 
Publish/cancel the token atomically or recheck and cancel/throw immediately 
after assignment; apply the same fix to `NereidsCoordinator.enqueue()` as well.



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