This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 5146a595726 branch-2.1:[fix](audit)Fixed an issue that the audit log
would record the previo… (#54010)
5146a595726 is described below
commit 5146a595726276e58df12ac22ddc7c0fbf1c8ce2
Author: zhangdong <[email protected]>
AuthorDate: Thu Sep 11 16:40:17 2025 +0800
branch-2.1:[fix](audit)Fixed an issue that the audit log would record the
previo… (#54010)
…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 | 1 +
.../org/apache/doris/qe/ConnectContextTest.java | 24 ++++++++++++++++++++++
.../java/org/apache/doris/qe/SqlCacheTest.java | 6 +++---
7 files changed, 45 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 fef45cec904..000bbc0691e 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
@@ -139,6 +139,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()));
@@ -166,6 +167,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 420ed780332..a01c8b7f119 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
@@ -56,7 +56,7 @@ import java.util.Set;
/** SqlCacheContext */
public class SqlCacheContext {
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;
@@ -95,9 +95,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() {
@@ -422,6 +421,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 cc04721ab80..ae57b5341e0 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
@@ -255,10 +255,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 3d68225c63f..33b029c268b 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
@@ -878,6 +878,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 9237e272e50..5e57a001f17 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
@@ -225,6 +225,7 @@ public abstract class ConnectProcessor {
// only throw an exception when there is a problem interacting with the
requesting client
protected void handleQuery(MysqlCommand mysqlCommand, String originStmt)
throws ConnectionException {
+ ctx.resetQueryId();
try {
executeQuery(mysqlCommand, originStmt);
} catch (ConnectionException exception) {
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 718cb0ecb59..693b66c7461 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]