dannycranmer commented on code in PR #20245:
URL: https://github.com/apache/flink/pull/20245#discussion_r940191990


##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/AsyncSinkWriter.java:
##########
@@ -256,43 +242,54 @@ public AsyncSinkWriter(
             long maxTimeInBufferMS,
             long maxRecordSizeInBytes,
             Collection<BufferedRequestState<RequestEntryT>> states) {
+        this(
+                elementConverter,
+                context,
+                BasicAsyncSinkWriterConfiguration.builder()
+                        .setMaxBatchSize(maxBatchSize)
+                        .setMaxInFlightRequests(maxInFlightRequests)
+                        .setMaxBufferedRequests(maxBufferedRequests)
+                        .setMaxBatchSizeInBytes(maxBatchSizeInBytes)
+                        .setMaxTimeInBufferMS(maxTimeInBufferMS)
+                        .setMaxRecordSizeInBytes(maxRecordSizeInBytes)
+                        .build(),
+                states);
+    }
+
+    public AsyncSinkWriter(
+            ElementConverter<InputT, RequestEntryT> elementConverter,
+            Sink.InitContext context,
+            BasicAsyncSinkWriterConfiguration configuration,

Review Comment:
   I think you meant `AsyncSinkWriterConfiguration` here?



##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/config/BasicAsyncSinkWriterConfiguration.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.connector.base.sink.writer.config;
+
+import 
org.apache.flink.connector.base.sink.writer.strategy.AIMDScalingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.CongestionControlRateLimitingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.RateLimitingStrategy;
+
+/**
+ * BasicAsyncSinkWriterConfiguration with defaults that work well for 
streaming sources/sinks like
+ * Kinesis Data Streams and Kinesis Firehose.
+ */
+public class BasicAsyncSinkWriterConfiguration implements 
AsyncSinkWriterConfiguration {
+    private final int maxBatchSize;
+    private final int maxInFlightRequests;
+    private final int maxBufferedRequests;
+    private final long maxBatchSizeInBytes;
+    private final long maxTimeInBufferMS;
+    private final long maxRecordSizeInBytes;
+    private final RateLimitingStrategy rateLimitingStrategy;
+
+    private BasicAsyncSinkWriterConfiguration(
+            int maxBatchSize,
+            int maxInFlightRequests,
+            int maxBufferedRequests,
+            long maxBatchSizeInBytes,
+            long maxTimeInBufferMS,
+            long maxRecordSizeInBytes,
+            RateLimitingStrategy rateLimitingStrategy) {
+        this.maxBatchSize = maxBatchSize;
+        this.maxInFlightRequests = maxInFlightRequests;
+        this.maxBufferedRequests = maxBufferedRequests;
+        this.maxBatchSizeInBytes = maxBatchSizeInBytes;
+        this.maxTimeInBufferMS = maxTimeInBufferMS;
+        this.maxRecordSizeInBytes = maxRecordSizeInBytes;
+        this.rateLimitingStrategy = rateLimitingStrategy;
+    }
+
+    public int getMaxBatchSize() {
+        return maxBatchSize;
+    }
+
+    public int getMaxInFlightRequests() {
+        return maxInFlightRequests;
+    }
+
+    public int getMaxBufferedRequests() {
+        return maxBufferedRequests;
+    }
+
+    public long getMaxBatchSizeInBytes() {
+        return maxBatchSizeInBytes;
+    }
+
+    public long getMaxTimeInBufferMS() {
+        return maxTimeInBufferMS;
+    }
+
+    public long getMaxRecordSizeInBytes() {
+        return maxRecordSizeInBytes;
+    }
+
+    public RateLimitingStrategy getRateLimitingStrategy() {
+        return rateLimitingStrategy;
+    }
+
+    public static BasicAsyncSinkWriterConfigurationBuilder builder() {
+        return new BasicAsyncSinkWriterConfigurationBuilder();
+    }
+
+    /** Builder for {@link BasicAsyncSinkWriterConfiguration}. */
+    public static class BasicAsyncSinkWriterConfigurationBuilder {
+
+        private int maxBatchSize = 500;
+        private int maxInFlightRequests = 50;
+        private int maxBufferedRequests = 10_000;
+        private long maxBatchSizeInBytes = 5 * 1024 * 1024;
+        private long maxTimeInBufferMS = 5_000;
+        private long maxRecordSizeInBytes = 1024 * 1024;

Review Comment:
   I do not think it is a good idea to have defaults in the base 
implementation. This also makes the validation less useful, users could develop 
sinks without considering these values and result in non-performant sink.



##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/config/BasicAsyncSinkWriterConfiguration.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.connector.base.sink.writer.config;
+
+import 
org.apache.flink.connector.base.sink.writer.strategy.AIMDScalingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.CongestionControlRateLimitingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.RateLimitingStrategy;
+
+/**
+ * BasicAsyncSinkWriterConfiguration with defaults that work well for 
streaming sources/sinks like
+ * Kinesis Data Streams and Kinesis Firehose.
+ */

Review Comment:
   Base framework should not know about concrete implementations 



##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/config/AsyncSinkWriterConfiguration.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.connector.base.sink.writer.config;
+
+import org.apache.flink.annotation.PublicEvolving;
+import 
org.apache.flink.connector.base.sink.writer.strategy.RateLimitingStrategy;
+
+/**
+ * AsyncSinkWriterConfiguration configures the {@link
+ * org.apache.flink.connector.base.sink.writer.AsyncSinkWriter}.
+ */
+@PublicEvolving
+public interface AsyncSinkWriterConfiguration {

Review Comment:
   Why does this need an interface? Can you think of any usecase where this 
would add value? I would prefer an `AsyncSinkWriterConfiguration` object here. 



##########
flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/sink/writer/config/BasicAsyncSinkWriterConfiguration.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.connector.base.sink.writer.config;
+
+import 
org.apache.flink.connector.base.sink.writer.strategy.AIMDScalingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.CongestionControlRateLimitingStrategy;
+import 
org.apache.flink.connector.base.sink.writer.strategy.RateLimitingStrategy;
+
+/**
+ * BasicAsyncSinkWriterConfiguration with defaults that work well for 
streaming sources/sinks like
+ * Kinesis Data Streams and Kinesis Firehose.
+ */
+public class BasicAsyncSinkWriterConfiguration implements 
AsyncSinkWriterConfiguration {
+    private final int maxBatchSize;
+    private final int maxInFlightRequests;
+    private final int maxBufferedRequests;
+    private final long maxBatchSizeInBytes;
+    private final long maxTimeInBufferMS;
+    private final long maxRecordSizeInBytes;
+    private final RateLimitingStrategy rateLimitingStrategy;
+
+    private BasicAsyncSinkWriterConfiguration(
+            int maxBatchSize,
+            int maxInFlightRequests,
+            int maxBufferedRequests,
+            long maxBatchSizeInBytes,
+            long maxTimeInBufferMS,
+            long maxRecordSizeInBytes,
+            RateLimitingStrategy rateLimitingStrategy) {
+        this.maxBatchSize = maxBatchSize;
+        this.maxInFlightRequests = maxInFlightRequests;
+        this.maxBufferedRequests = maxBufferedRequests;
+        this.maxBatchSizeInBytes = maxBatchSizeInBytes;
+        this.maxTimeInBufferMS = maxTimeInBufferMS;
+        this.maxRecordSizeInBytes = maxRecordSizeInBytes;
+        this.rateLimitingStrategy = rateLimitingStrategy;
+    }
+
+    public int getMaxBatchSize() {
+        return maxBatchSize;
+    }
+
+    public int getMaxInFlightRequests() {
+        return maxInFlightRequests;
+    }
+
+    public int getMaxBufferedRequests() {
+        return maxBufferedRequests;
+    }
+
+    public long getMaxBatchSizeInBytes() {
+        return maxBatchSizeInBytes;
+    }
+
+    public long getMaxTimeInBufferMS() {
+        return maxTimeInBufferMS;
+    }
+
+    public long getMaxRecordSizeInBytes() {
+        return maxRecordSizeInBytes;
+    }
+
+    public RateLimitingStrategy getRateLimitingStrategy() {
+        return rateLimitingStrategy;
+    }
+
+    public static BasicAsyncSinkWriterConfigurationBuilder builder() {
+        return new BasicAsyncSinkWriterConfigurationBuilder();
+    }
+
+    /** Builder for {@link BasicAsyncSinkWriterConfiguration}. */
+    public static class BasicAsyncSinkWriterConfigurationBuilder {
+
+        private int maxBatchSize = 500;
+        private int maxInFlightRequests = 50;
+        private int maxBufferedRequests = 10_000;
+        private long maxBatchSizeInBytes = 5 * 1024 * 1024;
+        private long maxTimeInBufferMS = 5_000;
+        private long maxRecordSizeInBytes = 1024 * 1024;
+        private RateLimitingStrategy rateLimitingStrategy;
+
+        public BasicAsyncSinkWriterConfigurationBuilder setMaxBatchSize(int 
maxBatchSize) {
+            this.maxBatchSize = maxBatchSize;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder setMaxInFlightRequests(
+                int maxInFlightRequests) {
+            this.maxInFlightRequests = maxInFlightRequests;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder setMaxBufferedRequests(
+                int maxBufferedRequests) {
+            this.maxBufferedRequests = maxBufferedRequests;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder setMaxBatchSizeInBytes(
+                long maxBatchSizeInBytes) {
+            this.maxBatchSizeInBytes = maxBatchSizeInBytes;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder setMaxTimeInBufferMS(
+                long maxTimeInBufferMS) {
+            this.maxTimeInBufferMS = maxTimeInBufferMS;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder 
setMaxRecordSizeInBytes(
+                long maxRecordSizeInBytes) {
+            this.maxRecordSizeInBytes = maxRecordSizeInBytes;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfigurationBuilder 
setRateLimitingStrategy(
+                RateLimitingStrategy rateLimitingStrategy) {
+            this.rateLimitingStrategy = rateLimitingStrategy;
+            return this;
+        }
+
+        public BasicAsyncSinkWriterConfiguration build() {
+            if (rateLimitingStrategy == null) {

Review Comment:
   What about if we do not want a rate limiting strategy? Should the sink use a 
no-op rather than null?



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