FMX commented on code in PR #1830: URL: https://github.com/apache/incubator-celeborn/pull/1830#discussion_r1312479821
########## client-mr/mr/src/main/java/org/apache/hadoop/mapreduce/task/reduce/CelebornShuffleConsumer.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.hadoop.mapreduce.task.reduce; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.hadoop.mapred.*; +import org.apache.hadoop.mapreduce.task.reduce.Shuffle.ShuffleError; +import org.apache.hadoop.util.Progress; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.celeborn.client.ShuffleClient; +import org.apache.celeborn.client.read.CelebornInputStream; +import org.apache.celeborn.common.CelebornConf; +import org.apache.celeborn.common.identity.UserIdentifier; +import org.apache.celeborn.util.HadoopUtils; + +public class CelebornShuffleConsumer<K, V> + implements ShuffleConsumerPlugin<K, V>, ExceptionReporter { + private static final Logger logger = LoggerFactory.getLogger(CelebornShuffleConsumer.class); + private JobConf mrJobConf; + private MergeManager<K, V> merger; + private Throwable throwable = null; + private Progress copyPhase; + private TaskStatus taskStatus; + private org.apache.hadoop.mapreduce.TaskAttemptID reduceId; + private TaskUmbilicalProtocol umbilical; + private Reporter reporter; + private ShuffleClientMetrics metrics; + private Task reduceTask; + + private ShuffleClient shuffleClient; + + @Override + public void init(Context<K, V> context) { + + reduceId = context.getReduceId(); + mrJobConf = context.getJobConf(); + JobConf celebornJobConf = new JobConf(HadoopUtils.MR_CELEBORN_CONF); + + umbilical = context.getUmbilical(); + reporter = context.getReporter(); + try { + this.metrics = createMetrics(reduceId, mrJobConf); + } catch (Exception e) { + logger.error("Fatal error occurred, failed to get shuffle client metrics.", e); + reportException(e); + } + copyPhase = context.getCopyPhase(); + taskStatus = context.getStatus(); + reduceTask = context.getReduceTask(); + + String appId = celebornJobConf.get(HadoopUtils.MR_CELEBORN_APPLICATION_ID); + String lcHost = celebornJobConf.get(HadoopUtils.MR_CELEBORN_LC_HOST); + int lcPort = Integer.parseInt(celebornJobConf.get(HadoopUtils.MR_CELEBORN_LC_PORT)); + logger.info("Reducer initialized with celeborn {} {} {}", appId, lcHost, lcPort); + CelebornConf celebornConf = HadoopUtils.fromYarnConf(mrJobConf); + shuffleClient = + ShuffleClient.get( + appId, + lcHost, + lcPort, + celebornConf, + new UserIdentifier( + celebornConf.quotaUserSpecificTenant(), celebornConf.quotaUserSpecificUserName())); + this.merger = createMergeManager(context); + } + + // Merge mapOutput and spill in local disks if necessary + protected MergeManager<K, V> createMergeManager(ShuffleConsumerPlugin.Context context) { + return new MergeManagerImpl<K, V>( + reduceId, + mrJobConf, + context.getLocalFS(), + context.getLocalDirAllocator(), + reporter, + context.getCodec(), + context.getCombinerClass(), + context.getCombineCollector(), + context.getSpilledRecordsCounter(), + context.getReduceCombineInputCounter(), + context.getMergedMapOutputsCounter(), + this, + context.getMergePhase(), + context.getMapOutputFile()); + } + + private ShuffleClientMetrics createMetrics( + org.apache.hadoop.mapreduce.TaskAttemptID taskAttemptID, JobConf jobConf) + throws NoSuchMethodException, InvocationTargetException, InstantiationException, + IllegalAccessException { + // for hadoop 3 Review Comment: Sounds good to me. I'll try it. -- 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]
