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


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsTaskScheduler.java:
##########
@@ -17,63 +17,95 @@
 
 package org.apache.doris.statistics;
 
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.Config;
+import org.apache.doris.common.ThreadPoolManager;
 import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.statistics.StatisticsJob.JobState;
+import org.apache.doris.statistics.StatisticsTask.TaskState;
+import org.apache.doris.statistics.StatsCategoryDesc.StatsCategory;
 
+import com.clearspring.analytics.util.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Queues;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Queue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-
-import com.clearspring.analytics.util.Lists;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 /*
 Schedule statistics task
  */
 public class StatisticsTaskScheduler extends MasterDaemon {
     private final static Logger LOG = 
LogManager.getLogger(StatisticsTaskScheduler.class);
 
-    private Queue<StatisticsTask> queue = Queues.newLinkedBlockingQueue();
+    private final Queue<StatisticsTask> queue = 
Queues.newLinkedBlockingQueue();
 
     public StatisticsTaskScheduler() {
         super("Statistics task scheduler", 0);
     }
 
     @Override
     protected void runAfterCatalogReady() {
-        // TODO
-        // step1: task n concurrent tasks from the queue
+        // task n concurrent tasks from the queue
         List<StatisticsTask> tasks = peek();
-        // step2: execute tasks
-        ExecutorService executor = Executors.newFixedThreadPool(tasks.size());
-        List<Future<StatisticsTaskResult>> taskResultList = null;
-        try {
-            taskResultList = executor.invokeAll(tasks);
-        } catch (InterruptedException e) {
-            LOG.warn("Failed to execute this turn of statistics tasks", e);
-        }
-        // step3: update job and statistics
-        handleTaskResult(taskResultList);
-        // step4: remove task from queue
-        remove(tasks.size());
 
+        if (!tasks.isEmpty()) {
+            ThreadPoolExecutor executor = 
ThreadPoolManager.newDaemonCacheThreadPool(tasks.size(),
+                    "statistic-pool", false);
+            StatisticsJobManager jobManager = 
Catalog.getCurrentCatalog().getStatisticsJobManager();
+            Map<Long, StatisticsJob> statisticsJobs = 
jobManager.getIdToStatisticsJob();
+            Map<Long, Future<StatisticsTaskResult>> taskMap = 
Maps.newLinkedHashMap();
+
+            long jobId = -1;
+            int taskSize = 0;
+            for (StatisticsTask task : tasks) {
+                this.queue.remove();

Review Comment:
   If one task fails, do other tasks continue? The statistics collected by 
other tasks may still be used, so that it may not be necessary to check the 
failure status of the job. 
   
   Of course, canceling the task should be checked~



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