smallzhongfeng commented on code in PR #1366:
URL: 
https://github.com/apache/incubator-uniffle/pull/1366#discussion_r1430035668


##########
client-flink/common/src/main/java/org/apache/uniffle/shuffle/RssShuffleMaster.java:
##########
@@ -0,0 +1,352 @@
+/*
+ * 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.uniffle.shuffle;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.runtime.shuffle.JobShuffleContext;
+import org.apache.flink.runtime.shuffle.PartitionDescriptor;
+import org.apache.flink.runtime.shuffle.ProducerDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleDescriptor;
+import org.apache.flink.runtime.shuffle.ShuffleEnvironment;
+import org.apache.flink.runtime.shuffle.ShuffleMaster;
+import org.apache.flink.runtime.shuffle.ShuffleMasterContext;
+import org.apache.flink.runtime.shuffle.TaskInputsOutputsDescriptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.uniffle.client.api.ShuffleWriteClient;
+import org.apache.uniffle.client.util.ClientUtils;
+import org.apache.uniffle.common.PartitionRange;
+import org.apache.uniffle.common.RemoteStorageInfo;
+import org.apache.uniffle.common.ShuffleAssignmentsInfo;
+import org.apache.uniffle.common.ShuffleDataDistributionType;
+import org.apache.uniffle.common.ShuffleServerInfo;
+import org.apache.uniffle.common.config.RssClientConf;
+import org.apache.uniffle.common.exception.RssException;
+import org.apache.uniffle.common.util.RetryUtils;
+import org.apache.uniffle.common.util.ThreadUtils;
+import org.apache.uniffle.shuffle.exception.ShuffleException;
+import org.apache.uniffle.shuffle.resource.DefaultRssShuffleResource;
+import org.apache.uniffle.shuffle.resource.RssShuffleResourceDescriptor;
+import org.apache.uniffle.shuffle.utils.FlinkShuffleUtils;
+
+import static org.apache.uniffle.shuffle.RssFlinkConfig.*;
+import static 
org.apache.uniffle.shuffle.utils.FlinkShuffleUtils.getShuffleDataDistributionType;
+
+public class RssShuffleMaster implements ShuffleMaster<RssShuffleDescriptor> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(RssShuffleMaster.class);
+
+  //
+  private final ShuffleMasterContext shuffleMasterContext;
+  private final RssFlinkApplication rssFlinkApplication;
+
+  //
+  protected ShuffleWriteClient shuffleWriteClient;
+
+  //
+  private boolean heartbeatStarted = false;
+  private final ScheduledExecutorService heartBeatScheduledExecutorService;
+
+  //
+  private final ScheduledExecutorService executorService;
+
+  private final Configuration config;
+
+  public RssShuffleMaster(ShuffleMasterContext shuffleMasterContext) {
+    this.shuffleMasterContext = shuffleMasterContext;
+    this.config = shuffleMasterContext.getConfiguration();
+    this.rssFlinkApplication = new RssFlinkApplication();
+    this.heartBeatScheduledExecutorService =
+        
ThreadUtils.getDaemonSingleThreadScheduledExecutor("uniffle-rss-heartbeat");
+    this.executorService =
+        
ThreadUtils.getDaemonSingleThreadScheduledExecutor("uniffle-shuffle-master-executor");
+  }
+
+  protected void registerCoordinator(Configuration config) {
+    String coordinators = 
config.getString(RssFlinkConfig.RSS_COORDINATOR_QUORM);
+    LOG.info("Start Registering Coordinator {}.", coordinators);
+    shuffleWriteClient.registerCoordinators(coordinators);
+  }
+
+  @Override
+  public void close() throws Exception {
+    if (heartBeatScheduledExecutorService != null) {
+      heartBeatScheduledExecutorService.shutdownNow();
+    }
+    if (executorService != null) {
+      executorService.shutdownNow();
+    }
+    if (shuffleWriteClient != null) {
+      shuffleWriteClient.close();
+    }
+  }
+
+  /**
+   * Registers the target job together with the corresponding {@link 
JobShuffleContext} to this
+   * shuffle master. Through the shuffle context, one can obtain some basic 
information like job ID,
+   * job configuration. It enables ShuffleMaster to notify JobMaster about 
lost result partitions,
+   * so that JobMaster can identify and reproduce unavailable partitions 
earlier.
+   *
+   * @param context the corresponding shuffle context of the target job.
+   */
+  @Override
+  public void registerJob(JobShuffleContext context) {
+    JobID jobID = context.getJobId();
+    if (shuffleWriteClient == null) {
+      synchronized (RssShuffleMaster.class) {

Review Comment:
   If it is a class object here, it may be heavier. Is the object 
RssShuffleMaster itself enough?



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

Reply via email to