JingsongLi commented on code in PR #519:
URL: https://github.com/apache/flink-table-store/pull/519#discussion_r1103568302


##########
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/ContinuousFileSplitEnumerator.java:
##########
@@ -91,6 +92,19 @@ private void addSplit(FileStoreSourceSplit split) {
                 .add(split);
     }
 
+    private void addSplitsBack(Collection<FileStoreSourceSplit> splits) {
+        List<FileStoreSourceSplit> backSplits = new ArrayList<>(splits);
+        Collections.reverse(backSplits);
+        backSplits.forEach(this::addSplitToHead);
+    }
+
+    private void addSplitToHead(FileStoreSourceSplit split) {
+        ((LinkedList<FileStoreSourceSplit>)

Review Comment:
   Don't use cast, just declare `bucketSplits` to `Map<Integer, 
LinkedList<FileStoreSourceSplit>>`



##########
flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/source/ContinuousFileSplitEnumeratorTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.table.store.connector.source;
+
+import org.apache.flink.api.connector.source.SplitEnumeratorContext;
+import 
org.apache.flink.connector.testutils.source.reader.TestingSplitEnumeratorContext;
+import org.apache.flink.table.store.file.io.DataFileMeta;
+import org.apache.flink.table.store.table.source.DataSplit;
+import org.apache.flink.table.store.table.source.snapshot.SnapshotEnumerator;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import static 
org.apache.flink.table.store.file.mergetree.compact.MergeTreeCompactManagerTest.row;
+
+/** Unit tests for the {@link ContinuousFileSplitEnumerator}. */
+public class ContinuousFileSplitEnumeratorTest {
+
+    @Test
+    public void testSplitAllocationIsOrdered() throws Exception {
+        final TestingSplitEnumeratorContext<FileStoreSourceSplit> context =
+                new TestingSplitEnumeratorContext<>(1);
+        context.registerReader(0, "test-host");
+
+        List<FileStoreSourceSplit> initialSplits = new ArrayList<>();
+        FileStoreSourceSplit split1 = createSnapshotSplit(1, 0, 
Collections.emptyList());
+        FileStoreSourceSplit split2 = createSnapshotSplit(2, 0, 
Collections.emptyList());
+        initialSplits.add(split1);
+        initialSplits.add(split2);
+        final ContinuousFileSplitEnumerator enumerator =
+                new Builder()
+                        .setSplitEnumeratorContext(context)
+                        .setInitialSplits(initialSplits)
+                        .setDiscoveryInterval(3)
+                        .build();
+
+        // The first time split is allocated, split1 should be allocated
+        enumerator.handleSplitRequest(0, "test-host");
+        Assert.assertEquals(1, context.getSplitAssignments().size());
+        Assert.assertTrue(context.getSplitAssignments().containsKey(0));
+        List<FileStoreSourceSplit> assignedSplits =
+                context.getSplitAssignments().get(0).getAssignedSplits();
+        Assert.assertEquals(1, assignedSplits.size());
+        Assert.assertEquals(split1, assignedSplits.get(0));
+
+        // split1 is added back
+        enumerator.addSplitsBack(Collections.singletonList(split1), 0);

Review Comment:
   We can add tests for adding back multiple splits.



##########
flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/source/ContinuousFileSplitEnumerator.java:
##########
@@ -91,6 +92,19 @@ private void addSplit(FileStoreSourceSplit split) {
                 .add(split);
     }
 
+    private void addSplitsBack(Collection<FileStoreSourceSplit> splits) {
+        List<FileStoreSourceSplit> backSplits = new ArrayList<>(splits);

Review Comment:
   nit: can use `new 
LinkedList<>(splits).descendingIterator().forEachRemaining(this::addSplitToHead)`.



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