liming30 commented on code in PR #1301:
URL: https://github.com/apache/incubator-paimon/pull/1301#discussion_r1218278952


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/assigners/FairSplitAssigner.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.paimon.flink.source.assigners;
+
+import org.apache.paimon.flink.source.FileStoreSourceSplit;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+/**
+ * Pre-calculate which splits each task should process according to the 
weight, and then distribute
+ * the splits fairly.
+ */
+public class FairSplitAssigner implements SplitAssigner {
+
+    /** Default batch splits size to avoid exceed `akka.framesize`. */
+    private final int splitBatchSize;
+
+    private final Map<Integer, Queue<FileStoreSourceSplit>> 
pendingSplitAssignment;
+
+    public FairSplitAssigner(
+            int splitBatchSize, Map<Integer, Queue<FileStoreSourceSplit>> 
pendingSplitAssignment) {
+        this.splitBatchSize = splitBatchSize;
+        this.pendingSplitAssignment = pendingSplitAssignment;
+    }
+
+    @Override
+    public List<FileStoreSourceSplit> getNext(int subtask, @Nullable String 
hostname) {
+        // The following batch assignment operation is for two purposes:
+        // To distribute splits evenly when batch reading to prevent a few 
tasks from reading all
+        // the data (for example, the current resource can only schedule part 
of the tasks).
+        Queue<FileStoreSourceSplit> taskSplits = 
pendingSplitAssignment.get(subtask);
+        List<FileStoreSourceSplit> assignment = new ArrayList<>();
+        while (taskSplits != null && !taskSplits.isEmpty() && 
assignment.size() < splitBatchSize) {
+            assignment.add(taskSplits.poll());
+        }
+        return assignment;
+    }
+
+    @Override
+    public void addSplits(int subtask, List<FileStoreSourceSplit> splits) {
+        pendingSplitAssignment.computeIfAbsent(subtask, k -> new 
LinkedList<>()).addAll(splits);

Review Comment:
   rebase to master and resolved.



-- 
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: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to