EmmyMiao87 commented on a change in pull request #1076: Add new scheduler of 
load in fe
URL: https://github.com/apache/incubator-doris/pull/1076#discussion_r279663541
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/load/loadv2/BrokerLoadJob.java
 ##########
 @@ -0,0 +1,229 @@
+/*
+ * 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.load.loadv2;
+
+
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.analysis.DataDescription;
+import org.apache.doris.analysis.LoadStmt;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.MetaNotFoundException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.LogBuilder;
+import org.apache.doris.common.util.LogKey;
+import org.apache.doris.load.BrokerFileGroup;
+import org.apache.doris.load.FailMsg;
+import org.apache.doris.load.PullLoadSourceInfo;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public class BrokerLoadJob extends LoadJob {
+
+    private static final Logger LOG = 
LogManager.getLogger(BrokerLoadJob.class);
+
+    private BrokerDesc brokerDesc;
+    // include broker desc and data desc
+    private PullLoadSourceInfo dataSourceInfo = new PullLoadSourceInfo();
+
+    public BrokerLoadJob(long dbId, String label, BrokerDesc brokerDesc) {
+        super(dbId, label);
+        this.timeoutSecond = Config.pull_load_task_default_timeout_second;
+        this.brokerDesc = brokerDesc;
+    }
+
+    public static BrokerLoadJob fromLoadStmt(LoadStmt stmt) throws 
DdlException {
+        // get db id
+        String dbName = stmt.getLabel().getDbName();
+        Database db = Catalog.getInstance().getDb(stmt.getLabel().getDbName());
+        if (db == null) {
+            throw new DdlException("Database[" + dbName + "] does not exist");
+        }
+
+        // create job
+        BrokerLoadJob brokerLoadJob = new BrokerLoadJob(db.getId(), 
stmt.getLabel().getLabelName(),
+                                                        stmt.getBrokerDesc());
+        brokerLoadJob.setJobProperties(stmt.getProperties());
+        brokerLoadJob.checkDataSourceInfo(db, stmt.getDataDescriptions());
+        brokerLoadJob.setDataSourceInfo(db, stmt.getDataDescriptions());
+        return brokerLoadJob;
+    }
+
+    private void setDataSourceInfo(Database db, List<DataDescription> 
dataDescriptions) throws DdlException {
+        for (DataDescription dataDescription : dataDescriptions) {
+            BrokerFileGroup fileGroup = new BrokerFileGroup(dataDescription);
+            fileGroup.parse(db);
+            dataSourceInfo.addFileGroup(fileGroup);
+        }
+    }
+
+    @Override
+    public void executeScheduleJob() {
+        LoadTask task = new BrokerLoadPendingTask(this, 
dataSourceInfo.getIdToFileGroups(), brokerDesc);
+        tasks.add(task);
+        Catalog.getCurrentCatalog().getLoadManager().submitTask(task);
+    }
+
+    @Override
+    public void onTaskFinished(TaskAttachment attachment) {
+        if (attachment instanceof BrokerPendingTaskAttachment) {
+            onPendingTaskFinished((BrokerPendingTaskAttachment) attachment);
+        } else if (attachment instanceof BrokerLoadingTaskAttachment) {
+            onLoadingTaskFinished((BrokerLoadingTaskAttachment) attachment);
+        }
 
 Review comment:
   Situation 1 (BrokerPendingTask ):There is only one pending task in 
BrokerLoad. So this function will not be called concurrently when pending task.
   Situation 2 (LoadingTask): I add the writelock before onLoadingTaskFinished. 
So the loading task will be serial executed.
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to