rkhachatryan commented on code in PR #29038:
URL: https://github.com/apache/flink/pull/29038#discussion_r4712473985


##########
flink-runtime/src/main/java/org/apache/flink/runtime/source/coordinator/SourceCoordinator.java:
##########
@@ -726,17 +736,44 @@ private void handleReportedWatermark(int subtask, 
Watermark watermark) throws Fl
 
         combinedWatermark
                 .aggregate(subtask, watermark)
-                .ifPresent(
-                        newCombinedWatermark ->
-                                coordinatorStore.computeIfPresent(
-                                        
watermarkAlignmentParams.getWatermarkGroup(),
-                                        (key, oldValue) -> {
-                                            WatermarkAggregator<String> 
watermarkAggregator =
-                                                    
(WatermarkAggregator<String>) oldValue;
-                                            watermarkAggregator.aggregate(
-                                                    operatorName, 
newCombinedWatermark);
-                                            return watermarkAggregator;
-                                        }));
+                .ifPresent(this::updateAggregatedWatermarkOfGroup);
+    }
+
+    private void updateAggregatedWatermarkOfGroup(Watermark 
newCombinedWatermark) {
+        coordinatorStore.computeIfPresent(
+                watermarkAlignmentParams.getWatermarkGroup(),
+                (key, oldValue) -> {
+                    WatermarkAggregator<String> watermarkAggregator =
+                            (WatermarkAggregator<String>) oldValue;
+                    watermarkAggregator.aggregate(operatorName, 
newCombinedWatermark);
+                    watermarkInGroup = newCombinedWatermark;
+                    return watermarkAggregator;
+                });
+    }
+
+    /**
+     * Drops the watermark of a failed subtask. It does not bound the 
restarted attempt, which may
+     * resume from an earlier checkpoint, and keeping it would hold back the 
group while the subtask
+     * restarts, or for good if the new attempt never reports. A source 
without watermarks leaves
+     * the group, as at startup.
+     */
+    private void removeWatermarkOfSubtask(int subtaskId) {
+        if (combinedWatermark.remove(subtaskId)) {
+            if (combinedWatermark.keySet().isEmpty()) {
+                removeFromGroup();
+            } else {
+                
updateAggregatedWatermarkOfGroup(combinedWatermark.getAggregatedWatermark());
+            }
+        }
+    }
+
+    private void removeFromGroup() {
+        coordinatorStore.computeIfPresent(
+                watermarkAlignmentParams.getWatermarkGroup(),
+                (key, oldValue) -> {
+                    ((WatermarkAggregator<String>) 
oldValue).remove(operatorName, watermarkInGroup);

Review Comment:
   NIT: also reset `watermarkInGroup`?



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