rkhachatryan commented on code in PR #22116:
URL: https://github.com/apache/flink/pull/22116#discussion_r1126916166
##########
flink-runtime/src/test/java/org/apache/flink/runtime/testtasks/OnceBlockingNoOpInvokable.java:
##########
@@ -33,45 +40,45 @@
*/
public class OnceBlockingNoOpInvokable extends AbstractInvokable {
- private static volatile boolean isBlocking = true;
+ private static final Map<ExecutionAttemptID, CountDownLatch>
EXECUTION_LATCHES =
+ new ConcurrentHashMap<>();
- private static final Object lock = new Object();
+ private static volatile boolean isBlocking = true;
- private static volatile boolean running = true;
+ private final ExecutionAttemptID executionAttemptId;
public OnceBlockingNoOpInvokable(Environment environment) {
super(environment);
+ this.executionAttemptId = environment.getExecutionId();
+ Preconditions.checkState(
+ EXECUTION_LATCHES.put(executionAttemptId, new
CountDownLatch(1)) == null);
}
@Override
public void invoke() throws Exception {
- if (isBlocking) {
- synchronized (lock) {
- while (running) {
- lock.wait();
- }
- }
+ final CountDownLatch executionLatch =
+
Preconditions.checkNotNull(EXECUTION_LATCHES.get(executionAttemptId));
+ while (isBlocking && executionLatch.getCount() > 0) {
+ executionLatch.await();
}
}
@Override
public void cancel() throws Exception {
- synchronized (lock) {
- running = false;
- lock.notifyAll();
- }
+
Preconditions.checkNotNull(EXECUTION_LATCHES.remove(executionAttemptId)).countDown();
Review Comment:
nit: don't remove in `cancel`, and rely on `reset` instead? otherwise, it's
possible to add the latch again by mistake
--
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]