You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "reswqa (via GitHub)" <gi...@apache.org> on 2023/07/12 07:26:58 UTC

[GitHub] [flink] reswqa commented on a diff in pull request #22983: [FLINK-32049][checkpoint] Fix thread-safe bug of channel state executor when some subtasks are closed while other subtasks are starting

reswqa commented on code in PR #22983:
URL: https://github.com/apache/flink/pull/22983#discussion_r1260692502


##########
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequestExecutorImpl.java:
##########
@@ -348,24 +360,29 @@ public void registerSubtask(JobVertexID jobVertexID, int subtaskIndex) {
                             subtaskID.getJobVertexID(), subtaskID.getSubtaskIndex()));
             lock.notifyAll();
             unreadyQueues.put(subtaskID, new ArrayDeque<>());
-            if (subtasks.size() == maxSubtasksPerChannelStateFile) {
-                completeRegister = completeRegister();
+            if (subtasks.size() == maxSubtasksPerChannelStateFile && completeRegister()) {
+                onRegistered.accept(this);
             }
         }
-        if (completeRegister) {
-            onRegistered.accept(this);
+    }
+
+    // Only for test to lock the registerLock
+    @VisibleForTesting
+    void registerSubtaskWithoutRegisterLock(JobVertexID jobVertexID, int subtaskIndex) {

Review Comment:
   It's a bit strange that this method still require `registerLock` but claims that it without `registerLock `. 🤔 



##########
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequestExecutorFactoryTest.java:
##########
@@ -69,4 +72,60 @@ private void assertReuseExecutor(int maxSubtasksPerChannelStateFile) {
             }
         }
     }
+
+    @Test
+    void testSomeSubtasksCloseDuringOtherSubtasksStarting() throws Exception {
+        JobID jobID = new JobID();
+        JobVertexID jobVertexID = new JobVertexID();
+        int numberOfSubtask = 100_000;
+        int maxSubtasksPerChannelStateFile = 10;
+
+        ChannelStateWriteRequestExecutorFactory executorFactory =
+                new ChannelStateWriteRequestExecutorFactory(jobID);
+
+        BlockingQueue<ChannelStateWriteRequestExecutor> queue = new LinkedBlockingQueue<>(100);
+
+        CompletableFuture<Void> createFuture = new CompletableFuture<>();
+        new Thread(
+                        () -> {
+                            try {
+                                for (int i = 0; i < numberOfSubtask; i++) {
+                                    ChannelStateWriteRequestExecutor executor =
+                                            executorFactory.getOrCreateExecutor(
+                                                    jobVertexID,
+                                                    i,
+                                                    CHECKPOINT_STORAGE,
+                                                    maxSubtasksPerChannelStateFile,
+                                                    false);
+                                    assertThat(executor).isNotNull();
+                                    queue.put(executor);
+                                }
+                                createFuture.complete(null);
+                            } catch (Throwable e) {
+                                createFuture.completeExceptionally(e);
+                            }
+                        })
+                .start();
+
+        CompletableFuture<Void> releaseFuture = new CompletableFuture<>();
+        new Thread(
+                        () -> {
+                            try {
+                                for (int i = 0; i < numberOfSubtask; i++) {
+                                    ChannelStateWriteRequestExecutor executor = queue.take();
+                                    executor.releaseSubtask(jobVertexID, numberOfSubtask);
+                                    if (i % 1000 == 0) {
+                                        System.gc();

Review Comment:
   What's the purpose of this `System.gc` invocation.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/channel/ChannelStateWriteRequestExecutorImpl.java:
##########
@@ -348,24 +360,29 @@ public void registerSubtask(JobVertexID jobVertexID, int subtaskIndex) {
                             subtaskID.getJobVertexID(), subtaskID.getSubtaskIndex()));
             lock.notifyAll();
             unreadyQueues.put(subtaskID, new ArrayDeque<>());
-            if (subtasks.size() == maxSubtasksPerChannelStateFile) {
-                completeRegister = completeRegister();
+            if (subtasks.size() == maxSubtasksPerChannelStateFile && completeRegister()) {
+                onRegistered.accept(this);
             }
         }
-        if (completeRegister) {
-            onRegistered.accept(this);
+    }
+
+    // Only for test to lock the registerLock
+    @VisibleForTesting
+    void registerSubtaskWithoutRegisterLock(JobVertexID jobVertexID, int subtaskIndex) {

Review Comment:
   It's a bit strange that this method still require `registerLock` but claims that it without `registerLock `. 🤔 



-- 
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-unsubscribe@flink.apache.org

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