zentol commented on a change in pull request #11443: 
[FLINK-14791][coordination] ResourceManager tracks ClusterPartitions
URL: https://github.com/apache/flink/pull/11443#discussion_r400033791
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResourceManagerPartitionTrackerImpl.java
 ##########
 @@ -0,0 +1,232 @@
+/*
+ * 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.flink.runtime.io.network.partition;
+
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.jobgraph.IntermediateDataSetID;
+import org.apache.flink.runtime.taskexecutor.partition.ClusterPartitionReport;
+import org.apache.flink.util.Preconditions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+/**
+ * Default {@link ResourceManagerPartitionTracker} implementation.
+ *
+ * <p>Internal tracking info must only be updated upon reception of a {@link 
ClusterPartitionReport}, as the task
+ * executor state is the source of truth.
+ */
+public class ResourceManagerPartitionTrackerImpl implements 
ResourceManagerPartitionTracker {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(ResourceManagerPartitionTrackerImpl.class);
+
+       private final Map<ResourceID, Set<IntermediateDataSetID>> 
taskExecutorToDataSets = new HashMap<>();
+       private final Map<IntermediateDataSetID, Map<ResourceID, 
Set<ResultPartitionID>>> dataSetToTaskExecutors = new HashMap<>();
+       private final Map<IntermediateDataSetID, DataSetMetaInfo> 
dataSetMetaInfo = new HashMap<>();
+       private final Map<IntermediateDataSetID, CompletableFuture<Void>> 
partitionReleaseCompletionFutures = new HashMap<>();
+
+       private final ClusterPartitionReleaser clusterPartitionReleaser;
+
+       public ResourceManagerPartitionTrackerImpl(ClusterPartitionReleaser 
clusterPartitionReleaser) {
+               this.clusterPartitionReleaser = clusterPartitionReleaser;
+       }
+
+       @Override
+       public void processTaskExecutorClusterPartitionReport(ResourceID 
taskExecutorId, ClusterPartitionReport clusterPartitionReport) {
+               Preconditions.checkNotNull(taskExecutorId);
+               Preconditions.checkNotNull(clusterPartitionReport);
+               LOG.debug("Processing cluster partition report from task 
executor {}: {}.", taskExecutorId, clusterPartitionReport);
+
+               internalProcessClusterPartitionReport(taskExecutorId, 
clusterPartitionReport);
+       }
+
+       @Override
+       public void processTaskExecutorShutdown(ResourceID taskExecutorId) {
+               Preconditions.checkNotNull(taskExecutorId);
+               LOG.debug("Processing shutdown of task executor {}.", 
taskExecutorId);
+
+               internalProcessClusterPartitionReport(taskExecutorId, new 
ClusterPartitionReport(Collections.emptyList()));
+       }
+
+       @Override
+       public CompletableFuture<Void> 
releaseClusterPartitions(IntermediateDataSetID dataSetId) {
+               Preconditions.checkNotNull(dataSetId);
+               LOG.debug("Releasing cluster partitions for data set {}.", 
dataSetId);
+
+               CompletableFuture<Void> partitionReleaseCompletionFuture = 
partitionReleaseCompletionFutures.computeIfAbsent(dataSetId, ignored -> new 
CompletableFuture<>());
+               internalReleasePartitions(Collections.singleton(dataSetId));
 
 Review comment:
   I will add a check at the start of the method that the partition is being 
tracked. if it isn't we will log something and return a completed future.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to