jerqi commented on code in PR #918: URL: https://github.com/apache/incubator-uniffle/pull/918#discussion_r1213054543
########## client-tez/src/main/java/org/apache/tez/dag/app/RssDAGAppMaster.java: ########## @@ -0,0 +1,360 @@ +/* + * 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.tez.dag.app; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.mapreduce.JobSubmissionFiles; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.ShutdownHookManager; +import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; +import org.apache.hadoop.yarn.api.ApplicationConstants; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.LocalResource; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.util.Clock; +import org.apache.hadoop.yarn.util.ConverterUtils; +import org.apache.hadoop.yarn.util.SystemClock; +import org.apache.tez.common.RssTezConfig; +import org.apache.tez.common.RssTezUtils; +import org.apache.tez.common.TezClassLoader; +import org.apache.tez.common.TezCommonUtils; +import org.apache.tez.common.TezUtilsInternal; +import org.apache.tez.common.VersionInfo; +import org.apache.tez.dag.api.TezConfiguration; +import org.apache.tez.dag.api.TezConstants; +import org.apache.tez.dag.api.TezException; +import org.apache.tez.dag.api.records.DAGProtos; +import org.apache.tez.dag.api.records.DAGProtos.AMPluginDescriptorProto; +import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.uniffle.client.api.ShuffleWriteClient; + +import static org.apache.tez.common.TezCommonUtils.TEZ_SYSTEM_SUB_DIR; + +public class RssDAGAppMaster extends DAGAppMaster { + private static final Logger LOG = LoggerFactory.getLogger(RssDAGAppMaster.class); + private ShuffleWriteClient shuffleWriteClient; + private TezRemoteShuffleManager tezRemoteShuffleManager; + private static final String rssConfFileLocalResourceName = "rss_conf.xml"; + private DAGProtos.PlanLocalResource rssConfFileLocalResource; + final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor( Review Comment: Could we reuse ThreadUtils? ########## client-tez/src/main/java/org/apache/tez/dag/app/RssDAGAppMaster.java: ########## @@ -0,0 +1,360 @@ +/* + * 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.tez.dag.app; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.mapreduce.JobSubmissionFiles; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.ShutdownHookManager; +import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; +import org.apache.hadoop.yarn.api.ApplicationConstants; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.LocalResource; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.util.Clock; +import org.apache.hadoop.yarn.util.ConverterUtils; +import org.apache.hadoop.yarn.util.SystemClock; +import org.apache.tez.common.RssTezConfig; +import org.apache.tez.common.RssTezUtils; +import org.apache.tez.common.TezClassLoader; +import org.apache.tez.common.TezCommonUtils; +import org.apache.tez.common.TezUtilsInternal; +import org.apache.tez.common.VersionInfo; +import org.apache.tez.dag.api.TezConfiguration; +import org.apache.tez.dag.api.TezConstants; +import org.apache.tez.dag.api.TezException; +import org.apache.tez.dag.api.records.DAGProtos; +import org.apache.tez.dag.api.records.DAGProtos.AMPluginDescriptorProto; +import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.uniffle.client.api.ShuffleWriteClient; + +import static org.apache.tez.common.TezCommonUtils.TEZ_SYSTEM_SUB_DIR; + +public class RssDAGAppMaster extends DAGAppMaster { + private static final Logger LOG = LoggerFactory.getLogger(RssDAGAppMaster.class); + private ShuffleWriteClient shuffleWriteClient; + private TezRemoteShuffleManager tezRemoteShuffleManager; + private static final String rssConfFileLocalResourceName = "rss_conf.xml"; + private DAGProtos.PlanLocalResource rssConfFileLocalResource; + final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor( + new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = Executors.defaultThreadFactory().newThread(r); + t.setDaemon(true); + return t; + } + } + ); + + public RssDAGAppMaster(ApplicationAttemptId applicationAttemptId, ContainerId containerId, + String nmHost, int nmPort, int nmHttpPort, Clock clock, long appSubmitTime, boolean isSession, + String workingDirectory, String [] localDirs, String[] logDirs, String clientVersion, + Credentials credentials, String jobUserName, AMPluginDescriptorProto pluginDescriptorProto) { + super(applicationAttemptId, containerId, nmHost, nmPort, nmHttpPort, clock, appSubmitTime, isSession, + workingDirectory, localDirs, logDirs, clientVersion, credentials, jobUserName, pluginDescriptorProto); + } + + public ShuffleWriteClient getShuffleWriteClient() { + return shuffleWriteClient; + } + + public void setShuffleWriteClient(ShuffleWriteClient shuffleWriteClient) { + this.shuffleWriteClient = shuffleWriteClient; + } + + public TezRemoteShuffleManager getTezRemoteShuffleManager() { + return tezRemoteShuffleManager; + } + + public void setTezRemoteShuffleManager(TezRemoteShuffleManager tezRemoteShuffleManager) { + this.tezRemoteShuffleManager = tezRemoteShuffleManager; + } + + /** + * Init and Start Rss Client + * @param appMaster + * @param conf + * @param applicationAttemptId + * @throws Exception + */ + public static void initAndStartRSSClient(final RssDAGAppMaster appMaster, Configuration conf, + ApplicationAttemptId applicationAttemptId) throws Exception { + + ShuffleWriteClient client = RssTezUtils.createShuffleClient(conf); + appMaster.setShuffleWriteClient(client); + + String coordinators = conf.get(RssTezConfig.RSS_COORDINATOR_QUORUM); + LOG.info("Registering coordinators {}", coordinators); + client.registerCoordinators(coordinators); + + String strAppAttemptId = applicationAttemptId.toString(); + long heartbeatInterval = conf.getLong(RssTezConfig.RSS_HEARTBEAT_INTERVAL, + RssTezConfig.RSS_HEARTBEAT_INTERVAL_DEFAULT_VALUE); + long heartbeatTimeout = conf.getLong(RssTezConfig.RSS_HEARTBEAT_TIMEOUT, heartbeatInterval / 2); + client.registerApplicationInfo(strAppAttemptId, heartbeatTimeout, "user"); + + appMaster.scheduledExecutorService.scheduleAtFixedRate( + () -> { + try { + client.sendAppHeartbeat(strAppAttemptId, heartbeatTimeout); + LOG.debug("Finish send heartbeat to coordinator and servers"); + } catch (Exception e) { + LOG.warn("Fail to send heartbeat to coordinator and servers", e); + } + }, + heartbeatInterval / 2, + heartbeatInterval, + TimeUnit.MILLISECONDS); + + appMaster.setTezRemoteShuffleManager(new TezRemoteShuffleManager(strAppAttemptId, null, conf, + strAppAttemptId, client)); + appMaster.getTezRemoteShuffleManager().initialize(); + appMaster.getTezRemoteShuffleManager().start(); + + TezConfiguration extraConf = new TezConfiguration(false); + extraConf.clear(); + + String strAppId = applicationAttemptId.getApplicationId().toString(); + extraConf.set(RssTezConfig.RSS_AM_SHUFFLE_MANAGER_ADDRESS, + appMaster.getTezRemoteShuffleManager().address.getHostName()); + extraConf.setInt(RssTezConfig.RSS_AM_SHUFFLE_MANAGER_PORT, + appMaster.getTezRemoteShuffleManager().address.getPort()); + writeExtraConf(appMaster, conf, extraConf, strAppId); + + mayCloseTezSlowStart(conf); + } + + @Override + public String submitDAGToAppMaster(DAGProtos.DAGPlan dagPlan, Map<String, LocalResource> additionalResources) Review Comment: Could we add some tests for this class? ########## client-tez/src/main/java/org/apache/tez/dag/app/RssDAGAppMaster.java: ########## @@ -0,0 +1,360 @@ +/* + * 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.tez.dag.app; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Options; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.mapreduce.JobSubmissionFiles; +import org.apache.hadoop.security.Credentials; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.ShutdownHookManager; +import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; +import org.apache.hadoop.yarn.api.ApplicationConstants; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.LocalResource; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.util.Clock; +import org.apache.hadoop.yarn.util.ConverterUtils; +import org.apache.hadoop.yarn.util.SystemClock; +import org.apache.tez.common.RssTezConfig; +import org.apache.tez.common.RssTezUtils; +import org.apache.tez.common.TezClassLoader; +import org.apache.tez.common.TezCommonUtils; +import org.apache.tez.common.TezUtilsInternal; +import org.apache.tez.common.VersionInfo; +import org.apache.tez.dag.api.TezConfiguration; +import org.apache.tez.dag.api.TezConstants; +import org.apache.tez.dag.api.TezException; +import org.apache.tez.dag.api.records.DAGProtos; +import org.apache.tez.dag.api.records.DAGProtos.AMPluginDescriptorProto; +import org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.uniffle.client.api.ShuffleWriteClient; + +import static org.apache.tez.common.TezCommonUtils.TEZ_SYSTEM_SUB_DIR; + +public class RssDAGAppMaster extends DAGAppMaster { + private static final Logger LOG = LoggerFactory.getLogger(RssDAGAppMaster.class); + private ShuffleWriteClient shuffleWriteClient; + private TezRemoteShuffleManager tezRemoteShuffleManager; + private static final String rssConfFileLocalResourceName = "rss_conf.xml"; + private DAGProtos.PlanLocalResource rssConfFileLocalResource; + final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor( + new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = Executors.defaultThreadFactory().newThread(r); + t.setDaemon(true); + return t; + } + } + ); + + public RssDAGAppMaster(ApplicationAttemptId applicationAttemptId, ContainerId containerId, + String nmHost, int nmPort, int nmHttpPort, Clock clock, long appSubmitTime, boolean isSession, + String workingDirectory, String [] localDirs, String[] logDirs, String clientVersion, + Credentials credentials, String jobUserName, AMPluginDescriptorProto pluginDescriptorProto) { + super(applicationAttemptId, containerId, nmHost, nmPort, nmHttpPort, clock, appSubmitTime, isSession, + workingDirectory, localDirs, logDirs, clientVersion, credentials, jobUserName, pluginDescriptorProto); + } + + public ShuffleWriteClient getShuffleWriteClient() { + return shuffleWriteClient; + } + + public void setShuffleWriteClient(ShuffleWriteClient shuffleWriteClient) { + this.shuffleWriteClient = shuffleWriteClient; + } + + public TezRemoteShuffleManager getTezRemoteShuffleManager() { + return tezRemoteShuffleManager; + } + + public void setTezRemoteShuffleManager(TezRemoteShuffleManager tezRemoteShuffleManager) { + this.tezRemoteShuffleManager = tezRemoteShuffleManager; + } + + /** + * Init and Start Rss Client + * @param appMaster + * @param conf + * @param applicationAttemptId + * @throws Exception + */ + public static void initAndStartRSSClient(final RssDAGAppMaster appMaster, Configuration conf, Review Comment: For AppMaster, do we need consider similar case? https://github.com/apache/incubator-uniffle/blob/4979ca633d25c67cd1ca7067995fa373d0017c87/client-mr/hadoop2.8/src/main/java/org/apache/uniffle/hadoop/shim/HadoopShimImpl.java#LL50C3-L50C3 -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
