Poorvankbhatia commented on code in PR #6:
URL: 
https://github.com/apache/flink-connector-redis-streams/pull/6#discussion_r3167244750


##########
flink-connector-redis-streams/src/main/java/org/apache/flink/connector/redis/streams/source/reader/split/RedisStreamsSplitReader.java:
##########
@@ -0,0 +1,983 @@
+/*
+ * 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.reader.split;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+import org.apache.flink.connector.base.source.reader.splitreader.SplitReader;
+import 
org.apache.flink.connector.base.source.reader.splitreader.SplitsAddition;
+import org.apache.flink.connector.base.source.reader.splitreader.SplitsChange;
+import 
org.apache.flink.connector.redis.streams.source.config.RedisStreamsSourceConfig;
+import org.apache.flink.connector.redis.streams.source.config.StartupMode;
+import 
org.apache.flink.connector.redis.streams.source.split.RedisStreamsSourceSplit;
+
+import io.lettuce.core.AbstractRedisClient;
+import io.lettuce.core.ClientOptions;
+import io.lettuce.core.Consumer;
+import io.lettuce.core.RedisClient;
+import io.lettuce.core.RedisConnectionException;
+import io.lettuce.core.RedisURI;
+import io.lettuce.core.StreamMessage;
+import io.lettuce.core.XGroupCreateArgs;
+import io.lettuce.core.XReadArgs;
+import io.lettuce.core.api.StatefulConnection;
+import io.lettuce.core.cluster.ClusterClientOptions;
+import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
+import io.lettuce.core.cluster.RedisClusterClient;
+import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Split reader that fetches records from Redis Streams via consumer groups 
and defers XACK until
+ * the next completed Flink checkpoint.
+ */
+@Internal

Review Comment:
   One major callout. Isin't adding to deferredAcks at fetch time a subtle 
data-loss bug?
   
   Fetching pulls records from Redis, but they don't become "committed" in 
Flink until they're EMITTED downstream past a checkpoint barrier and that 
happens later, on a different thread.
   
   So picture this: fetch returns 8 records, all 8 IDs go into deferredAcks. 
Main thread emits records 1–4, then snapshotState fires for checkpoint N, 
splitState captures position 4, but markCheckpoint snapshots the queue size as 
8. Barrier emitted. Main thread continues emitting 5–8 (these are AFTER the 
barrier → conceptually part of N+1).
   
   `notifyCheckpointComplete(N) ` fires → XACK sends all 8 to Redis. If we 
crash before checkpoint N+1, recovery restores splitState at position 4, PEL is 
empty (we just XACKed everything), XREADGROUP > returns 9+ — records 5–8 are 
gone  forever, no error, no log. The fix is to populate deferredAcks in 
RecordEmitter.emitRecord AFTER output.collect() succeeds, so the queue reflects 
what's been EMITTED, not what's been FETCHED.
   
   So IMO you can either: Move ACK queue population to emit time 
   
   `deferredAckQueue.add(msg.getId()); ` after the emit not in fetch.
   
   
   



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