You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/11/23 16:15:17 UTC

[GitHub] [flink] becketqin opened a new pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

becketqin opened a new pull request #14181:
URL: https://github.com/apache/flink/pull/14181


   …ce based on FLIP-27 to SourceOperatorStreamTask.
   
   ## What is the purpose of the change
   The current design of FLIP-27 has a regression of not supporting `ExternallyInducedSource` compared with the old `SourceFunction`. This patch fixes that by introducing an `ExternallyInducedSourceReader` interface.
   
   This patch did not add support of `ExternallyInducedSourceReader` for `MultipleInputStreamTask` because it is currently only used by batch jobs and the solution is more intrusive. The implementation that also support `MultipleInputStreamTask` can be found [here](https://github.com/becketqin/flink/tree/FLINK-20270). We will have a separate patch to cover that.
   
   ## Brief change log
   - Add support for ExternallyInducedSource based on FLIP-27 to SourceOperatorStreamTask.
   
   ## Verifying this change
   A unit test of `SourceOperatorStreamTask.testExternallyInducedSource()` has been added to verify the change.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes)
     - If yes, how is the feature documented? (JavaDocs)
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732274146


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970",
       "triggerID" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "e3b9dca74f6146bc5f00f399b268c3a2b76de777",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=10019",
       "triggerID" : "e3b9dca74f6146bc5f00f399b268c3a2b76de777",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970) 
   * e3b9dca74f6146bc5f00f399b268c3a2b76de777 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=10019) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r529272701



##########
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:
       I think just deleting init() can be dangerous. It means we create the input processors much later in the setup sequence (after the `beforeInvoke()` rather than early during that), which changes the setup can lead to surprises down the way.
   It may be that some part of the input sequence rely on the processors being present.
   
   The branch I referenced below has a way to create the reader earlier and thus maintain the SteamTask's setup sequence.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r529399887



##########
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:
       Fair enought.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732274146


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970",
       "triggerID" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "triggerType" : "PUSH"
     }, {
       "hash" : "e3b9dca74f6146bc5f00f399b268c3a2b76de777",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "e3b9dca74f6146bc5f00f399b268c3a2b76de777",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970) 
   * e3b9dca74f6146bc5f00f399b268c3a2b76de777 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732274146


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] becketqin commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
becketqin commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r529272777



##########
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:
       I tend to keep the polling behavior here for safety. If we give control to the user implementation. they may decide to trigger checkpoint at any point, and in any thread, which may cause problem.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732274146


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970",
       "triggerID" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen closed pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen closed pull request #14181:
URL: https://github.com/apache/flink/pull/14181


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] becketqin commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
becketqin commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r529085129



##########
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:
       Good catch. I forgot to delete the `Input` / `InputProcessor` creation in `init()`.
   We cannot add the code here to `init()` because the `SourceReader` was created after the `init()` invocation.
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on a change in pull request #14181:
URL: https://github.com/apache/flink/pull/14181#discussion_r529399887



##########
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:
       Fair enough.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732265798


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 (Mon Nov 23 16:17:53 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732415737


   I found a nice way to avoid the double-initialization of the output and processor and to stick to the proper initialization order.
   
   Here is the branch, the trick is to initialize the reader earlier, so it is already accessible during the task's normal init() phase.
   
   https://github.com/StephanEwen/flink/commits/becket


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732797344


   Manually merged in 4c5fd598d01b7843d9d44439480274a1ca31e87d


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] StephanEwen commented on a change in pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #14181: [FLINK-20270][connector/common] Add support for ExternallyInducedSour…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14181:
URL: https://github.com/apache/flink/pull/14181#issuecomment-732274146


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970",
       "triggerID" : "0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0073d718bd77d0d0cc31417d0f6ae0df0a3e72b9 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=9970) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org