zhijiangW commented on a change in pull request #8687: 
[FLINK-12612][coordination] Track stored partition on the TaskExecutor 
URL: https://github.com/apache/flink/pull/8687#discussion_r292778400
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/partition/PartitionTable.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * 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.taskexecutor.partition;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Thread-safe Utility for tracking partitions.
+ */
+public class PartitionTable {
+
+       private final Object lock = new Object();
+
+       private final Map<JobID, Set<ResultPartitionID>> 
trackedPartitionsPerJob = new HashMap<>(8);
+
+       boolean hasTrackedPartitions(JobID jobId) {
+               return trackedPartitionsPerJob.containsKey(jobId);
+       }
+
+       /**
+        * Tracks the given partition for the given attempt.
+        * These partitions are not considered finished.
+        *
+        * @param partitionId
+        */
+       void startTrackingPartition(JobID jobId, ResultPartitionID partitionId) 
{
+               Preconditions.checkNotNull(partitionId);
+
+               synchronized (lock) {
+                       trackedPartitionsPerJob.compute(jobId, (ignored, 
partitionIds) -> {
+                               if (partitionIds == null) {
+                                       partitionIds = new HashSet<>(8);
+                               }
+                               partitionIds.add(partitionId);
+                               return partitionIds;
+                       });
+               }
+       }
+
+       /**
+        * Stops the tracking of the given partition for the given attempt.
+        *
+        * @param partitionId
+        */
+       void stopTrackingPartition(JobID jobId, ResultPartitionID partitionId) {
+               Preconditions.checkNotNull(partitionId);
 
 Review comment:
   checkNotNull(jobId)

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