MartijnVisser commented on code in PR #279:
URL: 
https://github.com/apache/flink-connector-kafka/pull/279#discussion_r4770378638


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/DynamicKafkaSourceEnumerator.java:
##########
@@ -826,56 +1008,91 @@ private void 
flushPendingSplitAssignmentsForRegisteredReaders() {
     }
 
     private void reassignReportedSplits() {
-        Map<String, ReportedSplit> activeReportedSplits = new TreeMap<>();
-        Map<Integer, List<DynamicKafkaSourceSplit>> retainedSplitsByReader = 
new TreeMap<>();
-        long currentTimeMillis = System.currentTimeMillis();
-
-        for (Entry<Integer, List<DynamicKafkaSourceSplit>> readerSplits :
+        // Full restore reconciles a completed checkpoint. Older writers 
calculated reader
+        // deadlines independently, so normalize known retained reports here 
without a format tag.
+        // Live handoff and local recovery still require the current 
coordinator retention epoch.
+        Map<String, ReportedSplit> reports = new TreeMap<>();
+        for (Entry<Integer, List<DynamicKafkaSourceSplit>> batch :
                 new TreeMap<>(pendingReportedSplitsByReader).entrySet()) {
-            int readerId = readerSplits.getKey();
-            for (DynamicKafkaSourceSplit split : readerSplits.getValue()) {
-                if (isSplitActive(split)) {
-                    DynamicKafkaSourceSplit activeSplit = 
split.clearRetention();
-                    ReportedSplit previous =
-                            activeReportedSplits.putIfAbsent(
-                                    activeSplit.splitId(),
-                                    new ReportedSplit(activeSplit, readerId));
-                    if (previous != null) {
-                        throw new IllegalStateException(
-                                String.format(
-                                        "Split %s was reported by both reader 
%d and reader %d",
-                                        activeSplit.splitId(), 
previous.readerId, readerId));
-                    }
-                } else {
-                    DynamicKafkaSourceSplit retainedSplit =
-                            getRetainedReportedSplit(split, currentTimeMillis);
-                    if (retainedSplit != null) {
-                        retainedSplitsByReader
-                                .computeIfAbsent(readerId, ignored -> new 
ArrayList<>())
-                                .add(retainedSplit);
-                    } else {
-                        logger.info("Dropping inactive reported split on 
recovery: {}", split);
+            for (DynamicKafkaSourceSplit split : batch.getValue()) {
+                DynamicKafkaSourceSplit normalized =
+                        
retainedClusterEnumeratorStates.containsKey(split.getKafkaClusterId())
+                                ? getRetainedReportedSplit(split)
+                                : isSplitActive(split)
+                                                && (!split.isRetained()
+                                                        || 
restoredAssignedSplits.containsKey(
+                                                                
split.splitId()))
+                                        ? split.clearRetention()
+                                        : null;
+                if (normalized == null) {
+                    continue;
+                }
+                // Every reader is restoring the same completed checkpoint. A 
returning cluster
+                // can join ordinary recovery; only a live handoff needs 
another checkpoint fence.
+                if (isSplitActive(normalized)) {
+                    normalized = normalized.clearRetention();
+                }
+                ReportedSplit previous = reports.get(split.splitId());

Review Comment:
   Keyed by `splitId()`, cluster `a` topic `b-c` and cluster `a-b` topic `c` 
collide on `a-b-c-0` and a full restore fails every attempt. Main keys by 
partition since FLINK-41088.



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/DynamicKafkaSourceEnumerator.java:
##########
@@ -960,7 +1290,18 @@ private ReportedSplit(DynamicKafkaSourceSplit split, int 
readerId) {
      */
     @Override
     public DynamicKafkaSourceEnumState snapshotState(long checkpointId) throws 
Exception {
+        Preconditions.checkState(
+                checkpointId < 0 || allReadersRegistered(),

Review Comment:
   This fails every checkpoint and savepoint while a reader re-registers, which 
FLINK-40469 made safe. What does it still protect?



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/DynamicKafkaSourceEnumerator.java:
##########
@@ -833,13 +944,33 @@ private void reassignReportedSplits() {
                 new TreeMap<>(pendingReportedSplitsByReader).entrySet()) {
             int readerId = readerSplits.getKey();
             for (DynamicKafkaSourceSplit split : readerSplits.getValue()) {
-                if (isSplitActive(split)) {
+                boolean retainedClusterWaitingForHandoff =
+                        split.isRetained()
+                                && retainedClusterEnumeratorStates.containsKey(
+                                        split.getKafkaClusterId());
+                if (!retainedClusterWaitingForHandoff && isSplitActive(split)) 
{

Review Comment:
   On the head, reader 1's restored copy is still retained while its cluster is 
active, so `restoreFailedReaders` drops it.



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