StephanEwen commented on a change in pull request #11554: 
[FLINK-15101][connector/common] Add SourceCoordinator implementation.
URL: https://github.com/apache/flink/pull/11554#discussion_r410746103
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/source/coordinator/SplitAssignmentTracker.java
 ##########
 @@ -0,0 +1,202 @@
+/*
+ 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.source.coordinator;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.connector.source.SourceSplit;
+import org.apache.flink.api.connector.source.SplitEnumerator;
+import org.apache.flink.api.connector.source.SplitsAssignment;
+import org.apache.flink.core.io.SimpleVersionedSerializer;
+import org.apache.flink.util.function.FunctionWithException;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * A class that is responsible for tracking the past split assignments made by
+ * {@link SplitEnumerator}.
+ */
+@Internal
+public class SplitAssignmentTracker<SplitT extends SourceSplit> {
+       // All the split assignments since the last successful checkpoint.
+       // Maintaining this allow the subtasks to fail over independently.
+       // The mapping is [CheckpointId -> [SubtaskId -> 
LinkedHashSet[SourceSplits]]].
+       private final SortedMap<Long, Map<Integer, LinkedHashSet<SplitT>>> 
assignmentsByCheckpointId;
+       // The split assignments since the last checkpoint attempt.
+       // The mapping is [SubtaskId -> LinkedHashSet[SourceSplits]].
+       private Map<Integer, LinkedHashSet<SplitT>> uncheckpointedAssignments;
+
+       public SplitAssignmentTracker() {
+               this.assignmentsByCheckpointId = new TreeMap<>();
+               this.uncheckpointedAssignments = new HashMap<>();
+       }
+
+       /**
+        * Take a snapshot of the uncheckpointed split assignments.
+        *
+        * @param checkpointId the id of the ongoing checkpoint
+        */
+       public void snapshotState(
+                       long checkpointId,
+                       SimpleVersionedSerializer<SplitT> splitSerializer,
+                       ObjectOutput out) throws Exception {
+               // Write the split serializer version.
+               out.writeInt(splitSerializer.getVersion());
 
 Review comment:
   Java Serialization, see high-level comment.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to