Skip to content

Commit

Permalink
[enhance](mtmv)Mtmv support audit log (#41499) (#41841)
Browse files Browse the repository at this point in the history
pick from master #41499
  • Loading branch information
zddr authored Nov 1, 2024
1 parent d27c1bb commit 8034ab1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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;
Expand Down Expand Up @@ -199,7 +200,7 @@ public void run() throws JobException {
// 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);
}
Expand All @@ -214,10 +215,10 @@ public void run() throws JobException {
}
}

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();
Expand All @@ -226,20 +227,34 @@ private void exec(ConnectContext ctx, Set<String> refreshPartitionNames,
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static ConnectContext createMTMVContext(MTMV mtmv) {
if (workloadGroup.isPresent()) {
ctx.getSessionVariable().setWorkloadGroup(workloadGroup.get());
}
ctx.setStartTime();
return ctx;
}

Expand Down

0 comments on commit 8034ab1

Please sign in to comment.