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/10/26 11:20:34 UTC

[GitHub] [flink] StephanEwen commented on a change in pull request #13784: [FLINK-19689][connectors/common] API improvements to the Sources.

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



##########
File path: flink-core/src/test/java/org/apache/flink/testutils/TestUtils.java
##########
@@ -0,0 +1,65 @@
+/*
+ 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.testutils;
+
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.SystemClock;
+
+import java.util.concurrent.TimeoutException;
+import java.util.function.Supplier;
+
+/**
+ * A util class that provides general helper methods for unit tests and IT cases.
+ *
+ * <p>Generally speaking a method should be put into this class if the following
+ * conditions are met:
+ * <ul>
+ *     <li>The method is commonly used in different modules.</li>
+ *     <li>The method does not introduce cyclic dependency to flink-core.</li>
+ * </ul>
+ */
+public class TestUtils {

Review comment:
       There are two dedicated test utils modules already:
     - `flink-test-utils-junit` with all the generic test utils that have no dependency on any Flink code
     - `flink-test-utils` with the test utils that need runtime support (like mini clusters).
   
   The code here should probably go to the `flink-test-utils-junit` module. Putting it on `flink-core` means reliance on the test jars, which is always good to avoid when possible.

##########
File path: flink-core/src/test/java/org/apache/flink/testutils/TestUtils.java
##########
@@ -0,0 +1,65 @@
+/*
+ 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.testutils;
+
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.SystemClock;
+
+import java.util.concurrent.TimeoutException;
+import java.util.function.Supplier;
+
+/**
+ * A util class that provides general helper methods for unit tests and IT cases.
+ *
+ * <p>Generally speaking a method should be put into this class if the following
+ * conditions are met:
+ * <ul>
+ *     <li>The method is commonly used in different modules.</li>
+ *     <li>The method does not introduce cyclic dependency to flink-core.</li>
+ * </ul>
+ */
+public class TestUtils {
+	private static final Clock clock = SystemClock.getInstance();
+
+	private TestUtils() {}
+
+	/**
+	 * Wait util the given condition is met or timeout.
+	 *
+	 * @param condition the condition to wait for.
+	 * @param timeoutMs the maximum time in milliseconds to wait for the condition to become true.
+	 * @param errorMsg the error message to include in the <code>TimeoutException</code>
+	 * 				   if the condition was not met before timeout.
+	 * @throws TimeoutException if the condition is not met before timeout.
+	 * @throws InterruptedException if the thread is interrupted.
+	 */
+	@SuppressWarnings("BusyWait")
+	public static void waitUtil(Supplier<Boolean> condition, long timeoutMs, String errorMsg)

Review comment:
       Most non-performance critical parts of the code started using `Duration` to make time units explicit.

##########
File path: flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReader.java
##########
@@ -60,6 +60,13 @@
 	 */
 	List<SplitT> snapshotState();
 
+	/**
+	 * Notify the source reader of a successful checkpoint. Doing nothing by default.
+	 *
+	 * @param checkpointId the ID of the successful checkpoint.
+	 */
+	default void checkpointComplete(long checkpointId) {}

Review comment:
       The `checkpointComplete()` methods take the checkpoint ID, but the snapshot methods do not take any checkpoint Id. That makes it hard to correlate the calls.
   
   Because multiple checkpoints can (and ultimately will) happen concurrently, you don't know what snapshot will have completed here.
   
   For example in the Kafka case, I assume you remember the offsets at the point of snapshot. And then commit them when the snapshot is complete. If you look at the existing Kafka Connector, then it kept remembering offsets per checkpoint in a Map (checkpoint -> offsets) to commit them as the checkpoints where completed. I cannot see how this interface could support this.

##########
File path: flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/reader/splitreader/SplitReader.java
##########
@@ -57,4 +57,11 @@
 	 * {@link #fetch()}.
 	 */
 	void wakeUp();
+
+	/**
+	 * Close the split reader.
+	 *
+	 * @throws Exception if closing the split reader failed.
+	 */
+	default void close() throws Exception {}

Review comment:
       I would personally not make this a default method, because it is a crucial one for every implementer to think about.




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