You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by co...@apache.org on 2026/04/09 08:30:05 UTC

(seatunnel) branch dev updated: [Docs][Core] Add Javadoc to SupportResourceShare and MultiTableResourceManager (#10707)

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

corgy pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new df6ca723d7 [Docs][Core] Add Javadoc to SupportResourceShare and MultiTableResourceManager (#10707)
df6ca723d7 is described below

commit df6ca723d79f8a98dac078c2351037e6cd8352be
Author: zoo-code <75...@users.noreply.github.com>
AuthorDate: Thu Apr 9 17:29:44 2026 +0900

    [Docs][Core] Add Javadoc to SupportResourceShare and MultiTableResourceManager (#10707)
---
 .../api/sink/MultiTableResourceManager.java        | 36 ++++++++++++++++-
 .../seatunnel/api/sink/SupportResourceShare.java   | 46 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/MultiTableResourceManager.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/MultiTableResourceManager.java
index 001b0023e7..075eb12f86 100644
--- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/MultiTableResourceManager.java
+++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/MultiTableResourceManager.java
@@ -19,12 +19,46 @@ package org.apache.seatunnel.api.sink;
 
 import java.util.Optional;
 
-/** The multi table resource manager */
+/**
+ * Manages a shared resource (e.g., a connection pool) across multiple per-table sink writers in a
+ * multi-table sink scenario.
+ *
+ * <p>Created by {@link SupportResourceShare#initMultiTableResourceManager(int, int)} and closed by
+ * the multi-table sink runtime (e.g., {@link
+ * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkWriter#close()} or {@link
+ * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkAggregatedCommitter#close()}) after
+ * all participating components are closed.
+ *
+ * @param <T> the type of shared resource
+ * @see SupportResourceShare
+ */
 public interface MultiTableResourceManager<T> {
 
+    /**
+     * Returns the shared resource held by this manager.
+     *
+     * <p>Implementations that manage a shared object (e.g., a connection pool) should return it
+     * wrapped in an {@link Optional}. Return {@link Optional#empty()} only when the sink does not
+     * require a shared resource.
+     *
+     * <p>This method must be thread-safe, as multiple per-table writers may call it concurrently
+     * from different write queues.
+     *
+     * @return an {@link Optional} containing the shared resource, or {@link Optional#empty()} if no
+     *     shared resource is needed
+     */
     default Optional<T> getSharedResource() {
         return Optional.empty();
     }
 
+    /**
+     * Releases the shared resource held by this manager.
+     *
+     * <p>Called by the multi-table sink runtime (e.g., {@link
+     * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkWriter#close()} or {@link
+     * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkAggregatedCommitter#close()})
+     * after all participating components have been closed. Implementations should release pooled
+     * connections or other resources here.
+     */
     default void close() {}
 }
diff --git a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SupportResourceShare.java b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SupportResourceShare.java
index 23fe8848af..7db6077b23 100644
--- a/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SupportResourceShare.java
+++ b/seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SupportResourceShare.java
@@ -17,13 +17,59 @@
 
 package org.apache.seatunnel.api.sink;
 
+/**
+ * SPI interface for multi-table sink components that need to share resources (e.g., connection
+ * pools) across multiple tables in a multi-table sink scenario.
+ *
+ * <p>The methods in this interface are invoked during initialization by framework components such
+ * as {@link org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkWriter} and {@link
+ * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkAggregatedCommitter} to create and
+ * distribute a shared resource manager.
+ *
+ * <p>A typical initialization flow is:
+ *
+ * <ol>
+ *   <li>{@link #initMultiTableResourceManager(int, int)} is called once to create the shared
+ *       resource manager.
+ *   <li>{@link #setMultiTableResourceManager(MultiTableResourceManager, int)} is called on each
+ *       participating component to inject the shared resource manager.
+ * </ol>
+ *
+ * @param <T> the type of shared resource (e.g., a connection pool)
+ */
 public interface SupportResourceShare<T> {
 
+    /**
+     * Creates and returns a {@link MultiTableResourceManager} that holds the shared resource.
+     *
+     * <p>Called once per subtask by the {@link
+     * org.apache.seatunnel.api.sink.multitablesink.MultiTableSinkWriter} constructor. One component
+     * instance from the map is used to create the resource manager, based on the map's iteration
+     * order. Implementations must not rely on which instance performs this initialization.
+     *
+     * @param tableSize the number of target tables managed by this sink
+     * @param queueSize the number of parallel write queues
+     * @return a resource manager instance, or {@code null} if resource sharing is not needed
+     */
     default MultiTableResourceManager<T> initMultiTableResourceManager(
             int tableSize, int queueSize) {
         return null;
     }
 
+    /**
+     * Injects the shared {@link MultiTableResourceManager} into the implementing writer.
+     *
+     * <p>Called after {@link #initMultiTableResourceManager(int, int)} on each per-table writer. If
+     * {@link #initMultiTableResourceManager(int, int)} returns {@code null}, this method may still
+     * be called with a {@code null} argument. Implementations should handle that case gracefully
+     * (e.g., fall back to local resources). When non-null, implementations should store the
+     * resource manager and use {@code queueIndex} to retrieve the appropriate shared resource.
+     *
+     * @param multiTableResourceManager the shared resource manager created by {@link
+     *     #initMultiTableResourceManager(int, int)}, or {@code null} if resource sharing is not
+     *     needed
+     * @param queueIndex the index of the write queue this writer belongs to
+     */
     default void setMultiTableResourceManager(
             MultiTableResourceManager<T> multiTableResourceManager, int queueIndex) {}
 }