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


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsJobManager.java:
##########
@@ -35,39 +44,74 @@
 public class StatisticsJobManager {
     private static final Logger LOG = 
LogManager.getLogger(StatisticsJobManager.class);
 
-    // statistics job
-    private Map<Long, StatisticsJob> idToStatisticsJob = 
Maps.newConcurrentMap();
+    /**
+     * save statistics job status information
+     */
+    private final Map<Long, StatisticsJob> idToStatisticsJob = 
Maps.newConcurrentMap();
 
-    public void createStatisticsJob(AnalyzeStmt analyzeStmt) {
-        // step0: init statistics job by analyzeStmt
+    public Map<Long, StatisticsJob> getIdToStatisticsJob() {
+        return this.idToStatisticsJob;
+    }
+
+    public void createStatisticsJob(AnalyzeStmt analyzeStmt) throws 
UserException {
+        // step1: init statistics job by analyzeStmt
         StatisticsJob statisticsJob = 
StatisticsJob.fromAnalyzeStmt(analyzeStmt);
-        // step1: get statistics to be analyzed
-        Set<Long> tableIdList = statisticsJob.relatedTableId();
+
         // step2: check restrict
-        checkRestrict(tableIdList);
-        // step3: check permission
-        checkPermission();
-        // step4: create it
-        createStatisticsJob(statisticsJob);
+        this.checkRestrict(statisticsJob.getDbId(), 
statisticsJob.relatedTableId());
+
+        // step3: create it
+        this.createStatisticsJob(statisticsJob);
     }
 
-    public void createStatisticsJob(StatisticsJob statisticsJob) {
-        idToStatisticsJob.put(statisticsJob.getId(), statisticsJob);
+    public void createStatisticsJob(StatisticsJob statisticsJob) throws 
DdlException {
+        this.idToStatisticsJob.put(statisticsJob.getId(), statisticsJob);
         try {
             
Catalog.getCurrentCatalog().getStatisticsJobScheduler().addPendingJob(statisticsJob);
         } catch (IllegalStateException e) {
-            LOG.info("The pending statistics job is full. Please submit it 
again later.");
+            throw new DdlException("The pending statistics job is full, Please 
submit it again later.");
         }
     }
 
-    // Rule1: The same table cannot have two unfinished statistics jobs
-    // Rule2: The unfinished statistics job could not more then 
Config.max_statistics_job_num
-    // Rule3: The job for external table is not supported
-    private void checkRestrict(Set<Long> tableIdList) {
-        // TODO
-    }
+    /**
+     * The statistical job has the following restrict:
+     * - Rule1: The same table cannot have two unfinished statistics jobs
+     * - Rule2: The unfinished statistics job could not more then 
Config.max_statistics_job_num
+     * - Rule3: The job for external table is not supported
+     */
+    private synchronized void checkRestrict(long dbId, Set<Long> tableIds) 
throws AnalysisException {
+        Database db = 
Catalog.getCurrentCatalog().getDbOrAnalysisException(dbId);
 
-    private void checkPermission() {
-        // TODO
+        // check table type
+        for (Long tableId : tableIds) {
+            Table table = db.getTableOrAnalysisException(tableId);
+            if (table.getType() != Table.TableType.OLAP) {
+                
ErrorReport.reportAnalysisException(ErrorCode.ERR_NOT_OLAP_TABLE, 
db.getFullName(),table.getName(), "ANALYZE");
+            }
+        }
+
+        int unfinishedJobs = 0;
+
+        // check table unfinished job
+        for (Map.Entry<Long, StatisticsJob> jobEntry : 
this.idToStatisticsJob.entrySet()) {

Review Comment:
   ok~



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