This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 589878ac5f0 [Fix](Job)The INSERT execution failed, but the task record 
status is marked as successful. (#44292)
589878ac5f0 is described below

commit 589878ac5f0ffbc2f2aa437dcd09951fdfc68151
Author: Calvin Kirs <guoqi...@selectdb.com>
AuthorDate: Fri Nov 22 11:00:48 2024 +0800

    [Fix](Job)The INSERT execution failed, but the task record status is marked 
as successful. (#44292)
    
    ### What problem does this PR solve?
    
    After a job execution is completed, we need to verify whether the
    QueryState is normal.
    Currently, we rely on exception handling to determine success. However,
    in certain cases, such as execution timeouts, exceptions may not be
    captured. As a result, the status is incorrectly marked as successful.
    
    ### Release note
    
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [x] Manual test (add detailed scripts or steps below)
    ```
    select * from tasks('type'='insert') ;
    
    
    
+----------------+----------------+---------+-------------------------------+---------+----------------------------------------------+---------------------+---------------------+------------+-------------+---------------+------+
    | TaskId         | JobId          | JobName | Label                         
| Status  | ErrorMsg                                     | CreateTime          
| StartTime           | FinishTime | TrackingUrl | LoadStatistic | User |
    
+----------------+----------------+---------+-------------------------------+---------+----------------------------------------------+---------------------+---------------------+------------+-------------+---------------+------+
    | 53767413936871 | 53748267972932 | test    | 53748267972932_53767413936871 
| RUNNING |                                              | 2024-11-19 21:39:46 
| 2024-11-19 21:39:46 |            |             |               | root |
    | 53758617801828 | 53748267972932 | test    | 53748267972932_53758617801828 
| FAILED  | errCode = 2, detailMessage = Execute timeout | 2024-11-19 21:39:37 
| 2024-11-19 21:39:37 |            |             |               | root |
    
    ```
---
 .../doris/job/extensions/insert/InsertTask.java    | 30 ++++++++++++++--------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/InsertTask.java
 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/InsertTask.java
index d1a425aeaf7..c997ebcd30e 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/InsertTask.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/InsertTask.java
@@ -23,6 +23,7 @@ import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.Status;
 import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.common.util.Util;
 import org.apache.doris.job.exception.JobException;
 import org.apache.doris.job.task.AbstractTask;
 import org.apache.doris.load.FailMsg;
@@ -31,6 +32,7 @@ import org.apache.doris.load.loadv2.LoadStatistic;
 import org.apache.doris.nereids.parser.NereidsParser;
 import 
org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand;
 import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.QueryState;
 import org.apache.doris.qe.StmtExecutor;
 import org.apache.doris.thrift.TCell;
 import org.apache.doris.thrift.TRow;
@@ -195,10 +197,13 @@ public class InsertTask extends AbstractTask {
                 return;
             }
             command.runWithUpdateInfo(ctx, stmtExecutor, loadStatistic);
+            if (ctx.getState().getStateType() != QueryState.MysqlStateType.OK) 
{
+                throw new JobException(ctx.getState().getErrorMessage());
+            }
         } catch (Exception e) {
             log.warn("execute insert task error, job id is {}, task id is 
{},sql is {}", getJobId(),
                     getTaskId(), sql, e);
-            throw new JobException(e);
+            throw new JobException(Util.getRootCauseMessage(e));
         }
     }
 
@@ -237,15 +242,7 @@ public class InsertTask extends AbstractTask {
         trow.addToColumnValue(new TCell().setStringVal(jobName));
         trow.addToColumnValue(new TCell().setStringVal(getJobId() + 
LABEL_SPLITTER + getTaskId()));
         trow.addToColumnValue(new 
TCell().setStringVal(jobInfo.getState().name()));
-        // err msg
-        String errorMsg = "";
-        if (failMsg != null) {
-            errorMsg = failMsg.getMsg();
-        }
-        if (StringUtils.isNotBlank(getErrMsg())) {
-            errorMsg = getErrMsg();
-        }
-        trow.addToColumnValue(new TCell().setStringVal(errorMsg));
+        trow.addToColumnValue(new TCell().setStringVal(getErrorMsg()));
         // create time
         trow.addToColumnValue(new 
TCell().setStringVal(TimeUtils.longToTimeString(getCreateTimeMs())));
         trow.addToColumnValue(new TCell().setStringVal(null == 
getStartTimeMs() ? ""
@@ -275,7 +272,7 @@ public class InsertTask extends AbstractTask {
         trow.addToColumnValue(new TCell().setStringVal(jobName));
         trow.addToColumnValue(new TCell().setStringVal(getJobId() + 
LABEL_SPLITTER + getTaskId()));
         trow.addToColumnValue(new TCell().setStringVal(getStatus().name()));
-        trow.addToColumnValue(new TCell().setStringVal(""));
+        trow.addToColumnValue(new TCell().setStringVal(getErrorMsg()));
         trow.addToColumnValue(new 
TCell().setStringVal(TimeUtils.longToTimeString(getCreateTimeMs())));
         trow.addToColumnValue(new TCell().setStringVal(null == 
getStartTimeMs() ? ""
                 : TimeUtils.longToTimeString(getStartTimeMs())));
@@ -287,4 +284,15 @@ public class InsertTask extends AbstractTask {
         return trow;
     }
 
+    private String getErrorMsg() {
+        // err msg
+        String errorMsg = "";
+        if (failMsg != null) {
+            errorMsg = failMsg.getMsg();
+        }
+        if (StringUtils.isNotBlank(getErrMsg())) {
+            errorMsg = getErrMsg();
+        }
+        return errorMsg;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to