afedulov commented on code in PR #20757:
URL: https://github.com/apache/flink/pull/20757#discussion_r963675199


##########
flink-core/src/main/java/org/apache/flink/api/connector/source/lib/util/RateLimitedSourceReader.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.lib.util;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.connector.source.ReaderOutput;
+import org.apache.flink.api.connector.source.SourceReader;
+import org.apache.flink.api.connector.source.SourceSplit;
+import org.apache.flink.core.io.InputStatus;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Wraps the actual {@link SourceReader} and rate limits its data emission. */
+@Experimental
+public class RateLimitedSourceReader<E, SplitT extends SourceSplit>
+        implements SourceReader<E, SplitT> {
+
+    private final SourceReader<E, SplitT> sourceReader;
+    private final RateLimiter rateLimiter;
+
+    /**
+     * Instantiates a new rate-limited source reader.
+     *
+     * @param sourceReader The actual source reader.
+     * @param rateLimiter The rate limiter.
+     */
+    public RateLimitedSourceReader(SourceReader<E, SplitT> sourceReader, 
RateLimiter rateLimiter) {
+        checkNotNull(sourceReader);
+        checkNotNull(rateLimiter);
+        this.sourceReader = sourceReader;
+        this.rateLimiter = rateLimiter;
+    }
+
+    // ------------------------------------------------------------------------
+
+    @Override
+    public void start() {
+        sourceReader.start();
+    }
+
+    @Override
+    public InputStatus pollNext(ReaderOutput<E> output) throws Exception {
+        rateLimiter.acquire();

Review Comment:
   I am afraid that if we want to 100% adhere to the contract of the "proper" 
source for this "mock" source, we'd have to drop rate limiting. Having a 
non-blocking trotting built-in into the Source API looks like a major effort 
that would require a separate design discussion and a FLIP. I know there where 
some talks about this on the mailing list, but the did not seem to have 
materialized into anything yet:
   https://lists.apache.org/thread/93hwlq8lzwx2wvlh9wvsv23hthcx6y3n
   My plan was to go with the basic functionality and converge to the "final" 
solution once it is there from the Source API side.
   Dropping the rate limiting would be unfortunate. In my eyes, not having it 
makes the `DataGeneratorSource` half as useful.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to