StephanEwen commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r528936334



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java
##########
@@ -43,9 +51,11 @@
 @Internal
 public class SourceOperatorStreamTask<T> extends StreamTask<T, 
SourceOperator<T, ?>> {
        private AsyncDataOutputToOutput<T> output;
+       private boolean isExternallyInducedSource;
 
        public SourceOperatorStreamTask(Environment env) throws Exception {
                super(env);
+               this.isExternallyInducedSource = false;

Review comment:
       nit: this is not necessary, false is the default.

##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/SourceOperatorStreamTask.java
##########
@@ -66,6 +76,43 @@ public void init() {
                        operatorChain);
        }
 
+       @Override
+       protected void beforeInvoke() throws Exception {

Review comment:
       We are creating `input` and the `inputProcessor` twice now, once in 
`init()` and once on `beforeInvoke()`. Can we add this code here to init to 
avoid creating this twice? I think creating it twice may have some unexpected 
side effects in certain cases.

##########
File path: 
flink-core/src/main/java/org/apache/flink/api/connector/source/ExternallyInducedSourceReader.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.api.connector.source;
+
+import org.apache.flink.annotation.PublicEvolving;
+
+import java.util.Optional;
+
+/**
+ * Sources that implement this interface do not trigger checkpoints when 
receiving a
+ * trigger message from the checkpoint coordinator, but when their input 
data/events
+ * indicate that a checkpoint should be triggered.
+ *
+ * <p>The ExternallyInducedSourceReader tells the Flink runtime that a 
checkpoint needs to
+ * be made by returning a checkpointId when shouldTriggerCheckpoint() is 
invoked.
+ *
+ * <p>The implementations typically works together with the SplitEnumerator 
which informs
+ * the external system to trigger a checkpoint.
+ *
+ * @param <T>        The type of records produced by the source.
+ * @param <SplitT>   The type of splits handled by the source.
+ */
+@PublicEvolving
+public interface ExternallyInducedSourceReader<T, SplitT extends SourceSplit>
+               extends SourceReader<T, SplitT> {
+
+       /**
+        * A method that informs the Flink runtime whether a checkpoint should 
be triggered on
+        * this Source.
+        *
+        * <p>This method is invoked when the previous {@link 
#pollNext(ReaderOutput)}
+        * returns {@link 
org.apache.flink.core.io.InputStatus#NOTHING_AVAILABLE}, to check
+        * if the source needs to be checkpointed.
+        *
+        * <p>If a CheckpointId is returned, a checkpoint will be triggered on 
this source reader.
+        * Otherwise, Flink runtime will continue to process the records.
+        *
+        * @return An optional checkpoint ID that Flink runtime should take a 
checkpoint for.
+        */
+       Optional<Long> shouldTriggerCheckpoint();

Review comment:
       If we want to switch from polling to notifying, we could change this 
method to
   ```java
   void registerCheckpointTrigger(Consumer<Long> trigger);
   ```




----------------------------------------------------------------
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:
[email protected]


Reply via email to