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

lijibing 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 6403b3c04bb [fix](auditlog)Fix auditlog NPE (#45772)
6403b3c04bb is described below

commit 6403b3c04bb71c0081e401b46cc70db1d05a2636
Author: James <lijib...@selectdb.com>
AuthorDate: Mon Dec 23 17:07:04 2024 +0800

    [fix](auditlog)Fix auditlog NPE (#45772)
    
    ### What problem does this PR solve?
    
    Don't call MetricRepo if it is not initialized to avoid NPE.
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    ### Release note
    
    None
---
 .../java/org/apache/doris/qe/AuditLogHelper.java   | 62 +++++++++++-----------
 .../statistics/ColumnStatisticsCacheLoader.java    |  2 +-
 2 files changed, 33 insertions(+), 31 deletions(-)

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 f29c617c158..cd1be6c5cb6 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
@@ -216,40 +216,42 @@ public class AuditLogHelper {
                 .setCommandType(ctx.getCommand().toString());
 
         if (ctx.getState().isQuery()) {
-            if (!ctx.getSessionVariable().internalSession) {
-                MetricRepo.COUNTER_QUERY_ALL.increase(1L);
-                
MetricRepo.USER_COUNTER_QUERY_ALL.getOrAdd(ctx.getQualifiedUser()).increase(1L);
-            }
-            try {
-                if (Config.isCloudMode()) {
-                    cloudCluster = ctx.getCloudCluster(false);
-                }
-            } catch (ComputeGroupException e) {
-                LOG.warn("Failed to get cloud cluster", e);
-                return;
-            }
-            MetricRepo.increaseClusterQueryAll(cloudCluster);
-            if (ctx.getState().getStateType() == MysqlStateType.ERR
-                    && ctx.getState().getErrType() != 
QueryState.ErrType.ANALYSIS_ERR) {
-                // err query
+            if (MetricRepo.isInit) {
                 if (!ctx.getSessionVariable().internalSession) {
-                    MetricRepo.COUNTER_QUERY_ERR.increase(1L);
-                    
MetricRepo.USER_COUNTER_QUERY_ERR.getOrAdd(ctx.getQualifiedUser()).increase(1L);
-                    MetricRepo.increaseClusterQueryErr(cloudCluster);
+                    MetricRepo.COUNTER_QUERY_ALL.increase(1L);
+                    
MetricRepo.USER_COUNTER_QUERY_ALL.getOrAdd(ctx.getQualifiedUser()).increase(1L);
                 }
-            } else if (ctx.getState().getStateType() == MysqlStateType.OK
-                    || ctx.getState().getStateType() == MysqlStateType.EOF) {
-                // ok query
-                if (!ctx.getSessionVariable().internalSession) {
-                    MetricRepo.HISTO_QUERY_LATENCY.update(elapseMs);
-                    
MetricRepo.USER_HISTO_QUERY_LATENCY.getOrAdd(ctx.getQualifiedUser()).update(elapseMs);
-                    MetricRepo.updateClusterQueryLatency(cloudCluster, 
elapseMs);
+                try {
+                    if (Config.isCloudMode()) {
+                        cloudCluster = ctx.getCloudCluster(false);
+                    }
+                } catch (ComputeGroupException e) {
+                    LOG.warn("Failed to get cloud cluster", e);
+                    return;
                 }
+                MetricRepo.increaseClusterQueryAll(cloudCluster);
+                if (ctx.getState().getStateType() == MysqlStateType.ERR
+                        && ctx.getState().getErrType() != 
QueryState.ErrType.ANALYSIS_ERR) {
+                    // err query
+                    if (!ctx.getSessionVariable().internalSession) {
+                        MetricRepo.COUNTER_QUERY_ERR.increase(1L);
+                        
MetricRepo.USER_COUNTER_QUERY_ERR.getOrAdd(ctx.getQualifiedUser()).increase(1L);
+                        MetricRepo.increaseClusterQueryErr(cloudCluster);
+                    }
+                } else if (ctx.getState().getStateType() == MysqlStateType.OK
+                        || ctx.getState().getStateType() == 
MysqlStateType.EOF) {
+                    // ok query
+                    if (!ctx.getSessionVariable().internalSession) {
+                        MetricRepo.HISTO_QUERY_LATENCY.update(elapseMs);
+                        
MetricRepo.USER_HISTO_QUERY_LATENCY.getOrAdd(ctx.getQualifiedUser()).update(elapseMs);
+                        MetricRepo.updateClusterQueryLatency(cloudCluster, 
elapseMs);
+                    }
 
-                if (elapseMs > Config.qe_slow_log_ms) {
-                    String sqlDigest = DigestUtils.md5Hex(((Queriable) 
parsedStmt).toDigest());
-                    auditEventBuilder.setSqlDigest(sqlDigest);
-                    MetricRepo.COUNTER_QUERY_SLOW.increase(1L);
+                    if (elapseMs > Config.qe_slow_log_ms) {
+                        String sqlDigest = DigestUtils.md5Hex(((Queriable) 
parsedStmt).toDigest());
+                        auditEventBuilder.setSqlDigest(sqlDigest);
+                        MetricRepo.COUNTER_QUERY_SLOW.increase(1L);
+                    }
                 }
             }
             auditEventBuilder.setIsQuery(true)
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
index 692d723ed0a..8e29fe25d72 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatisticsCacheLoader.java
@@ -42,7 +42,7 @@ public class ColumnStatisticsCacheLoader extends 
BasicAsyncCacheLoader<Statistic
                 columnStatistic = table.getColumnStatistic(key.colName);
             }
         } catch (Throwable t) {
-            LOG.warn("Failed to load stats for column [Catalog:{}, DB:{}, 
Table:{}, Column:{}], Reason: {}",
+            LOG.info("Failed to load stats for column [Catalog:{}, DB:{}, 
Table:{}, Column:{}], Reason: {}",
                     key.catalogId, key.dbId, key.tableId, key.colName, 
t.getMessage());
             if (LOG.isDebugEnabled()) {
                 LOG.debug(t);


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

Reply via email to