This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/dev/pr-13251-f08c722acb4a95d8bf0cca76367d331b08539a0d
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit 85c150df16144326a9c86fc4c0d4934c4cdbebb1
Author: zhiweiniu <[email protected]>
AuthorDate: Wed Nov 25 07:41:51 2026 +0000

    [Improve][API] Clarify table isolation synchronization during shutdown 
(#13251)
---
 .../sink/multitablesink/MultiTableSinkWriter.java  | 41 ++++++++++++++--------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git 
a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java
 
b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java
index 271f6df30e..fce0fec520 100644
--- 
a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java
+++ 
b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java
@@ -901,19 +901,7 @@ public class MultiTableSinkWriter
         }
         executorService.shutdownNow();
         if (failurePolicy.continueOtherTables()) {
-            synchronized (this) {
-                // When a timer flush round is cancelled, a worker may already 
be isolating
-                // a failed table. That isolation can continue after 
shutdownNow() returns
-                // while the worker closes and removes the table's writers 
across queues.
-                //
-                // Queue locks serialize individual close calls. If shutdown 
closes a writer
-                // first, the writer is still in the map and isolation could 
close it again.
-                //
-                // handleTableFailure() holds this monitor. A flush worker 
checks the round's
-                // stop signal under the same monitor before starting 
isolation. Since close()
-                // has already signaled the round to stop, acquiring this 
monitor waits for any
-                // isolation in progress. Release it before acquiring the 
queue locks below.
-            }
+            awaitTableIsolation();
         }
         for (int i = 0; i < sinkWritersWithIndex.size(); i++) {
             synchronized (runnable.get(i)) {
@@ -986,6 +974,27 @@ public class MultiTableSinkWriter
         }
     }
 
+    /**
+     * Waits for table isolation started by a timer flush before closing the 
remaining writers.
+     *
+     * <p>The caller must first signal the active timer flush round to stop. 
The timer flush stop
+     * check and {@code handleTableFailure()} hold this writer's monitor: a 
timer flush that passed
+     * the check finishes isolation before this method returns, and a later 
timer flush failure
+     * observes the completed round under that monitor and skips isolation. 
This prevents timer
+     * flush isolation and shutdown from closing the same writer twice.
+     *
+     * <p>Other isolation entry points do not check this timer stop signal. 
{@link #close()}
+     * separately calls {@link #checkQueueRemain()} to drain runtime writes 
and their failure
+     * handling.
+     *
+     * <p>Acquiring this monitor is unbounded and uninterruptible; the 
executor termination timeout
+     * in {@link #close()} does not cover this wait. The monitor is released 
before {@code close()}
+     * acquires the queue locks.
+     */
+    private synchronized void awaitTableIsolation() {
+        // Acquiring this monitor is the wait; no additional work is required.
+    }
+
     /**
      * Drains the row queues and flushes independent queues in parallel. A 
successful round waits
      * for every queue. A fatal failure ends the round and prevents further 
child flush actions.
@@ -1091,8 +1100,10 @@ public class MultiTableSinkWriter
                 if (error instanceof InterruptedException) {
                     Thread.currentThread().interrupt();
                 } else if (error instanceof Exception && 
failurePolicy.continueOtherTables()) {
-                    // Table isolation acquires other queue locks. Coordinate 
with close outside
-                    // ours.
+                    // Keep this catch outside the queue monitor: isolation 
takes every queue lock.
+                    // Holding ours while acquiring the writer monitor risks a 
lock-order cycle.
+                    // Hold the writer monitor across the stop check and 
handleTableFailure(), so
+                    // close() cannot acquire it via awaitTableIsolation() 
between them.
                     synchronized (this) {
                         if (!completion.isDone()) {
                             handleTableFailure(

Reply via email to