morningman commented on code in PR #26146:
URL: https://github.com/apache/doris/pull/26146#discussion_r1400105125


##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.job.extensions.mtmv;
+
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MTMV;
+import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.job.exception.JobException;
+import org.apache.doris.job.task.AbstractTask;
+import org.apache.doris.mtmv.MTMVCache;
+import org.apache.doris.mtmv.MTMVCacheManager;
+import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVRefreshState;
+import org.apache.doris.mtmv.MTMVStatus;
+import org.apache.doris.mysql.privilege.Auth;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.system.SystemInfoService;
+import org.apache.doris.thrift.TUniqueId;
+
+import com.google.common.collect.Lists;
+import com.google.gson.annotations.SerializedName;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.UUID;
+
+public class MTMVTask extends AbstractTask {
+    private static final Logger LOG = LogManager.getLogger(MTMVTask.class);
+    public static final Long MAX_HISTORY_TASKS_NUM = 100L;
+
+    @SerializedName(value = "dn")
+    private String dbName;
+    @SerializedName(value = "mi")
+    private long mtmvId;
+    @SerializedName("sql")
+    private String sql;
+
+    private MTMV mtmv;

Review Comment:
   These can be set to null after task finished



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/EnvInfo.java:
##########
@@ -40,4 +40,12 @@ public String getCtlName() {
     public String getDbName() {

Review Comment:
   use ctlid and dbid



##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVJob.java:
##########
@@ -0,0 +1,152 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.job.extensions.mtmv;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MTMV;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.MetaNotFoundException;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.job.base.AbstractJob;
+import org.apache.doris.job.common.JobType;
+import org.apache.doris.job.common.TaskType;
+import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+import com.google.common.collect.Lists;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MTMVJob extends AbstractJob<MTMVTask> {
+    private static final Logger LOG = LogManager.getLogger(MTMVJob.class);
+    private static final ShowResultSetMetaData JOB_META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column("JobId", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("JobName", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("ExecuteType", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("RecurringStrategy", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("JobStatus", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("CreateTime", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("Comment", 
ScalarType.createVarchar(20)))
+                    .build();
+    private static final ShowResultSetMetaData TASK_META_DATA =
+            ShowResultSetMetaData.builder()
+                    .addColumn(new Column("JobId", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("TaskId", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("Status", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("CreateTimeMs", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("StartTimeMs", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("FinishTimeMs", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("Duration", 
ScalarType.createVarchar(20)))
+                    .addColumn(new Column("ExecuteSql", 
ScalarType.createVarchar(20)))
+                    .build();
+
+    @SerializedName(value = "dn")
+    private String dbName;
+    @SerializedName(value = "mi")
+    private long mtmvId;
+
+    public MTMVJob(String dbName, long mtmvId) {
+        this.dbName = dbName;
+        this.mtmvId = mtmvId;
+        super.setCreateTimeMs(System.currentTimeMillis());
+    }
+
+    @Override
+    protected void checkJobParamsInternal() {
+
+    }
+
+    @Override
+    public List<MTMVTask> createTasks(TaskType taskType) {
+        MTMVTask task = new MTMVTask(dbName, mtmvId);
+        task.setTaskType(taskType);
+        ArrayList<MTMVTask> tasks = new ArrayList<>();
+        tasks.add(task);
+        super.initTasks(tasks);

Review Comment:
   The inittasks should be called in JobScheduler



##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.job.extensions.mtmv;
+
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MTMV;
+import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.job.exception.JobException;
+import org.apache.doris.job.task.AbstractTask;
+import org.apache.doris.mtmv.MTMVCache;
+import org.apache.doris.mtmv.MTMVCacheManager;
+import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVRefreshState;
+import org.apache.doris.mtmv.MTMVStatus;
+import org.apache.doris.mysql.privilege.Auth;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.system.SystemInfoService;
+import org.apache.doris.thrift.TUniqueId;
+
+import com.google.common.collect.Lists;
+import com.google.gson.annotations.SerializedName;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.UUID;
+
+public class MTMVTask extends AbstractTask {
+    private static final Logger LOG = LogManager.getLogger(MTMVTask.class);
+    public static final Long MAX_HISTORY_TASKS_NUM = 100L;
+
+    @SerializedName(value = "dn")
+    private String dbName;
+    @SerializedName(value = "mi")
+    private long mtmvId;
+    @SerializedName("sql")
+    private String sql;
+
+    private MTMV mtmv;
+    private MTMVCache cache;
+
+    public MTMVTask(String dbName, long mtmvId) {
+        this.dbName = dbName;
+        this.mtmvId = mtmvId;
+    }
+
+    @Override
+    public void run() throws JobException {
+        ConnectContext ctx = createContext();
+        TUniqueId queryId = generateQueryId();
+
+        cache = MTMVCacheManager.generateMTMVCache(mtmv);
+        StmtExecutor executor = new StmtExecutor(ctx, sql);
+        try {
+            executor.execute(queryId);
+        } catch (Exception e) {
+            LOG.warn(e);
+            throw new JobException(e);
+        }
+    }
+
+    @Override
+    public void onFail() throws JobException {
+        super.onFail();
+        addTaskResult();
+    }
+
+    @Override
+    public void onSuccess() throws JobException {
+        super.onSuccess();
+        addTaskResult();
+    }
+
+    @Override
+    public void cancel() throws JobException {
+        super.cancel();
+        addTaskResult();
+    }
+
+    @Override
+    public void before() throws JobException {
+        super.before();
+        try {
+            Database db = 
Env.getCurrentInternalCatalog().getDbOrDdlException(dbName);
+            mtmv = (MTMV) db.getTableOrMetaException(mtmvId, 
TableType.MATERIALIZED_VIEW);
+            sql = generateSql(mtmv);
+            MTMVStatus status = new MTMVStatus(MTMVRefreshState.REFRESHING);

Review Comment:
   do not need to persist REFRESHING



##########
fe/fe-core/src/main/java/org/apache/doris/job/task/AbstractTask.java:
##########
@@ -21,39 +21,45 @@
 import org.apache.doris.job.base.Job;
 import org.apache.doris.job.common.TaskStatus;
 import org.apache.doris.job.common.TaskType;
+import org.apache.doris.job.exception.JobException;
 
+import com.google.gson.annotations.SerializedName;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
 @Data
 @Slf4j
 public abstract class AbstractTask implements Task {
 
+    @SerializedName(value = "jid")
     private Long jobId;
-
+    @SerializedName(value = "tid")
     private Long taskId;
 
+    @SerializedName(value = "st")
     private TaskStatus status;
-
+    @SerializedName(value = "ctm")
     private Long createTimeMs;
-
+    @SerializedName(value = "stm")
     private Long startTimeMs;
-
+    @SerializedName(value = "ftm")
     private Long finishTimeMs;
 
+    @SerializedName(value = "tt")
     private TaskType taskType;
 
     @Override
     public void onFail(String msg) {
+        status = TaskStatus.FAILD;
         if (!isCallable()) {
             return;
         }
         Env.getCurrentEnv().getJobManager().getJob(jobId).onTaskFail(this);
-        status = TaskStatus.FAILD;
     }
 
     @Override
-    public void onFail() {
+    public void onFail() throws JobException {
+        status = TaskStatus.FAILD;

Review Comment:
   Is it possible that job can not be found(eg, being dropped)?



##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.job.extensions.mtmv;
+
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MTMV;
+import org.apache.doris.catalog.TableIf.TableType;
+import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.TimeUtils;
+import org.apache.doris.job.exception.JobException;
+import org.apache.doris.job.task.AbstractTask;
+import org.apache.doris.mtmv.MTMVCache;
+import org.apache.doris.mtmv.MTMVCacheManager;
+import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVRefreshState;
+import org.apache.doris.mtmv.MTMVStatus;
+import org.apache.doris.mysql.privilege.Auth;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.system.SystemInfoService;
+import org.apache.doris.thrift.TUniqueId;
+
+import com.google.common.collect.Lists;
+import com.google.gson.annotations.SerializedName;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.UUID;
+
+public class MTMVTask extends AbstractTask {
+    private static final Logger LOG = LogManager.getLogger(MTMVTask.class);
+    public static final Long MAX_HISTORY_TASKS_NUM = 100L;
+
+    @SerializedName(value = "dn")
+    private String dbName;
+    @SerializedName(value = "mi")
+    private long mtmvId;
+    @SerializedName("sql")
+    private String sql;
+
+    private MTMV mtmv;
+    private MTMVCache cache;
+
+    public MTMVTask(String dbName, long mtmvId) {
+        this.dbName = dbName;
+        this.mtmvId = mtmvId;
+    }
+
+    @Override
+    public void run() throws JobException {
+        ConnectContext ctx = createContext();
+        TUniqueId queryId = generateQueryId();
+
+        cache = MTMVCacheManager.generateMTMVCache(mtmv);

Review Comment:
   Add some comment to explain why create cache each time



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to