morningman commented on a change in pull request #3715: URL: https://github.com/apache/incubator-doris/pull/3715#discussion_r432798579
########## File path: fe/src/main/java/org/apache/doris/common/Config.java ########## @@ -491,6 +491,12 @@ @ConfField(mutable = true, masterOnly = true) public static int hadoop_load_default_timeout_second = 86400 * 3; // 3 day + /* + * Default spark load timeout + */ + @ConfField(mutable = true, masterOnly = true) + public static int spark_load_default_timeout_second = 86400 * 3; // 3 days Review comment: I think 1 day is long enough~ ########## File path: fe/src/main/java/org/apache/doris/load/loadv2/SparkLoadJob.java ########## @@ -0,0 +1,249 @@ +// 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 com.google.common.base.Strings; +import org.apache.doris.analysis.BrokerDesc; +import org.apache.doris.analysis.ResourceDesc; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Resource; +import org.apache.doris.catalog.SparkResource; +import org.apache.doris.common.Config; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.MetaNotFoundException; +import org.apache.doris.common.Pair; +import org.apache.doris.common.io.Text; +import org.apache.doris.load.EtlJobType; +import org.apache.doris.load.FailMsg; +import org.apache.doris.qe.OriginStatement; +import org.apache.doris.task.AgentTaskQueue; +import org.apache.doris.task.PushTask; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.spark.launcher.SparkAppHandle; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; +import java.util.Set; + +/** + * There are 4 steps in SparkLoadJob: + * Step1: SparkLoadPendingTask will be created by unprotectedExecuteJob method and submit spark etl job. + * Step2: LoadEtlChecker will check spark etl job status periodly and send push tasks to be when spark etl job is finished. + * Step3: LoadLoadingChecker will check loading status periodly and commit transaction when push tasks are finished. + * Step4: PublishVersionDaemon will send publish version tasks to be and finish transaction. + */ +public class SparkLoadJob extends BulkLoadJob { + private static final Logger LOG = LogManager.getLogger(SparkLoadJob.class); + + // for global dict + public static final String BITMAP_DATA_PROPERTY = "bitmap_data"; Review comment: this property is hard to understand and is coupled with the detail implementation of the global dict. How about changing it to a more abstract nouns? ########## File path: fe/src/main/java/org/apache/doris/load/loadv2/BulkLoadJob.java ########## @@ -0,0 +1,328 @@ +// 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.analysis.SqlParser; +import org.apache.doris.analysis.SqlScanner; +import org.apache.doris.catalog.AuthorizationInfo; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Table; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.FeMetaVersion; +import org.apache.doris.common.MetaNotFoundException; +import org.apache.doris.common.io.Text; +import org.apache.doris.common.util.LogBuilder; +import org.apache.doris.common.util.LogKey; +import org.apache.doris.common.util.SqlParserUtils; +import org.apache.doris.load.BrokerFileGroup; +import org.apache.doris.load.BrokerFileGroupAggInfo; +import org.apache.doris.load.FailMsg; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.OriginStatement; +import org.apache.doris.qe.SessionVariable; +import org.apache.doris.qe.SqlModeHelper; +import org.apache.doris.transaction.TabletCommitInfo; +import org.apache.doris.transaction.TransactionState; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.StringReader; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * parent class of BrokerLoadJob and SparkLoadJob from load stmt + */ +public abstract class BulkLoadJob extends LoadJob { + private static final Logger LOG = LogManager.getLogger(BulkLoadJob.class); + + // input params + protected BrokerDesc brokerDesc; Review comment: I think `brokerDesc` should be in the subclass of `BulkLoadJob`. Although currently both broker load and spark load need a broker, but for spark load, it may not be required in future. ########## File path: fe/src/main/java/org/apache/doris/load/loadv2/SparkLoadJob.java ########## @@ -0,0 +1,249 @@ +// 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 com.google.common.base.Strings; +import org.apache.doris.analysis.BrokerDesc; +import org.apache.doris.analysis.ResourceDesc; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Resource; +import org.apache.doris.catalog.SparkResource; +import org.apache.doris.common.Config; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.MetaNotFoundException; +import org.apache.doris.common.Pair; +import org.apache.doris.common.io.Text; +import org.apache.doris.load.EtlJobType; +import org.apache.doris.load.FailMsg; +import org.apache.doris.qe.OriginStatement; +import org.apache.doris.task.AgentTaskQueue; +import org.apache.doris.task.PushTask; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.spark.launcher.SparkAppHandle; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; +import java.util.Set; + +/** + * There are 4 steps in SparkLoadJob: + * Step1: SparkLoadPendingTask will be created by unprotectedExecuteJob method and submit spark etl job. + * Step2: LoadEtlChecker will check spark etl job status periodly and send push tasks to be when spark etl job is finished. + * Step3: LoadLoadingChecker will check loading status periodly and commit transaction when push tasks are finished. + * Step4: PublishVersionDaemon will send publish version tasks to be and finish transaction. + */ +public class SparkLoadJob extends BulkLoadJob { + private static final Logger LOG = LogManager.getLogger(SparkLoadJob.class); + + // for global dict + public static final String BITMAP_DATA_PROPERTY = "bitmap_data"; + + // --- members below need persist --- + // create from resourceDesc when job created + private SparkResource sparkResource; + // members below updated when job state changed to etl + private long etlStartTimestamp = -1; + // for spark yarn + private String appId = ""; + // spark job outputPath + private String etlOutputPath = ""; + // members below updated when job state changed to loading + // { tableId.partitionId.indexId.bucket.schemaHash -> (etlFilePath, etlFileSize) } + private Map<String, Pair<String, Long>> tabletMetaToFileInfo = Maps.newHashMap(); + + // --- members below not persist --- + // temporary use + // one SparkLoadJob has only one table to load + // hivedb.table for global dict + private String hiveTableName = ""; + private ResourceDesc resourceDesc; + // for spark standalone + private SparkAppHandle sparkAppHandle; + // for straggler wait long time to commit transaction + private long quorumFinishTimestamp = -1; + // below for push task + private Map<Long, Set<Long>> tableToLoadPartitions = Maps.newHashMap(); + //private Map<Long, PushBrokerScannerParams> indexToPushBrokerReaderParams = Maps.newHashMap(); + private Map<Long, Integer> indexToSchemaHash = Maps.newHashMap(); + private Map<Long, Map<Long, PushTask>> tabletToSentReplicaPushTask = Maps.newHashMap(); + private Set<Long> finishedReplicas = Sets.newHashSet(); + private Set<Long> quorumTablets = Sets.newHashSet(); + private Set<Long> fullTablets = Sets.newHashSet(); + + // only for log replay + public SparkLoadJob() { + super(); + jobType = EtlJobType.SPARK; + } + + public SparkLoadJob(long dbId, String label, ResourceDesc resourceDesc, OriginStatement originStmt) + throws MetaNotFoundException { + super(dbId, label, originStmt); + this.resourceDesc = resourceDesc; + timeoutSecond = Config.spark_load_default_timeout_second; + jobType = EtlJobType.SPARK; + } + + public String getHiveTableName() { + return hiveTableName; + } + + @Override + protected void setJobProperties(Map<String, String> properties) throws DdlException { + super.setJobProperties(properties); + + // set spark resource and broker desc + setResourceInfo(); + + // global dict + if (properties != null) { + if (properties.containsKey(BITMAP_DATA_PROPERTY)) { + hiveTableName = properties.get(BITMAP_DATA_PROPERTY); + } + } + } + + /** + * merge system conf with load stmt + * @throws DdlException + */ + private void setResourceInfo() throws DdlException { + // spark resource + String resourceName = resourceDesc.getName(); + Resource oriResource = Catalog.getCurrentCatalog().getResourceMgr().getResource(resourceName); + if (oriResource == null) { + throw new DdlException("Resource does not exist. name: " + resourceName); + } + Preconditions.checkState(oriResource instanceof SparkResource); Review comment: Why using `Preconditions` here? It may be some other kind of resource. ########## File path: fe/src/main/java/org/apache/doris/load/loadv2/SparkLoadJob.java ########## @@ -0,0 +1,249 @@ +// 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 com.google.common.base.Strings; +import org.apache.doris.analysis.BrokerDesc; +import org.apache.doris.analysis.ResourceDesc; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Resource; +import org.apache.doris.catalog.SparkResource; +import org.apache.doris.common.Config; +import org.apache.doris.common.DdlException; +import org.apache.doris.common.MetaNotFoundException; +import org.apache.doris.common.Pair; +import org.apache.doris.common.io.Text; +import org.apache.doris.load.EtlJobType; +import org.apache.doris.load.FailMsg; +import org.apache.doris.qe.OriginStatement; +import org.apache.doris.task.AgentTaskQueue; +import org.apache.doris.task.PushTask; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.spark.launcher.SparkAppHandle; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Map; +import java.util.Set; + +/** + * There are 4 steps in SparkLoadJob: + * Step1: SparkLoadPendingTask will be created by unprotectedExecuteJob method and submit spark etl job. + * Step2: LoadEtlChecker will check spark etl job status periodly and send push tasks to be when spark etl job is finished. + * Step3: LoadLoadingChecker will check loading status periodly and commit transaction when push tasks are finished. + * Step4: PublishVersionDaemon will send publish version tasks to be and finish transaction. + */ +public class SparkLoadJob extends BulkLoadJob { + private static final Logger LOG = LogManager.getLogger(SparkLoadJob.class); + + // for global dict + public static final String BITMAP_DATA_PROPERTY = "bitmap_data"; + + // --- members below need persist --- + // create from resourceDesc when job created + private SparkResource sparkResource; + // members below updated when job state changed to etl + private long etlStartTimestamp = -1; + // for spark yarn + private String appId = ""; + // spark job outputPath + private String etlOutputPath = ""; + // members below updated when job state changed to loading + // { tableId.partitionId.indexId.bucket.schemaHash -> (etlFilePath, etlFileSize) } + private Map<String, Pair<String, Long>> tabletMetaToFileInfo = Maps.newHashMap(); + + // --- members below not persist --- + // temporary use + // one SparkLoadJob has only one table to load + // hivedb.table for global dict + private String hiveTableName = ""; + private ResourceDesc resourceDesc; + // for spark standalone + private SparkAppHandle sparkAppHandle; + // for straggler wait long time to commit transaction + private long quorumFinishTimestamp = -1; + // below for push task + private Map<Long, Set<Long>> tableToLoadPartitions = Maps.newHashMap(); + //private Map<Long, PushBrokerScannerParams> indexToPushBrokerReaderParams = Maps.newHashMap(); + private Map<Long, Integer> indexToSchemaHash = Maps.newHashMap(); + private Map<Long, Map<Long, PushTask>> tabletToSentReplicaPushTask = Maps.newHashMap(); + private Set<Long> finishedReplicas = Sets.newHashSet(); + private Set<Long> quorumTablets = Sets.newHashSet(); + private Set<Long> fullTablets = Sets.newHashSet(); + + // only for log replay + public SparkLoadJob() { + super(); + jobType = EtlJobType.SPARK; + } + + public SparkLoadJob(long dbId, String label, ResourceDesc resourceDesc, OriginStatement originStmt) + throws MetaNotFoundException { + super(dbId, label, originStmt); + this.resourceDesc = resourceDesc; + timeoutSecond = Config.spark_load_default_timeout_second; + jobType = EtlJobType.SPARK; + } + + public String getHiveTableName() { + return hiveTableName; + } + + @Override + protected void setJobProperties(Map<String, String> properties) throws DdlException { + super.setJobProperties(properties); + + // set spark resource and broker desc + setResourceInfo(); + + // global dict + if (properties != null) { + if (properties.containsKey(BITMAP_DATA_PROPERTY)) { + hiveTableName = properties.get(BITMAP_DATA_PROPERTY); + } + } + } + + /** + * merge system conf with load stmt + * @throws DdlException + */ + private void setResourceInfo() throws DdlException { + // spark resource + String resourceName = resourceDesc.getName(); + Resource oriResource = Catalog.getCurrentCatalog().getResourceMgr().getResource(resourceName); + if (oriResource == null) { + throw new DdlException("Resource does not exist. name: " + resourceName); + } + Preconditions.checkState(oriResource instanceof SparkResource); + sparkResource = ((SparkResource) oriResource).getCopiedResource(); + sparkResource.update(resourceDesc); + + // broker desc + Map<String, String> brokerProperties = sparkResource.getBrokerPropertiesWithoutPrefix(); + brokerDesc = new BrokerDesc(sparkResource.getBroker(), brokerProperties); + } + + /** + * load job already cancelled or finished, clear job below: + * 1. kill etl job and delete etl files + * 2. clear push tasks and infos that not persist + */ + private void clearJob() { + Preconditions.checkState(state == JobState.FINISHED || state == JobState.CANCELLED); + + LOG.debug("kill etl job and delete etl files. id: {}, state: {}", id, state); + // TODO(wyb): spark-load + //SparkEtlJobHandler handler = new SparkEtlJobHandler(); + if (state == JobState.CANCELLED) { + if ((!Strings.isNullOrEmpty(appId) && sparkResource.isYarnMaster()) || sparkAppHandle != null) { + try { + // TODO(wyb): spark-load + //handler.killEtlJob(sparkAppHandle, appId, id, sparkResource); + } catch (Exception e) { + LOG.warn("kill etl job failed. id: {}, state: {}", id, state, e); Review comment: Save the error msg somewhere for user to get? ---------------------------------------------------------------- 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