Samrat002 commented on code in PR #6: URL: https://github.com/apache/flink-connector-redis-streams/pull/6#discussion_r3055298250
########## flink-connector-redis-streams/src/main/java/org/apache/flink/connector/redis/streams/source/config/RedisStreamsSourceConfig.java: ########## @@ -0,0 +1,257 @@ +/* + * 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.redis.streams.source.config; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.util.Preconditions; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +/** Configuration for the Redis Streams Source. */ +@PublicEvolving +public class RedisStreamsSourceConfig implements Serializable { + + private static final long serialVersionUID = 1L; + public static final String DEFAULT_CONSUMER_GROUP = "flink-consumer-group"; + + private final String host; + private final int port; + private final String password; + private final int database; + private final List<String> streamKeys; + private final String consumerGroup; + private final String consumerName; + private final boolean bounded; + private final long pollTimeout; + private final int batchSize; + private final long discoveryInterval; + private final int maxDeferredAckQueueSize; + private final long circuitBreakerOpenDurationMs; + private final int circuitBreakerFailureThreshold; + + private RedisStreamsSourceConfig( + String host, + int port, + String password, + int database, + List<String> streamKeys, + String consumerGroup, + String consumerName, + boolean bounded, + long pollTimeout, + int batchSize, + long discoveryInterval, + int maxDeferredAckQueueSize, + long circuitBreakerOpenDurationMs, + int circuitBreakerFailureThreshold) { + this.host = host; + this.port = port; + this.password = password; + this.database = database; + this.streamKeys = Collections.unmodifiableList(new ArrayList<>(streamKeys)); + this.consumerGroup = consumerGroup; + this.consumerName = consumerName; + this.bounded = bounded; + this.pollTimeout = pollTimeout; + this.batchSize = batchSize; + this.discoveryInterval = discoveryInterval; + this.maxDeferredAckQueueSize = maxDeferredAckQueueSize; + this.circuitBreakerOpenDurationMs = circuitBreakerOpenDurationMs; + this.circuitBreakerFailureThreshold = circuitBreakerFailureThreshold; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + public String getPassword() { + return password; + } + + public int getDatabase() { + return database; + } + + public List<String> getStreamKeys() { + return streamKeys; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public String getConsumerName() { + return consumerName; + } + + public boolean isBounded() { + return bounded; + } + + public long getPollTimeout() { + return pollTimeout; + } + + public int getBatchSize() { + return batchSize; + } + + public long getDiscoveryInterval() { + return discoveryInterval; + } + + public int getMaxDeferredAckQueueSize() { + return maxDeferredAckQueueSize; + } + + public long getCircuitBreakerOpenDurationMs() { + return circuitBreakerOpenDurationMs; + } + + public int getCircuitBreakerFailureThreshold() { + return circuitBreakerFailureThreshold; + } + + public static Builder builder() { + return new Builder(); + } + + /** Builder for RedisStreamsSourceConfig. */ + public static class Builder { + private String host = "localhost"; + private int port = 6379; + private String password = null; + private int database = 0; + private List<String> streamKeys; + private String consumerGroup = DEFAULT_CONSUMER_GROUP; + private String consumerName; + private boolean bounded = false; + private long pollTimeout = 1000; + private int batchSize = 100; + private long discoveryInterval = 60000; + private int maxDeferredAckQueueSize = 10000; + private long circuitBreakerOpenDurationMs = 5000; + private int circuitBreakerFailureThreshold = 3; + + public Builder setHost(String host) { + this.host = host; + return this; + } + + public Builder setPort(int port) { + this.port = port; + return this; + } + + public Builder setPassword(String password) { + this.password = password; + return this; + } + + public Builder setDatabase(int database) { + this.database = database; + return this; + } + + public Builder setStreamKeys(List<String> streamKeys) { + this.streamKeys = streamKeys; + return this; + } + + public Builder setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + return this; + } + + public Builder setConsumerName(String consumerName) { + this.consumerName = consumerName; + return this; + } + + public Builder setBounded(boolean bounded) { + this.bounded = bounded; + return this; + } + + public Builder setPollTimeout(long pollTimeout) { + this.pollTimeout = pollTimeout; + return this; + } + + public Builder setBatchSize(int batchSize) { + this.batchSize = batchSize; + return this; + } + + public Builder setDiscoveryInterval(long discoveryInterval) { + this.discoveryInterval = discoveryInterval; + return this; + } + + public Builder setMaxDeferredAckQueueSize(int maxDeferredAckQueueSize) { + this.maxDeferredAckQueueSize = maxDeferredAckQueueSize; + return this; + } + + public Builder setCircuitBreakerOpenDurationMs(long circuitBreakerOpenDurationMs) { + this.circuitBreakerOpenDurationMs = circuitBreakerOpenDurationMs; + return this; + } + + public Builder setCircuitBreakerFailureThreshold(int circuitBreakerFailureThreshold) { + this.circuitBreakerFailureThreshold = circuitBreakerFailureThreshold; + return this; + } + + public RedisStreamsSourceConfig build() { Review Comment: Excellent catch. When consumerName is shared across parallel subtasks, Redis consumer groups treat all connections as one consumer, defeating the purpose of parallel reads. Fixed by appending -subtaskId to the consumer name in RedisStreamsSplitReader.fetchFromSplit(). The subtaskId is now passed from SourceReaderContext.getIndexOfSubtask() through RedisStreamsSource.createReader() → RedisStreamsSplitReader constructor. This ensures each subtask gets a unique consumer identity within the consumer group (e.g., `flink-consumer-abc12345-0`, `flink-consumer-abc12345-1`). -- 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]
