EricJoy2048 commented on code in PR #6766:
URL: https://github.com/apache/seatunnel/pull/6766#discussion_r1637932861


##########
seatunnel-connectors-v2/connector-paimon/src/main/java/org/apache/seatunnel/connectors/seatunnel/paimon/source/PaimonSourceSplitEnumerator.java:
##########
@@ -39,36 +43,50 @@ public class PaimonSourceSplitEnumerator
     /** Source split enumerator context */
     private final Context<PaimonSourceSplit> context;
 
-    /** The splits that has assigned */
-    private final Set<PaimonSourceSplit> assignedSplit;
+    private final Set<PaimonSourceSplit> pendingSplits = new HashSet<>();
 
-    /** The splits that have not assigned */
-    private Set<PaimonSourceSplit> pendingSplit;
+    private Map<Integer, Set<PaimonSourceSplit>> assignedSplits;
+
+    private volatile boolean shouldEnumerate;
+
+    private final Object stateLock = new Object();
 
     /** The table that wants to read */
     private final Table table;
 
     public PaimonSourceSplitEnumerator(Context<PaimonSourceSplit> context, 
Table table) {
-        this.context = context;
-        this.table = table;
-        this.assignedSplit = new HashSet<>();
+        this(context, table, null);
     }
 
     public PaimonSourceSplitEnumerator(
             Context<PaimonSourceSplit> context, Table table, PaimonSourceState 
sourceState) {
         this.context = context;
         this.table = table;
-        this.assignedSplit = sourceState.getAssignedSplits();
+        this.shouldEnumerate = (sourceState == null || 
sourceState.isShouldEnumerate());
+        this.assignedSplits = new HashedMap();
+        if (sourceState != null) {
+            this.assignedSplits.putAll(sourceState.getAssignedSplits());
+        }
     }
 
     @Override
     public void open() {
-        this.pendingSplit = new HashSet<>();
+        this.pendingSplits.addAll(getTableSplits());
     }
 
     @Override
     public void run() throws Exception {
-        // do nothing
+        Set<Integer> readers = context.registeredReaders();
+        if (shouldEnumerate) {
+            synchronized (stateLock) {
+                addAssignSplit(pendingSplits);
+                shouldEnumerate = false;
+            }
+            assignSplit(readers);

Review Comment:
   need put `assignSplit(readers);` in `synchronized (stateLock)`



##########
seatunnel-connectors-v2/connector-paimon/src/main/java/org/apache/seatunnel/connectors/seatunnel/paimon/source/PaimonSourceSplitEnumerator.java:
##########
@@ -79,25 +97,29 @@ public void close() throws IOException {
     @Override
     public void addSplitsBack(List<PaimonSourceSplit> splits, int subtaskId) {
         if (!splits.isEmpty()) {
-            pendingSplit.addAll(splits);
-            assignSplit(subtaskId);
+            addAssignSplit(splits);

Review Comment:
   ```
   synchronized (stateLock) {
                   addPendingSplit(splits, subtaskId);
                   if (context.registeredReaders().contains(subtaskId)) {
                       assignSplit(Collections.singletonList(subtaskId));
                   } else {
                       LOG.warn(
                               "Reader {} is not registered. Pending splits {} 
are not assigned.",
                               subtaskId,
                               splits);
                   }
               }
   ```



##########
seatunnel-connectors-v2/connector-paimon/src/main/java/org/apache/seatunnel/connectors/seatunnel/paimon/source/PaimonSourceSplitEnumerator.java:
##########
@@ -79,25 +97,29 @@ public void close() throws IOException {
     @Override
     public void addSplitsBack(List<PaimonSourceSplit> splits, int subtaskId) {
         if (!splits.isEmpty()) {
-            pendingSplit.addAll(splits);
-            assignSplit(subtaskId);
+            addAssignSplit(splits);
+            assignSplit(Collections.singletonList(subtaskId));
         }
     }
 
     @Override
     public int currentUnassignedSplitSize() {
-        return pendingSplit.size();
+        return pendingSplits.size();
     }
 
     @Override
     public void registerReader(int subtaskId) {
-        pendingSplit = getTableSplits();
-        assignSplit(subtaskId);
+        log.debug("Register reader {} to PaimonSourceSplitEnumerator.", 
subtaskId);

Review Comment:
   ```
           if (!pendingSplits.isEmpty()) {
               synchronized (stateLock) {
                   assignSplit(Collections.singletonList(subtaskId));
               }
           }
   ```



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

Reply via email to