This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 8034ab187d4 [enhance](mtmv)Mtmv support audit log (#41499) (#41841)
8034ab187d4 is described below
commit 8034ab187d43995f147104fd39bdb3bb0a8653ab
Author: zhangdong <[email protected]>
AuthorDate: Fri Nov 1 19:20:53 2024 +0800
[enhance](mtmv)Mtmv support audit log (#41499) (#41841)
pick from master #41499
---
.../apache/doris/job/extensions/mtmv/MTMVTask.java | 43 +++++++++++++++-------
.../java/org/apache/doris/mtmv/MTMVPlanUtil.java | 1 +
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
index a2ec9fb03b0..a22070a0fd1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
@@ -46,6 +46,7 @@ import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
import
org.apache.doris.nereids.trees.plans.commands.UpdateMvByPartitionCommand;
import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.qe.AuditLogHelper;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.qe.StmtExecutor;
@@ -199,7 +200,7 @@ public class MTMVTask extends AbstractTask {
// need get names before exec
Map<String, MTMVRefreshPartitionSnapshot>
execPartitionSnapshots = MTMVPartitionUtil
.generatePartitionSnapshots(context,
relation.getBaseTablesOneLevel(), execPartitionNames);
- exec(ctx, execPartitionNames, tableWithPartKey);
+ exec(execPartitionNames, tableWithPartKey);
completedPartitions.addAll(execPartitionNames);
partitionSnapshots.putAll(execPartitionSnapshots);
}
@@ -214,10 +215,10 @@ public class MTMVTask extends AbstractTask {
}
}
- private void exec(ConnectContext ctx, Set<String> refreshPartitionNames,
+ private void exec(Set<String> refreshPartitionNames,
Map<TableIf, String> tableWithPartKey)
throws Exception {
- Objects.requireNonNull(ctx, "ctx should not be null");
+ ConnectContext ctx = MTMVPlanUtil.createMTMVContext(mtmv);
StatementContext statementContext = new StatementContext();
ctx.setStatementContext(statementContext);
TUniqueId queryId = generateQueryId();
@@ -226,20 +227,34 @@ public class MTMVTask extends AbstractTask {
UpdateMvByPartitionCommand command = UpdateMvByPartitionCommand
.from(mtmv, mtmv.getMvPartitionInfo().getPartitionType() !=
MTMVPartitionType.SELF_MANAGE
? refreshPartitionNames : Sets.newHashSet(),
tableWithPartKey);
- executor = new StmtExecutor(ctx, new LogicalPlanAdapter(command,
ctx.getStatementContext()));
- ctx.setExecutor(executor);
- ctx.setQueryId(queryId);
- ctx.getState().setNereids(true);
- command.run(ctx, executor);
- if (getStatus() == TaskStatus.CANCELED) {
- // Throwing an exception to interrupt subsequent partition update
tasks
- throw new JobException("task is CANCELED");
- }
- if (ctx.getState().getStateType() != MysqlStateType.OK) {
- throw new JobException(ctx.getState().getErrorMessage());
+ try {
+ executor = new StmtExecutor(ctx, new LogicalPlanAdapter(command,
ctx.getStatementContext()));
+ ctx.setExecutor(executor);
+ ctx.setQueryId(queryId);
+ ctx.getState().setNereids(true);
+ command.run(ctx, executor);
+ if (getStatus() == TaskStatus.CANCELED) {
+ // Throwing an exception to interrupt subsequent partition
update tasks
+ throw new JobException("task is CANCELED");
+ }
+ if (ctx.getState().getStateType() != MysqlStateType.OK) {
+ throw new JobException(ctx.getState().getErrorMessage());
+ }
+ } finally {
+ if (executor != null) {
+ AuditLogHelper.logAuditLog(ctx,
getDummyStmt(refreshPartitionNames),
+ executor.getParsedStmt(),
executor.getQueryStatisticsForAuditLog(), true);
+ }
}
}
+ private String getDummyStmt(Set<String> refreshPartitionNames) {
+ return String.format(
+ "Asynchronous materialized view refresh task, mvName: %s,"
+ + "taskId: %s, partitions refreshed by this insert
overwrite: %s",
+ mtmv.getName(), super.getTaskId(), refreshPartitionNames);
+ }
+
@Override
public synchronized void onFail() throws JobException {
LOG.info("mtmv task onFail, taskId: {}", super.getTaskId());
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
index 8dcca9851c5..0a93af5676f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
@@ -64,6 +64,7 @@ public class MTMVPlanUtil {
if (workloadGroup.isPresent()) {
ctx.getSessionVariable().setWorkloadGroup(workloadGroup.get());
}
+ ctx.setStartTime();
return ctx;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]