morningman commented on a change in pull request #3716:
URL: https://github.com/apache/incubator-doris/pull/3716#discussion_r432800096



##########
File path: fe/src/main/java/org/apache/doris/catalog/OlapTable.java
##########
@@ -530,6 +530,30 @@ public KeysType getKeysType() {
         return keysType;
     }
 
+    public KeysType getKeysTypeByIndexId(long indexId) {

Review comment:
       There is `keysType` is `MaterializedIndexMeta`. You can get it directly.

##########
File path: fe/src/main/java/org/apache/doris/common/util/BrokerUtil.java
##########
@@ -17,52 +17,59 @@
 
 package org.apache.doris.common.util;
 
-import com.google.common.collect.Lists;
 import org.apache.doris.analysis.BrokerDesc;
 import org.apache.doris.catalog.Catalog;
 import org.apache.doris.catalog.FsBroker;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.UserException;
 import org.apache.doris.service.FrontendOptions;
+import org.apache.doris.thrift.TBrokerCloseReaderRequest;
+import org.apache.doris.thrift.TBrokerCloseWriterRequest;
+import org.apache.doris.thrift.TBrokerDeletePathRequest;
+import org.apache.doris.thrift.TBrokerFD;
 import org.apache.doris.thrift.TBrokerFileStatus;
 import org.apache.doris.thrift.TBrokerListPathRequest;
 import org.apache.doris.thrift.TBrokerListResponse;
+import org.apache.doris.thrift.TBrokerOpenMode;
+import org.apache.doris.thrift.TBrokerOpenReaderRequest;
+import org.apache.doris.thrift.TBrokerOpenReaderResponse;
+import org.apache.doris.thrift.TBrokerOpenWriterRequest;
+import org.apache.doris.thrift.TBrokerOpenWriterResponse;
+import org.apache.doris.thrift.TBrokerOperationStatus;
 import org.apache.doris.thrift.TBrokerOperationStatusCode;
+import org.apache.doris.thrift.TBrokerPReadRequest;
+import org.apache.doris.thrift.TBrokerPWriteRequest;
+import org.apache.doris.thrift.TBrokerReadResponse;
 import org.apache.doris.thrift.TBrokerVersion;
 import org.apache.doris.thrift.TNetworkAddress;
 import org.apache.doris.thrift.TPaloBrokerService;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.thrift.TException;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
 import java.util.Collections;
 import java.util.List;
 
 public class BrokerUtil {
     private static final Logger LOG = LogManager.getLogger(BrokerUtil.class);
 
+    private static int READ_BUFFER_SIZE = 1024 * 1024;

Review comment:
       add unit to name.

##########
File path: fe/src/main/java/org/apache/doris/common/Pair.java
##########
@@ -25,7 +27,9 @@
 public class Pair<F, S> {
     public static PairComparator<Pair<?, Comparable>> PAIR_VALUE_COMPARATOR = 
new PairComparator<>();
 
+    @SerializedName(value = "first")

Review comment:
       I'am not sure this is ok, cause there is no guarantee that the `F` and 
`S` object can also be serialized by GSON

##########
File path: fe/src/main/java/org/apache/doris/load/loadv2/SparkEtlJobHandler.java
##########
@@ -0,0 +1,170 @@
+// 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.PaloFe;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.catalog.SparkResource;
+import org.apache.doris.common.LoadException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.load.loadv2.etl.EtlJobConfig;
+import org.apache.doris.thrift.TEtlState;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.spark.launcher.SparkAppHandle;
+import org.apache.spark.launcher.SparkAppHandle.Listener;
+import org.apache.spark.launcher.SparkAppHandle.State;
+import org.apache.spark.launcher.SparkLauncher;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+/**
+ * SparkEtlJobHandler is responsible for
+ * 1. submit spark etl job
+ * 2. get spark etl job status
+ * 3. kill spark etl job
+ * 4. get spark etl file paths
+ * 5. delete etl output path
+ */
+public class SparkEtlJobHandler {
+    private static final Logger LOG = 
LogManager.getLogger(SparkEtlJobHandler.class);
+
+    private static final String APP_RESOURCE_NAME = "palo-fe.jar";
+    private static final String CONFIG_FILE_NAME = "jobconfig.json";
+    private static final String APP_RESOURCE_LOCAL_PATH = 
PaloFe.DORIS_HOME_DIR + "/lib/" + APP_RESOURCE_NAME;
+    private static final String JOB_CONFIG_DIR = "configs";
+    private static final String MAIN_CLASS = 
"org.apache.doris.load.loadv2.etl.SparkEtlJob";

Review comment:
       How about get it from `SparkEtlJob.class.getXXX()`?

##########
File path: fe/src/main/java/org/apache/doris/load/loadv2/SparkEtlJobHandler.java
##########
@@ -0,0 +1,170 @@
+// 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.PaloFe;
+import org.apache.doris.analysis.BrokerDesc;
+import org.apache.doris.catalog.SparkResource;
+import org.apache.doris.common.LoadException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.load.loadv2.etl.EtlJobConfig;
+import org.apache.doris.thrift.TEtlState;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.spark.launcher.SparkAppHandle;
+import org.apache.spark.launcher.SparkAppHandle.Listener;
+import org.apache.spark.launcher.SparkAppHandle.State;
+import org.apache.spark.launcher.SparkLauncher;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+/**
+ * SparkEtlJobHandler is responsible for
+ * 1. submit spark etl job
+ * 2. get spark etl job status
+ * 3. kill spark etl job
+ * 4. get spark etl file paths
+ * 5. delete etl output path
+ */
+public class SparkEtlJobHandler {
+    private static final Logger LOG = 
LogManager.getLogger(SparkEtlJobHandler.class);
+
+    private static final String APP_RESOURCE_NAME = "palo-fe.jar";
+    private static final String CONFIG_FILE_NAME = "jobconfig.json";
+    private static final String APP_RESOURCE_LOCAL_PATH = 
PaloFe.DORIS_HOME_DIR + "/lib/" + APP_RESOURCE_NAME;
+    private static final String JOB_CONFIG_DIR = "configs";
+    private static final String MAIN_CLASS = 
"org.apache.doris.load.loadv2.etl.SparkEtlJob";
+    private static final String ETL_JOB_NAME = "doris__%s";
+    // 5min
+    private static final int GET_APPID_MAX_RETRY_TIMES = 300;
+    private static final int GET_APPID_SLEEP_MS = 1000;
+
+    class SparkAppListener implements Listener {
+        @Override
+        public void stateChanged(SparkAppHandle sparkAppHandle) {}
+
+        @Override
+        public void infoChanged(SparkAppHandle sparkAppHandle) {}
+    }
+
+    public void submitEtlJob(long loadJobId, String loadLabel, EtlJobConfig 
etlJobConfig, SparkResource resource,
+                             BrokerDesc brokerDesc, SparkPendingTaskAttachment 
attachment) throws LoadException {
+        // delete outputPath
+        deleteEtlOutputPath(etlJobConfig.outputPath, brokerDesc);
+
+        // upload app resource and jobconfig to hdfs
+        String configsHdfsDir = etlJobConfig.outputPath + "/" + JOB_CONFIG_DIR 
+ "/";
+        String appResourceHdfsPath = configsHdfsDir + APP_RESOURCE_NAME;
+        String jobConfigHdfsPath = configsHdfsDir + CONFIG_FILE_NAME;
+        try {
+            BrokerUtil.writeBrokerFile(APP_RESOURCE_LOCAL_PATH, 
appResourceHdfsPath, brokerDesc);
+            byte[] configData = etlJobConfig.configToJson().getBytes("UTF-8");
+            BrokerUtil.writeBrokerFile(configData, jobConfigHdfsPath, 
brokerDesc);
+        } catch (UserException | UnsupportedEncodingException e) {
+            throw new LoadException(e.getMessage());
+        }
+
+        SparkLauncher launcher = new SparkLauncher();
+        // master      |  deployMode
+        // ------------|-------------
+        // yarn        |  cluster
+        // spark://xx  |  client
+        launcher.setMaster(resource.getMaster())
+                .setDeployMode(resource.getDeployMode().name().toLowerCase())
+                .setAppResource(appResourceHdfsPath)
+                .setMainClass(MAIN_CLASS)
+                .setAppName(String.format(ETL_JOB_NAME, loadLabel))
+                .addAppArgs(jobConfigHdfsPath);
+        // spark configs
+        for (Map.Entry<String, String> entry : 
resource.getSparkConfigs().entrySet()) {
+            launcher.setConf(entry.getKey(), entry.getValue());
+        }
+
+        // start app
+        SparkAppHandle handle = null;
+        State state = null;
+        String appId = null;
+        int retry = 0;
+        String errMsg = "start spark app failed. error: ";
+        try {
+            handle = launcher.startApplication(new SparkAppListener());
+        } catch (IOException e) {
+            LOG.warn(errMsg, e);
+            throw new LoadException(errMsg + e.getMessage());
+        }
+
+        while (retry++ < GET_APPID_MAX_RETRY_TIMES) {
+            appId = handle.getAppId();
+            if (appId != null) {
+                break;
+            }
+
+            // check state and retry
+            state = handle.getState();
+            if (fromSparkState(state) == TEtlState.CANCELLED) {
+                throw new LoadException(errMsg + "spark app state: " + 
state.toString());
+            }
+            if (retry >= GET_APPID_MAX_RETRY_TIMES) {
+                throw new LoadException(errMsg + "wait too much time for 
getting appid. spark app state: "

Review comment:
       ```suggestion
                   throw new LoadException(errMsg + " wait too much time for 
getting appi d. spark app state: "
   ```




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



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

Reply via email to