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

morningman 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 9e49bdf012f [Audit](fix) fix audit log lost for npe (#44145)
9e49bdf012f is described below

commit 9e49bdf012f7fdbc7bfa20606e701141ab2d4fba
Author: shee <13843187+qz...@users.noreply.github.com>
AuthorDate: Mon Dec 9 14:54:21 2024 +0800

    [Audit](fix) fix audit log lost for npe (#44145)
    
    ### What problem does this PR solve?
    
    ```
    private static void logAuditLogImpl(ConnectContext ctx, String origStmt, 
StatementBase parsedStmt,
                org.apache.doris.proto.Data.PQueryStatistics statistics, 
boolean printFuzzyVariables) {
    
            //........
           // When we execute a statement, we execute the executeQuery method. 
In this method, we parse the sql using the new optimizer first, and if the 
parsing fails, we execute handleQueryException to record the audit log. At this 
time, there is no executor set, resulting in the npe
            if (!Env.getCurrentEnv().isMaster()) {
                if (ctx.executor != null && ctx.executor.isForwardToMaster()) {
                    auditEventBuilder.setState(ctx.executor.getProxyStatus());
                    int proxyStatusCode = ctx.executor.getProxyStatusCode();
                    if (proxyStatusCode != 0) {
                        auditEventBuilder.setErrorCode(proxyStatusCode);
                        
auditEventBuilder.setErrorMessage(ctx.executor.getProxyErrMsg());
                    }
                }
            }
            if (ctx.getCommand() == MysqlCommand.COM_STMT_PREPARE && 
ctx.getState().getErrorCode() == null) {
                auditEventBuilder.setState(String.valueOf(MysqlStateType.OK));
            }
            
Env.getCurrentEnv().getWorkloadRuntimeStatusMgr().submitFinishQueryToAudit(auditEventBuilder.build());
        }
    ```
    
    Co-authored-by: garenshi <garen...@tencent.com>
---
 fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java
index 903b72898c9..f29c617c158 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java
@@ -286,7 +286,7 @@ public class AuditLogHelper {
         auditEventBuilder.setStmtType(getStmtType(parsedStmt));
 
         if (!Env.getCurrentEnv().isMaster()) {
-            if (ctx.executor.isForwardToMaster()) {
+            if (ctx.executor != null && ctx.executor.isForwardToMaster()) {
                 auditEventBuilder.setState(ctx.executor.getProxyStatus());
                 int proxyStatusCode = ctx.executor.getProxyStatusCode();
                 if (proxyStatusCode != 0) {


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

Reply via email to