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


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/align/AlignedSourceReader.java:
##########
@@ -0,0 +1,298 @@
+/*
+ * 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.align;
+
+import org.apache.paimon.table.source.EndOfScanException;
+import org.apache.paimon.table.source.ReadBuilder;
+import org.apache.paimon.table.source.SnapshotNotExistPlan;
+import org.apache.paimon.table.source.Split;
+import org.apache.paimon.table.source.StreamTableScan;
+import org.apache.paimon.table.source.TableScan;
+
+import org.apache.flink.api.common.eventtime.Watermark;
+import org.apache.flink.api.connector.source.ExternallyInducedSourceReader;
+import org.apache.flink.api.connector.source.ReaderOutput;
+import org.apache.flink.api.connector.source.SourceEvent;
+import org.apache.flink.core.io.InputStatus;
+import org.apache.flink.runtime.io.AvailabilityProvider;
+import org.apache.flink.util.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.runtime.io.AvailabilityProvider.AVAILABLE;
+import static 
org.apache.paimon.flink.FlinkConnectorOptions.CheckpointAlignMode;
+
+/**
+ * A non-parallel {@link org.apache.flink.api.connector.source.SourceReader} 
that uses Flip-27 to
+ * achieve the same function as {@link 
org.apache.paimon.flink.source.operator.MonitorFunction}.
+ *
+ * <p>Send {@link Split} to the downstream task at paimon snapshot 
granularity, and provide two
+ * alignment modes: {@link CheckpointAlignMode#STRICTLY} and {@link 
CheckpointAlignMode#LOOSELY}.
+ *
+ * <ol>
+ *   <li>STRICTLY: only one paimon snapshot is processed within a checkpoint 
interval.
+ *   <li>LOOSELY: several paimon snapshots are processed within a checkpoint 
interval.
+ * </ol>
+ */
+@SuppressWarnings("unchecked")
+public abstract class AlignedSourceReader
+        implements ExternallyInducedSourceReader<Split, AlignedSourceSplit> {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(AlignedSourceReader.class);
+    private static final int MAX_PENDING_PLANS = 10;
+
+    private final ReadBuilder readBuilder;
+
+    private final FutureCompletingBlockingDeque<AlignedSourceSplit> 
pendingSplits;
+
+    private final TreeSet<Long> pendingCheckpoints;
+
+    private final TreeMap<Long, Long> nextSnapshotPerCheckpoint;
+
+    private final long scanInterval;
+
+    private final boolean emitSnapshotWatermark;
+
+    private final ScheduledExecutorService executors;
+
+    private Long snapshotIdByNextCheckpoint;
+
+    private boolean blocking;
+
+    private boolean endOfScan;
+
+    private CompletableFuture<Void> availabilityFuture;
+
+    private transient StreamTableScan scan;
+
+    public AlignedSourceReader(
+            ReadBuilder readBuilder,
+            long scanInterval,
+            boolean emitSnapshotWatermark,
+            ScheduledExecutorService executors) {
+        this.readBuilder = readBuilder;
+        this.pendingSplits = new FutureCompletingBlockingDeque<>();
+        this.pendingCheckpoints = new TreeSet<>();
+        this.availabilityFuture = (CompletableFuture<Void>) AVAILABLE;
+        this.nextSnapshotPerCheckpoint = new TreeMap<>();
+        this.scanInterval = scanInterval;
+        this.emitSnapshotWatermark = emitSnapshotWatermark;
+        this.executors = executors;
+        this.snapshotIdByNextCheckpoint = null;
+        this.blocking = false;
+        this.endOfScan = false;
+    }
+
+    @Override
+    public void start() {
+        this.scan = readBuilder.newStreamScan();

Review Comment:
   So what should the reader do for this checkpoint? directly abort? This may 
cause unnecessary checkpoint failures.



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