Savonitar commented on code in PR #289:
URL: 
https://github.com/apache/flink-connector-kafka/pull/289#discussion_r3895996928


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/ReaderRecoveryGate.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.kafka.dynamic.source.enumerator;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.connector.kafka.dynamic.source.split.DynamicKafkaSourceSplit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Tracks the recovery-time reader registration state of the {@link 
DynamicKafkaSourceEnumerator}.
+ *
+ * <p>When the enumerator is restored from checkpointed state, split 
assignment and metadata update
+ * events must be deferred until the first metadata discovery has completed 
and every reader has
+ * (re-)registered, so that restored reader splits can be redistributed 
consistently. This class
+ * owns that gating state; the enumerator remains responsible for acting on it.
+ */
+@Internal
+class ReaderRecoveryGate {

Review Comment:
   this class is not thread-safe, right? but it is called only in coordinator 
thread, that's why it is fine. am I right?



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/ReaderRecoveryGate.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.kafka.dynamic.source.enumerator;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.connector.kafka.dynamic.source.split.DynamicKafkaSourceSplit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * Tracks the recovery-time reader registration state of the {@link 
DynamicKafkaSourceEnumerator}.
+ *
+ * <p>When the enumerator is restored from checkpointed state, split 
assignment and metadata update
+ * events must be deferred until the first metadata discovery has completed 
and every reader has
+ * (re-)registered, so that restored reader splits can be redistributed 
consistently. This class
+ * owns that gating state; the enumerator remains responsible for acting on it.
+ */
+@Internal
+class ReaderRecoveryGate {
+
+    /** Set on restore; cleared once all readers have registered after the 
first discovery. */
+    private boolean initialReaderRegistrationPending;
+
+    /** Splits reported by readers on registration, pending redistribution. */
+    private final Map<Integer, List<DynamicKafkaSourceSplit>> 
pendingReportedSplitsByReader =
+            new HashMap<>();
+
+    /** Readers whose metadata update events were deferred during recovery. */
+    private final Set<Integer> pendingMetadataUpdateReaders = new HashSet<>();
+
+    ReaderRecoveryGate(boolean restoredFromCheckpoint) {
+        this.initialReaderRegistrationPending = restoredFromCheckpoint;
+    }
+
+    /** Records splits a reader reported on registration; an empty report is 
ignored. */
+    void recordReportedSplits(int subtaskId, List<DynamicKafkaSourceSplit> 
reportedSplits) {

Review Comment:
   Is my understanding correct, that even if this method called twice for same 
subtask (e.g. during failover), it does not bring any issues? if so, do we have 
a test for that case? 



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