xy720 commented on a change in pull request #4163: URL: https://github.com/apache/incubator-doris/pull/4163#discussion_r460087064
########## File path: fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkRepository.java ########## @@ -0,0 +1,379 @@ +// 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.FeConstants; +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; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/* + * 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 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 ReentrantReadWriteLock rwLock; + private boolean isInit; + + public SparkRepository(String remoteRepositoryPath, BrokerDesc brokerDesc) { + this.remoteRepositoryPath = remoteRepositoryPath; + this.brokerDesc = brokerDesc; + this.currentDppVersion = FeConstants.spark_dpp_version; + currentArchive = new SparkArchive(getRemoteArchivePath(currentDppVersion), currentDppVersion); + this.rwLock = new ReentrantReadWriteLock(); + this.isInit = false; + this.localDppPath = PaloFe.DORIS_HOME_DIR + "/spark-dpp/spark-dpp.jar"; + if (!Strings.isNullOrEmpty(Config.spark_resource_path)) { + this.localSpark2xPath = Config.spark_resource_path; + } else { + this.localSpark2xPath = Config.spark_home_default_dir + "/jars/spark-2x.zip"; + } + } + + public boolean prepare() throws LoadException { + if (!isInit) { + initRepository(); + } + return isInit; + } + + private void initRepository() throws LoadException { + LOG.info("start to init remote repository"); Review comment: Added a synchronized lock in SparkEtlHandler for cluster id. Now initRepository operations are blocked if they are in same cluster ---------------------------------------------------------------- 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