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


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/util/ProgressBlockingRelativeClock.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.streaming.api.operators.util;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.metrics.TimerGauge;
+import org.apache.flink.util.clock.Clock;
+import org.apache.flink.util.clock.RelativeClock;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * A {@link RelativeClock} that can be marked to start and stop blocking 
progress of the relative
+ * time with respect to the wall clock.
+ */
+@Internal
+@ThreadSafe
+public class ProgressBlockingRelativeClock implements RelativeClock, 
TimerGauge.StartStopListener {
+    private final Clock baseClock;
+
+    private long accumulativeBlockedNanoTime;
+    private long currentBlockedNanoTimeStart;
+    private long blockedCounter;
+
+    public ProgressBlockingRelativeClock(Clock baseClock) {
+        this.baseClock = baseClock;
+    }
+
+    @Override
+    public long relativeTimeMillis() {
+        return relativeTimeNanos() / 1_000_000;
+    }
+
+    @Override
+    public long relativeTimeNanos() {
+        return baseClock.relativeTimeNanos() - getBlockedTime();
+    }
+
+    public synchronized void markBlocked() {
+        if (blockedCounter == 0) {
+            currentBlockedNanoTimeStart = baseClock.relativeTimeNanos();
+        }
+        blockedCounter++;
+    }
+
+    public synchronized void markUnblocked() {
+        checkState(blockedCounter >= 1);
+        blockedCounter--;
+        if (blockedCounter == 0) {

Review Comment:
   Do I understand correctly, that the counter is needed to account for 
multiple sources of blocking (source alignment, soft back-pressure, hard 
back-pressure)?
   
   But if I'm reading `SourceOperator` code correctly, the same split can be 
paused multiple times - there is no guard in `checkSplitWatermarkAlignment`. 
But it is unpaused only once - there _**is**_ a guard:
   
   ```
   if (splitWatermark > currentMaxDesiredWatermark) {
       splitsToPause.add(splitId); // <--- add even if is paused already
   } else if (currentlyPausedSplits.contains(splitId)) {
       splitsToResume.add(splitId); // <---- add only if paused
   }
   ...
   pauseOrResumeSplits(splitsToPause, splitsToResume);
   ```
   
   So the counter might be broken if the same split is paused twice and then 
unpaused once.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to