This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new d8f734a14d4 branch-3.0:[fix](audit)Fixed an issue that the audit log
would record the previo… (#54008)
d8f734a14d4 is described below
commit d8f734a14d467c09086d6f939164c2e40849df09
Author: zhangdong <[email protected]>
AuthorDate: Wed Jul 30 09:30:47 2025 +0800
branch-3.0:[fix](audit)Fixed an issue that the audit log would record the
previo… (#54008)
…us queryId when parseSQL fails. (#53107)
pick: https://github.com/apache/doris/pull/53107
---
.../doris/common/NereidsSqlCacheManager.java | 2 ++
.../org/apache/doris/nereids/SqlCacheContext.java | 9 +++++---
.../org/apache/doris/nereids/StatementContext.java | 4 ++--
.../java/org/apache/doris/qe/ConnectContext.java | 7 +++++++
.../java/org/apache/doris/qe/ConnectProcessor.java | 3 +++
.../org/apache/doris/qe/ConnectContextTest.java | 24 ++++++++++++++++++++++
.../java/org/apache/doris/qe/SqlCacheTest.java | 6 +++---
7 files changed, 47 insertions(+), 8 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java
b/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java
index ba4b465d4b0..f9836ccd192 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java
@@ -144,6 +144,7 @@ public class NereidsSqlCacheManager {
}
SqlCacheContext sqlCacheContext = sqlCacheContextOpt.get();
+ sqlCacheContext.setQueryId(connectContext.queryId());
String key = sqlCacheContext.getCacheKeyType() == CacheKeyType.SQL
? generateCacheKey(connectContext, normalizeSql(sql))
: generateCacheKey(connectContext,
DebugUtil.printId(sqlCacheContext.getOrComputeCacheKeyMd5()));
@@ -171,6 +172,7 @@ public class NereidsSqlCacheManager {
return;
}
SqlCacheContext sqlCacheContext = sqlCacheContextOpt.get();
+ sqlCacheContext.setQueryId(connectContext.queryId());
String key = sqlCacheContext.getCacheKeyType() == CacheKeyType.SQL
? generateCacheKey(connectContext, normalizeSql(sql))
: generateCacheKey(connectContext,
DebugUtil.printId(sqlCacheContext.getOrComputeCacheKeyMd5()));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java
index 0794d0aca0b..458cdae3b73 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java
@@ -60,7 +60,7 @@ import java.util.Set;
public class SqlCacheContext {
private static final Logger LOG =
LogManager.getLogger(SqlCacheContext.class);
private final UserIdentity userIdentity;
- private final TUniqueId queryId;
+ private volatile TUniqueId queryId;
// if contains udf/udaf/tableValuesFunction we can not process it and skip
use sql cache
private volatile boolean cannotProcessExpression;
private volatile String originSql;
@@ -99,9 +99,8 @@ public class SqlCacheContext {
private volatile CacheKeyType cacheKeyType = CacheKeyType.SQL;
- public SqlCacheContext(UserIdentity userIdentity, TUniqueId queryId) {
+ public SqlCacheContext(UserIdentity userIdentity) {
this.userIdentity = Objects.requireNonNull(userIdentity, "userIdentity
cannot be null");
- this.queryId = Objects.requireNonNull(queryId, "queryId cannot be
null");
}
public String getPhysicalPlan() {
@@ -437,6 +436,10 @@ public class SqlCacheContext {
this.cacheKeyType = cacheKeyType;
}
+ public void setQueryId(TUniqueId queryId) {
+ this.queryId = queryId;
+ }
+
/** FullTableName */
@lombok.Data
@lombok.AllArgsConstructor
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
index 9401ec102da..ec372f863f8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java
@@ -254,10 +254,10 @@ public class StatementContext implements Closeable {
this.originStatement = originStatement;
exprIdGenerator = ExprId.createGenerator(initialId);
if (connectContext != null && connectContext.getSessionVariable() !=
null
- && connectContext.queryId() != null
&&
CacheAnalyzer.canUseSqlCache(connectContext.getSessionVariable())) {
+ // cannot set the queryId here because the queryId for the current
query is set in the subsequent steps.
this.sqlCacheContext = new SqlCacheContext(
- connectContext.getCurrentUserIdentity(),
connectContext.queryId());
+ connectContext.getCurrentUserIdentity());
if (originStatement != null) {
this.sqlCacheContext.setOriginSql(originStatement.originStmt);
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
index 8b0bdf38571..bf5d7e37ffb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
@@ -867,6 +867,13 @@ public class ConnectContext {
}
}
+ public void resetQueryId() {
+ if (this.queryId != null) {
+ this.lastQueryId = this.queryId.deepCopy();
+ }
+ this.queryId = null;
+ }
+
public void setTraceId(String traceId) {
this.traceId = traceId;
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
index cb3c3478fd0..168eaab9f6f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java
@@ -236,6 +236,9 @@ public abstract class ConnectProcessor {
// only throw an exception when there is a problem interacting with the
requesting client
protected void handleQuery(String originStmt) throws ConnectionException {
+ // Before executing the query, the queryId should be set to empty.
+ // Otherwise, if SQL parsing fails, the audit log will record the
queryId from the previous query.
+ ctx.resetQueryId();
if (Config.isCloudMode()) {
if (!ctx.getCurrentUserIdentity().isRootUser()
&& ((CloudSystemInfoService)
Env.getCurrentSystemInfo()).getInstanceStatus()
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
index 6ad9532a297..70ef82dbcd1 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java
@@ -31,6 +31,7 @@ import org.junit.Test;
import java.nio.channels.SocketChannel;
import java.util.List;
+import java.util.UUID;
public class ConnectContextTest {
@Mocked
@@ -272,4 +273,27 @@ public class ConnectContextTest {
result = context.getInsertTimeoutS();
Assert.assertEquals(propertyValue, result);
}
+
+ @Test
+ public void testResetQueryId() {
+ ConnectContext context = new ConnectContext();
+ Assert.assertNull(context.queryId);
+ Assert.assertNull(context.lastQueryId);
+
+ UUID uuid = UUID.randomUUID();
+ TUniqueId queryId = new TUniqueId(uuid.getMostSignificantBits(),
uuid.getLeastSignificantBits());
+ context.setQueryId(queryId);
+ Assert.assertEquals(queryId, context.queryId);
+ Assert.assertNull(context.lastQueryId);
+
+ context.resetQueryId();
+ Assert.assertNull(context.queryId);
+ Assert.assertEquals(queryId, context.lastQueryId);
+
+ UUID uuid2 = UUID.randomUUID();
+ TUniqueId queryId2 = new TUniqueId(uuid2.getMostSignificantBits(),
uuid2.getLeastSignificantBits());
+ context.setQueryId(queryId2);
+ Assert.assertEquals(queryId2, context.queryId);
+ Assert.assertEquals(queryId, context.lastQueryId);
+ }
}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
index afe95a49bde..f67d037fdf6 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
@@ -37,11 +37,11 @@ public class SqlCacheTest {
queryId.setLo(uuid.getLeastSignificantBits());
UserIdentity admin = new UserIdentity("admin", "127.0.0.1");
- SqlCacheContext cacheContext = new SqlCacheContext(admin, queryId);
+ SqlCacheContext cacheContext = new SqlCacheContext(admin);
cacheContext.setOriginSql("SELECT * FROM tbl");
PUniqueId key1 = cacheContext.doComputeCacheKeyMd5(ImmutableSet.of());
- SqlCacheContext cacheContext2 = new SqlCacheContext(admin, queryId);
+ SqlCacheContext cacheContext2 = new SqlCacheContext(admin);
cacheContext2.setOriginSql(
"-- Same query with comments and extra spaces\n"
+ "/* Comment */ SELECT * FROM tbl "
@@ -49,7 +49,7 @@ public class SqlCacheTest {
PUniqueId key2 = cacheContext2.doComputeCacheKeyMd5(ImmutableSet.of());
Assertions.assertEquals(key1, key2);
- SqlCacheContext cacheContext3 = new SqlCacheContext(admin, queryId);
+ SqlCacheContext cacheContext3 = new SqlCacheContext(admin);
cacheContext3.setOriginSql(
"-- Same query with comments and extra spaces\n"
+ "/* Comment */ SELeCT * FROM tbl "
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]