weizhengte commented on code in PR #8859:
URL: https://github.com/apache/incubator-doris/pull/8859#discussion_r856107078


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsJob.java:
##########
@@ -18,62 +18,200 @@
 package org.apache.doris.statistics;
 
 import org.apache.doris.analysis.AnalyzeStmt;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.AnalysisException;
 
-import com.google.common.collect.Maps;
+import com.clearspring.analytics.util.Lists;
 
-import org.glassfish.jersey.internal.guava.Sets;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import com.clearspring.analytics.util.Lists;
-
-/*
-Used to store statistics job info,
-including job status, progress, etc.
+/***
+ * Used to store statistics job info,
+ * including job status, progress, etc.
  */
 public class StatisticsJob {
+    private static final Logger LOG = 
LogManager.getLogger(StatisticsJob.class);
 
     public enum JobState {
         PENDING,
         SCHEDULING,
         RUNNING,
         FINISHED,
+        FAILED,
         CANCELLED
     }
 
-    private long id = -1;
+    private long id = Catalog.getCurrentCatalog().getNextId();
+
+    /**
+     * to be collected database stats.
+     */
+    private final long dbId;
+
+    /**
+     * to be collected table stats.
+     */
+    private final Set<Long> tblIds;
+
+    /**
+     * to be collected column stats.
+     */
+    private final Map<Long, List<String>> tableIdToColumnName;
+
+    /**
+     * timeout of a statistics task
+     */
+    private long taskTimeout;
+
+    /**
+     * to be executed tasks.
+     */
+    private List<StatisticsTask> tasks = Lists.newArrayList();
+
     private JobState jobState = JobState.PENDING;
-    // optional
-    // to be collected table stats
-    private List<Long> tableId = Lists.newArrayList();
-    // to be collected column stats
-    private Map<Long, List<String>> tableIdToColumnName = Maps.newHashMap();
-    private Map<String, String> properties;
-    // end
+    private final List<String> errorMsgs = Lists.newArrayList();
 
-    private List<StatisticsTask> taskList = Lists.newArrayList();
+    private final long createTime = System.currentTimeMillis();
+    private long startTime = -1L;
+    private long finishTime = -1L;
+    private int progress = 0;
+
+    public StatisticsJob(Long dbId,
+                         Set<Long> tblIds,
+                         Map<Long, List<String>> tableIdToColumnName) {
+        this.dbId = dbId;
+        this.tblIds = tblIds;
+        this.tableIdToColumnName = tableIdToColumnName;
+    }
 
     public long getId() {
-        return id;
+        return this.id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getDbId() {
+        return this.dbId;
+    }
+
+    public Set<Long> getTblIds() {
+        return this.tblIds;
+    }
+
+    public Map<Long, List<String>> getTableIdToColumnName() {
+        return this.tableIdToColumnName;
+    }
+
+    public long getTaskTimeout() {
+        return taskTimeout;
     }
 
-    /*
-        AnalyzeStmt: Analyze t1(c1), t2
-        StatisticsJob:
-          tableId [t1, t2]
-          tableIdToColumnName <t1, [c1]> <t2, [c1,c2,c3]>
-         */
-    public static StatisticsJob fromAnalyzeStmt(AnalyzeStmt analyzeStmt) {
-        // TODO
-        return new StatisticsJob();
+    public List<StatisticsTask> getTasks() {
+        return this.tasks;
+    }
+
+    public void setTasks(List<StatisticsTask> tasks) {
+        this.tasks = tasks;
+    }
+
+    public List<String> getErrorMsgs() {
+        return errorMsgs;
+    }
+
+    public JobState getJobState() {
+        return this.jobState;
+    }
+
+    public long getCreateTime() {
+        return this.createTime;
+    }
+
+    public long getStartTime() {
+        return this.startTime;
+    }
+
+    public void setStartTime(long startTime) {
+        this.startTime = startTime;
+    }
+
+    public long getFinishTime() {
+        return this.finishTime;
+    }
+
+    public void setFinishTime(long finishTime) {
+        this.finishTime = finishTime;
+    }
+
+    public int getProgress() {
+        return this.progress;
+    }
+
+    public void setProgress(int progress) {
+        this.progress = progress;
+    }
+
+    private void setOptional(AnalyzeStmt stmt) {
+        if (stmt.getTaskTimeout() != -1) {
+            this.taskTimeout = stmt.getTaskTimeout();
+        }
+    }
+
+    public synchronized void updateJobState(JobState jobState) {
+        // PENDING -> SCHEDULING/FAILED/CANCELLED
+        if (this.jobState == JobState.PENDING) {
+            if (jobState == JobState.SCHEDULING) {
+                this.jobState = JobState.SCHEDULING;
+            } else if (jobState == JobState.FAILED) {
+                this.jobState = JobState.FAILED;
+            } else if (jobState == JobState.CANCELLED) {
+                this.jobState = JobState.CANCELLED;
+            }
+            return;
+        }
+
+        // SCHEDULING -> RUNNING/FAILED/CANCELLED
+        if (this.jobState == JobState.SCHEDULING) {
+            if (jobState == JobState.RUNNING) {
+                this.jobState = JobState.RUNNING;
+            } else if (jobState == JobState.FAILED) {
+                this.jobState = JobState.FAILED;
+            } else if (jobState == JobState.CANCELLED) {
+                this.jobState = JobState.CANCELLED;
+            }
+            return;
+        }
+
+        // RUNNING -> FINISHED/FAILED/CANCELLED
+        if (this.jobState == JobState.RUNNING) {
+            if (jobState == JobState.FINISHED) {
+                this.jobState = JobState.FINISHED;
+            } else if (jobState == JobState.FAILED) {
+                this.jobState = JobState.FAILED;
+            } else if (jobState == JobState.CANCELLED) {
+                this.jobState = JobState.CANCELLED;
+            }
+        }

Review Comment:
   This willprint log in the method of job status update.



-- 
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