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



##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/SparkResource.java
##########
@@ -144,6 +146,28 @@ public SparkResource getCopiedResource() {
         return new SparkResource(name, Maps.newHashMap(sparkConfigs), 
workingDir, broker, brokerProperties);
     }
 
+    public SparkRepository getRemoteRepository() {
+        String remoteRepositoryPath = workingDir + "/" + 
Catalog.getCurrentCatalog().getClusterId()
+                + "/" + SparkRepository.REPOSITORY_DIR;
+        BrokerDesc brokerDesc = new BrokerDesc(broker, 
getBrokerPropertiesWithoutPrefix());
+        return new SparkRepository(remoteRepositoryPath, brokerDesc);
+    }
+
+    // Each SparkResource has and only has one SparkRepository.
+    // This method get the remote archive which matches the dpp version from 
remote repository
+    public synchronized SparkRepository.SparkArchive prepareArchive() throws 
LoadException {
+        SparkRepository.SparkArchive archive = null;
+        String remoteRepositoryPath = workingDir + "/" + 
Catalog.getCurrentCatalog().getClusterId()
+                + "/" + SparkRepository.REPOSITORY_DIR + name;
+        BrokerDesc brokerDesc = new BrokerDesc(broker, 
getBrokerPropertiesWithoutPrefix());
+        SparkRepository repository = new SparkRepository(remoteRepositoryPath, 
brokerDesc);
+        boolean isPrepare = repository.prepare();

Review comment:
       `isPrepare` is meaningless, we can just call `repository.prepare()` and 
then call `archive = repository.getCurrentArchive();`
   If error happens, exception will be thrown, and this method will never 
return null.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/SparkResource.java
##########
@@ -144,6 +146,28 @@ public SparkResource getCopiedResource() {
         return new SparkResource(name, Maps.newHashMap(sparkConfigs), 
workingDir, broker, brokerProperties);
     }
 
+    public SparkRepository getRemoteRepository() {

Review comment:
       This method is unused, can be removed.

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkRepository.java
##########
@@ -0,0 +1,347 @@
+// 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.common.Config;
+import org.apache.doris.common.LoadException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+
+/*
+ * SparkRepository represents the remote repository for spark archives 
uploaded by spark
+ * The organization in repository is:
+ *
+ * * __spark_repository__/
+ *   * __archive_1_0_0/
+ *     * __lib_990325d2c0d1d5e45bf675e54e44fb16_spark-dpp.jar
+ *     * __lib_7670c29daf535efe3c9b923f778f61fc_spark-2x.zip
+ *   * __archive_2_2_0/
+ *     * __lib_64d5696f99c379af2bee28c1c84271d5_spark-dpp.jar
+ *     * __lib_1bbb74bb6b264a270bc7fca3e964160f_spark-2x.zip
+ *   * __archive_3_2_0/
+ *     * ...
+ */
+public class SparkRepository {
+    private static final Logger LOG = 
LogManager.getLogger(SparkRepository.class);
+
+    public static final String REPOSITORY_DIR = "__spark_repository__";
+    public static final String PREFIX_ARCHIVE = "__archive_";
+    public static final String PREFIX_LIB = "__lib_";
+    public static final String SPARK_DPP = "spark-dpp";
+    public static final String SPARK_2X = "spark-2x";
+    public static final String SUFFIX = ".zip";
+
+    private static final String PATH_DELIMITER = "/";
+    private static final String FILE_NAME_SEPARATOR = "_";
+
+    private static final String DPP_RESOURCE = "/spark-dpp/spark-dpp.jar";
+    private static final String SPARK_RESOURCE = "/jars/spark-2x.zip";
+
+    private String remoteRepositoryPath;
+    private BrokerDesc brokerDesc;
+    private String localDppPath;
+    private String localSpark2xPath;
+
+    // Version of the spark dpp program in this cluster
+    private String currentDppVersion;
+    // Archive that current dpp version pointed to
+    private SparkArchive currentArchive;
+
+    private boolean isInit;

Review comment:
       The `SparkRepository` will be created as a new Object for each time. So 
this `isInit` is meaningless.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/util/BrokerUtil.java
##########
@@ -349,6 +351,39 @@ public static void deletePath(String path, BrokerDesc 
brokerDesc) throws UserExc
         }
     }
 
+    public static boolean checkPathExist(String remotePath, BrokerDesc 
brokerDesc) throws UserException {
+        Pair<TPaloBrokerService.Client, TNetworkAddress> pair = new 
Pair<TPaloBrokerService.Client, TNetworkAddress>(null, null);

Review comment:
       ```suggestion
           Pair<TPaloBrokerService.Client, TNetworkAddress> pair = 
getBrokerAddressAndClient(brokerDesc);
   ```

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkEtlJobHandler.java
##########
@@ -92,12 +90,41 @@ public void submitEtlJob(long loadJobId, String loadLabel, 
EtlJobConfig etlJobCo
         // delete outputPath
         deleteEtlOutputPath(etlJobConfig.outputPath, brokerDesc);
 
-        // upload app resource and jobconfig to hdfs
+        // prepare dpp archive
+        SparkRepository.SparkArchive archive = resource.prepareArchive();
+        Preconditions.checkNotNull(archive);
+        List<SparkRepository.SparkLibrary> libraries = archive.libraries;
+        Optional<SparkRepository.SparkLibrary> dppLibrary = libraries.stream().
+                filter(library -> library.libType == 
SparkRepository.SparkLibrary.LibType.DPP).findFirst();
+        Optional<SparkRepository.SparkLibrary> spark2xLibrary = 
libraries.stream().
+                filter(library -> library.libType == 
SparkRepository.SparkLibrary.LibType.SPARK2X).findFirst();
+        if (!dppLibrary.isPresent() || !spark2xLibrary.isPresent()) {
+            throw new LoadException("failed to get library from remote 
archive");
+        }
+
+        // spark home
+        String sparkHome = Config.spark_home_default_dir;
+        // etl config path
         String configsHdfsDir = etlJobConfig.outputPath + "/" + JOB_CONFIG_DIR 
+ "/";
-        String appResourceHdfsPath = configsHdfsDir + APP_RESOURCE_NAME;
+        // etl config json path
         String jobConfigHdfsPath = configsHdfsDir + CONFIG_FILE_NAME;
+        // spark submit app resource path
+        String appResourceHdfsPath = dppLibrary.get().remotePath;
+        // spark yarn archive path
+        String jobArchiveHdfsPath = spark2xLibrary.get().remotePath;
+        // spark yarn stage dir
+        String jobStageHdfsPath = resource.getWorkingDir();
+
+        // update archive and stage configs here
+        Map<String, String> sparkConfigs = resource.getSparkConfigs();
+        if (Strings.isNullOrEmpty(sparkConfigs.get("spark.yarn.archive"))) {

Review comment:
       In what situation, the `spark.yarn.archive` config will NOT be empty?

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkRepository.java
##########
@@ -0,0 +1,347 @@
+// 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.common.Config;
+import org.apache.doris.common.LoadException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.BrokerUtil;
+import org.apache.doris.thrift.TBrokerFileStatus;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+
+/*
+ * SparkRepository represents the remote repository for spark archives 
uploaded by spark
+ * The organization in repository is:
+ *
+ * * __spark_repository__/
+ *   * __archive_1_0_0/
+ *     * __lib_990325d2c0d1d5e45bf675e54e44fb16_spark-dpp.jar
+ *     * __lib_7670c29daf535efe3c9b923f778f61fc_spark-2x.zip
+ *   * __archive_2_2_0/
+ *     * __lib_64d5696f99c379af2bee28c1c84271d5_spark-dpp.jar
+ *     * __lib_1bbb74bb6b264a270bc7fca3e964160f_spark-2x.zip
+ *   * __archive_3_2_0/
+ *     * ...
+ */
+public class SparkRepository {
+    private static final Logger LOG = 
LogManager.getLogger(SparkRepository.class);
+
+    public static final String REPOSITORY_DIR = "__spark_repository__";
+    public static final String PREFIX_ARCHIVE = "__archive_";
+    public static final String PREFIX_LIB = "__lib_";
+    public static final String SPARK_DPP = "spark-dpp";
+    public static final String SPARK_2X = "spark-2x";
+    public static final String SUFFIX = ".zip";
+
+    private static final String PATH_DELIMITER = "/";
+    private static final String FILE_NAME_SEPARATOR = "_";
+
+    private static final String DPP_RESOURCE = "/spark-dpp/spark-dpp.jar";
+    private static final String SPARK_RESOURCE = "/jars/spark-2x.zip";
+
+    private String remoteRepositoryPath;
+    private BrokerDesc brokerDesc;
+    private String localDppPath;
+    private String localSpark2xPath;
+
+    // Version of the spark dpp program in this cluster
+    private String currentDppVersion;
+    // Archive that current dpp version pointed to
+    private SparkArchive currentArchive;
+
+    private boolean isInit;
+
+    public SparkRepository(String remoteRepositoryPath, BrokerDesc brokerDesc) 
{
+        this.remoteRepositoryPath = remoteRepositoryPath;
+        this.brokerDesc = brokerDesc;
+        this.currentDppVersion = Config.spark_dpp_version;
+        this.currentArchive = new 
SparkArchive(getRemoteArchivePath(currentDppVersion), currentDppVersion);
+        this.localDppPath = PaloFe.DORIS_HOME_DIR + DPP_RESOURCE;
+        if (!Strings.isNullOrEmpty(Config.spark_resource_path)) {
+            this.localSpark2xPath = Config.spark_resource_path;
+        } else {
+            this.localSpark2xPath = Config.spark_home_default_dir + 
SPARK_RESOURCE;
+        }
+        this.isInit = false;
+    }
+
+    public boolean prepare() throws LoadException {

Review comment:
       This method can be `public void`, and if error happens, just throw 
exception

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkEtlJobHandler.java
##########
@@ -92,12 +90,41 @@ public void submitEtlJob(long loadJobId, String loadLabel, 
EtlJobConfig etlJobCo
         // delete outputPath
         deleteEtlOutputPath(etlJobConfig.outputPath, brokerDesc);
 
-        // upload app resource and jobconfig to hdfs
+        // prepare dpp archive
+        SparkRepository.SparkArchive archive = resource.prepareArchive();
+        Preconditions.checkNotNull(archive);
+        List<SparkRepository.SparkLibrary> libraries = archive.libraries;
+        Optional<SparkRepository.SparkLibrary> dppLibrary = libraries.stream().
+                filter(library -> library.libType == 
SparkRepository.SparkLibrary.LibType.DPP).findFirst();
+        Optional<SparkRepository.SparkLibrary> spark2xLibrary = 
libraries.stream().
+                filter(library -> library.libType == 
SparkRepository.SparkLibrary.LibType.SPARK2X).findFirst();
+        if (!dppLibrary.isPresent() || !spark2xLibrary.isPresent()) {

Review comment:
       These checks can be put into the `resource.prepareArchive()` to make the 
caller logic more simple.
   `prepareArchive()` only return the right results, or exception will be 
thrown.

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkEtlJobHandler.java
##########
@@ -114,7 +141,9 @@ public void submitEtlJob(long loadJobId, String loadLabel, 
EtlJobConfig etlJobCo
                 .setAppResource(appResourceHdfsPath)
                 .setMainClass(SparkEtlJob.class.getCanonicalName())
                 .setAppName(String.format(ETL_JOB_NAME, loadLabel))
+                .setSparkHome(sparkHome)

Review comment:
       Why need to set spark home here?
   Is it compatible with open source spark env?




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