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

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 6374a26cbc [flink] Support managed & task off-heap memory for 
committer slot sharing groups. (#11069)
6374a26cbc is described below

commit 6374a26cbce0ac26c139fe572e479068d4493082
Author: Master.TJ <[email protected]>
AuthorDate: Tue Nov 10 23:04:44 2026 +0800

    [flink] Support managed & task off-heap memory for committer slot sharing 
groups. (#11069)
---
 docs/docs/flink/configuration.md                   |  33 ++++
 docs/generated/flink_connector_configuration.html  |  12 ++
 .../flink/sink/cdc/FlinkCdcMultiTableSink.java     |  44 ++++-
 .../sink/cdc/FlinkCdcSyncDatabaseSinkBuilder.java  |   8 +
 .../flink/sink/cdc/FlinkCdcMultiTableSinkTest.java | 108 ++++++++++++
 .../apache/paimon/flink/FlinkConnectorOptions.java |  16 ++
 .../org/apache/paimon/flink/sink/FlinkSink.java    |  67 +++++---
 ...eapMemoryTest.java => CommitterMemoryTest.java} | 183 ++++++++++++---------
 .../paimon/flink/sink/WriterOffHeapMemoryTest.java |   3 +-
 9 files changed, 369 insertions(+), 105 deletions(-)

diff --git a/docs/docs/flink/configuration.md b/docs/docs/flink/configuration.md
index ee79fa18ad..a5f4066a4d 100644
--- a/docs/docs/flink/configuration.md
+++ b/docs/docs/flink/configuration.md
@@ -119,6 +119,39 @@ downstream slot sharing is preserved; a committer with its 
own explicit resource
 receive the writer's off-heap budget. Leaving the option unset preserves 
existing resource
 configuration.
 
+## Memory for an Explicit Committer Resource Group
+
+Use `sink.committer-memory` to configure the committer slot sharing group's 
task heap, and
+`sink.committer-cpu` to configure its CPU cores (one core by default). Add
+`sink.committer-offheap-memory` and `sink.committer-managed-memory` to request 
task off-heap
+and managed memory independently or together. Both optional budgets must be 
positive and
+require `sink.committer-memory`. Units such as `kb`, `mb`, and `gb` retain 
their byte precision.
+
+```sql
+INSERT INTO paimon_table /*+ OPTIONS(
+    'sink.committer-cpu' = '0.25',
+    'sink.committer-memory' = '256 mb',
+    'sink.committer-offheap-memory' = '64 mb',
+    'sink.committer-managed-memory' = '128 mb'
+) */
+SELECT * FROM source_table;
+```
+
+These settings apply to ordinary global committers and combined CDC 
multi-table committers,
+including database synchronization table options. An explicit committer 
resource group uses
+its own budgets independently of the writer group. Leaving the new options 
unset preserves
+existing resource configuration and downstream slot sharing.
+
+Each budget is a resource request for a shared slot of the committer group, 
not a total across
+committer subtasks or a guaranteed allocation to one operator. Allocation 
follows Flink's
+[fine-grained resource 
management](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/finegrained_resource/)
+requirements and available resources. Declaring a managed budget does not 
introduce an allocator
+or managed memory consumer, or change the writer's allocator and allocation 
weight.
+
+When `sink.coordinator-commit.enabled` is enabled, commits run in the writer's
+`OperatorCoordinator` on the JobManager. That path has no global committer 
operator, so these
+slot sharing group settings do not configure its resources.
+
 ## Setting dynamic options
 
 Dynamic options tune a query or a subsequently submitted job without changing 
the options
diff --git a/docs/generated/flink_connector_configuration.html 
b/docs/generated/flink_connector_configuration.html
index 915de83b78..6cc457a264 100644
--- a/docs/generated/flink_connector_configuration.html
+++ b/docs/generated/flink_connector_configuration.html
@@ -272,6 +272,18 @@ under the License.
             <td>MemorySize</td>
             <td>Sink committer memory to control heap memory of global 
committer.</td>
         </tr>
+        <tr>
+            <td><h5>sink.committer-offheap-memory</h5></td>
+            <td style="word-wrap: break-word;">(none)</td>
+            <td>MemorySize</td>
+            <td>Task off-heap memory resource budget for the committer slot 
sharing group. Must be positive and requires sink.committer-memory.</td>
+        </tr>
+        <tr>
+            <td><h5>sink.committer-managed-memory</h5></td>
+            <td style="word-wrap: break-word;">(none)</td>
+            <td>MemorySize</td>
+            <td>Managed memory resource budget for the committer slot sharing 
group. Must be positive and requires sink.committer-memory.</td>
+        </tr>
         <tr>
             <td><h5>sink.committer-operator-chaining</h5></td>
             <td style="word-wrap: break-word;">true</td>
diff --git 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSink.java
 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSink.java
index 235b4ffc8c..f1a171eded 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSink.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSink.java
@@ -51,6 +51,7 @@ import java.io.Serializable;
 import java.util.Collections;
 
 import static 
org.apache.paimon.flink.sink.FlinkSink.assertStreamingConfiguration;
+import static 
org.apache.paimon.flink.sink.FlinkSink.configureCommitterSlotSharingGroup;
 import static org.apache.paimon.flink.sink.FlinkSink.configureSlotSharingGroup;
 import static 
org.apache.paimon.flink.utils.ParallelismUtils.forwardParallelism;
 
@@ -76,6 +77,8 @@ public class FlinkCdcMultiTableSink implements Serializable {
     @Nullable private final MemorySize writeOffHeapMemory;
     private final double commitCpuCores;
     @Nullable private final MemorySize commitHeapMemory;
+    @Nullable private final MemorySize commitManagedMemory;
+    @Nullable private final MemorySize commitOffHeapMemory;
     private final String commitUser;
     @Nullable private final String databaseName;
     private boolean eagerInit = false;
@@ -105,6 +108,8 @@ public class FlinkCdcMultiTableSink implements Serializable 
{
         this.writeOffHeapMemory = null;
         this.commitCpuCores = commitCpuCores;
         this.commitHeapMemory = commitHeapMemory;
+        this.commitManagedMemory = null;
+        this.commitOffHeapMemory = null;
         this.commitUser = commitUser;
         this.eagerInit = eagerInit;
         this.tableFilter = tableFilter;
@@ -170,6 +175,36 @@ public class FlinkCdcMultiTableSink implements 
Serializable {
             String commitUser,
             boolean eagerInit,
             TableFilter tableFilter) {
+        this(
+                catalogLoader,
+                databaseName,
+                writeCpuCores,
+                writeHeapMemory,
+                writeManagedMemory,
+                writeOffHeapMemory,
+                commitCpuCores,
+                commitHeapMemory,
+                null,
+                null,
+                commitUser,
+                eagerInit,
+                tableFilter);
+    }
+
+    public FlinkCdcMultiTableSink(
+            CatalogLoader catalogLoader,
+            String databaseName,
+            double writeCpuCores,
+            @Nullable MemorySize writeHeapMemory,
+            @Nullable MemorySize writeManagedMemory,
+            @Nullable MemorySize writeOffHeapMemory,
+            double commitCpuCores,
+            @Nullable MemorySize commitHeapMemory,
+            @Nullable MemorySize commitManagedMemory,
+            @Nullable MemorySize commitOffHeapMemory,
+            String commitUser,
+            boolean eagerInit,
+            TableFilter tableFilter) {
         this.catalogLoader = catalogLoader;
         this.databaseName = Preconditions.checkNotNull(databaseName);
         this.writeCpuCores = writeCpuCores;
@@ -178,6 +213,8 @@ public class FlinkCdcMultiTableSink implements Serializable 
{
         this.writeOffHeapMemory = writeOffHeapMemory;
         this.commitCpuCores = commitCpuCores;
         this.commitHeapMemory = commitHeapMemory;
+        this.commitManagedMemory = commitManagedMemory;
+        this.commitOffHeapMemory = commitOffHeapMemory;
         this.commitUser = commitUser;
         this.eagerInit = eagerInit;
         this.tableFilter = tableFilter;
@@ -272,7 +309,12 @@ public class FlinkCdcMultiTableSink implements 
Serializable {
                                 createCommitterFactory(tableFilter),
                                 createCommittableStateManager()));
         forwardParallelism(committed, shuffled);
-        configureSlotSharingGroup(committed, commitCpuCores, commitHeapMemory);
+        configureCommitterSlotSharingGroup(
+                committed,
+                commitCpuCores,
+                commitHeapMemory,
+                commitManagedMemory,
+                commitOffHeapMemory);
         return committed.sinkTo(new 
DiscardingSink<>()).name("end").setParallelism(1);
     }
 
diff --git 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcSyncDatabaseSinkBuilder.java
 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcSyncDatabaseSinkBuilder.java
index 098879e9bc..b94d4a501e 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcSyncDatabaseSinkBuilder.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/sink/cdc/FlinkCdcSyncDatabaseSinkBuilder.java
@@ -73,6 +73,8 @@ public class FlinkCdcSyncDatabaseSinkBuilder<T> {
     @Nullable private MemorySize writerOffHeapMemory;
     private double committerCpu;
     @Nullable private MemorySize committerMemory;
+    @Nullable private MemorySize committerManagedMemory;
+    @Nullable private MemorySize committerOffHeapMemory;
 
     // Paimon catalog used to check and create tables. There will be two
     //     places where this catalog is used. 1) in processing function,
@@ -117,6 +119,10 @@ public class FlinkCdcSyncDatabaseSinkBuilder<T> {
         this.writerOffHeapMemory = 
options.get(FlinkConnectorOptions.SINK_WRITER_OFFHEAP_MEMORY);
         this.committerCpu = 
options.get(FlinkConnectorOptions.SINK_COMMITTER_CPU);
         this.committerMemory = 
options.get(FlinkConnectorOptions.SINK_COMMITTER_MEMORY);
+        this.committerManagedMemory =
+                
options.get(FlinkConnectorOptions.SINK_COMMITTER_MANAGED_MEMORY);
+        this.committerOffHeapMemory =
+                
options.get(FlinkConnectorOptions.SINK_COMMITTER_OFFHEAP_MEMORY);
         this.commitUser = createCommitUser(options);
         return this;
     }
@@ -199,6 +205,8 @@ public class FlinkCdcSyncDatabaseSinkBuilder<T> {
                         writerOffHeapMemory,
                         committerCpu,
                         committerMemory,
+                        committerManagedMemory,
+                        committerOffHeapMemory,
                         commitUser,
                         eagerInit,
                         tableFilter);
diff --git 
a/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSinkTest.java
 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSinkTest.java
index 7f61b83812..32352ce94a 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSinkTest.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/sink/cdc/FlinkCdcMultiTableSinkTest.java
@@ -37,6 +37,7 @@ import 
org.apache.flink.streaming.api.transformations.PartitionTransformation;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 import org.junit.jupiter.params.provider.NullSource;
 import org.junit.jupiter.params.provider.ValueSource;
 
@@ -270,4 +271,111 @@ public class FlinkCdcMultiTableSinkTest {
                                         null))
                 .isInstanceOf(NullPointerException.class);
     }
+
+    @ParameterizedTest
+    @CsvSource({
+        "64 mb, 128 mb, 67108864, 134217728",
+        "1536 kb, , 1572864, 0",
+        ", 512 kb, 0, 524288"
+    })
+    public void testDatabaseBuilderPropagatesCommitterResources(
+            String offHeap,
+            String managed,
+            long offHeapBytes,
+            long managedBytes,
+            @TempDir java.nio.file.Path tempDir) {
+        Options options = new Options();
+        options.setString("sink.writer-cpu", "2.5");
+        options.setString("sink.writer-memory", "512 mb");
+        options.setString("sink.writer-offheap-memory", "32 mb");
+        options.setString("sink.writer-managed-memory", "16 mb");
+        options.setString("sink.committer-cpu", "0.25");
+        options.setString("sink.committer-memory", "256 mb");
+        if (offHeap != null) {
+            options.setString("sink.committer-offheap-memory", offHeap);
+        }
+        if (managed != null) {
+            options.setString("sink.committer-managed-memory", managed);
+        }
+        StreamGraph graph = databaseGraph(options, tempDir);
+        ResourceProfile writer = graph.getSlotSharingGroupResource("CDC 
MultiplexWriter").get();
+        
assertThat(writer.getCpuCores().getValue().doubleValue()).isEqualTo(2.5);
+        assertThat(writer.getTaskHeapMemory().getMebiBytes()).isEqualTo(512);
+        assertThat(writer.getTaskOffHeapMemory().getMebiBytes()).isEqualTo(32);
+        assertThat(writer.getManagedMemory().getMebiBytes()).isEqualTo(16);
+        ResourceProfile committer =
+                graph.getSlotSharingGroupResource("Multiplex Global 
Committer").get();
+        
assertThat(committer.getCpuCores().getValue().doubleValue()).isEqualTo(0.25);
+        
assertThat(committer.getTaskHeapMemory().getMebiBytes()).isEqualTo(256);
+        
assertThat(committer.getTaskOffHeapMemory().getBytes()).isEqualTo(offHeapBytes);
+        
assertThat(committer.getManagedMemory().getBytes()).isEqualTo(managedBytes);
+        
assertThat(graph.getJobGraph().getVerticesSortedTopologicallyFromSources())
+                .filteredOn(vertex -> vertex.getName().startsWith("Multiplex 
Global Committer"))
+                .singleElement()
+                .satisfies(
+                        vertex ->
+                                
assertThat(vertex.getSlotSharingGroup().getResourceProfile())
+                                        .isEqualTo(committer));
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"sink.committer-offheap-memory", 
"sink.committer-managed-memory"})
+    public void testCommitterMemoryRequiresCommitterHeap(
+            String option, @TempDir java.nio.file.Path tempDir) {
+        Options options = new Options();
+        options.setString("sink.writer-memory", "512 mb");
+        options.setString(option, "128 mb");
+        assertThatThrownBy(() -> databaseGraph(options, tempDir))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining(option)
+                .hasMessageContaining("sink.committer-memory")
+                .hasMessageNotContaining("sink.writer-");
+    }
+
+    @Test
+    public void testLegacyOffHeapConstructorPreservesCommitterResources() {
+        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+        new FlinkCdcMultiTableSink(
+                        () -> FlinkCatalogFactory.createPaimonCatalog(new 
Options()),
+                        "test_db",
+                        2.5,
+                        MemorySize.ofMebiBytes(512),
+                        MemorySize.ofMebiBytes(16),
+                        MemorySize.ofMebiBytes(32),
+                        0.25,
+                        MemorySize.ofMebiBytes(256),
+                        "test-user",
+                        false,
+                        null)
+                .sinkFrom(
+                        env.fromData(
+                                CdcMultiplexRecord.class, new 
CdcMultiplexRecord("", "", null)));
+        ResourceProfile resources =
+                env.getStreamGraph()
+                        .getSlotSharingGroupResource("Multiplex Global 
Committer")
+                        .get();
+        
assertThat(resources.getCpuCores().getValue().doubleValue()).isEqualTo(0.25);
+        
assertThat(resources.getTaskHeapMemory().getMebiBytes()).isEqualTo(256);
+        assertThat(resources.getTaskOffHeapMemory().getBytes()).isZero();
+        assertThat(resources.getManagedMemory().getBytes()).isZero();
+    }
+
+    private StreamGraph databaseGraph(Options options, java.nio.file.Path 
tempDir) {
+        Options catalogOptions = new Options();
+        catalogOptions.setString("warehouse", tempDir.toString());
+        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+        new FlinkCdcSyncDatabaseSinkBuilder<TestCdcEvent>()
+                .withInput(
+                        env.fromData(
+                                TestCdcEvent.class,
+                                new TestCdcEvent("t", Collections.emptyList(), 
0)))
+                .withParserFactory(TestCdcEventParser::new)
+                .withTableOptions(options)
+                .withDatabase("test_db")
+                .withCatalogLoader(() -> 
FlinkCatalogFactory.createPaimonCatalog(catalogOptions))
+                .withTypeMapping(TypeMapping.defaultMapping())
+                .withMode(MultiTablesSinkMode.COMBINED)
+                .build();
+        return env.getStreamGraph();
+    }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java
index 6d2fa392f7..ae1486be08 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkConnectorOptions.java
@@ -397,6 +397,22 @@ public class FlinkConnectorOptions {
                     .withDescription(
                             "Sink committer memory to control heap memory of 
global committer.");
 
+    public static final ConfigOption<MemorySize> SINK_COMMITTER_MANAGED_MEMORY 
=
+            ConfigOptions.key("sink.committer-managed-memory")
+                    .memoryType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Managed memory resource budget for the committer 
slot sharing group. "
+                                    + "Must be positive and requires 
sink.committer-memory.");
+
+    public static final ConfigOption<MemorySize> SINK_COMMITTER_OFFHEAP_MEMORY 
=
+            ConfigOptions.key("sink.committer-offheap-memory")
+                    .memoryType()
+                    .noDefaultValue()
+                    .withDescription(
+                            "Task off-heap memory resource budget for the 
committer slot sharing group. "
+                                    + "Must be positive and requires 
sink.committer-memory.");
+
     public static final ConfigOption<Boolean> SINK_COMMITTER_OPERATOR_CHAINING 
=
             ConfigOptions.key("sink.committer-operator-chaining")
                     .booleanType()
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/FlinkSink.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/FlinkSink.java
index a3e8621ec1..3b251e94e6 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/FlinkSink.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/FlinkSink.java
@@ -25,6 +25,7 @@ import 
org.apache.paimon.flink.compact.changelog.ChangelogCompactSortOperator;
 import 
org.apache.paimon.flink.compact.changelog.ChangelogCompactWorkerOperator;
 import org.apache.paimon.flink.compact.changelog.ChangelogTaskTypeInfo;
 import org.apache.paimon.manifest.ManifestCommittable;
+import org.apache.paimon.options.ConfigOption;
 import org.apache.paimon.options.MemorySize;
 import org.apache.paimon.options.Options;
 import org.apache.paimon.table.BucketMode;
@@ -59,7 +60,9 @@ import static 
org.apache.paimon.flink.FlinkConnectorOptions.END_INPUT_WATERMARK;
 import static org.apache.paimon.flink.FlinkConnectorOptions.PRECOMMIT_COMPACT;
 import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_AUTO_TAG_FOR_SAVEPOINT;
 import static org.apache.paimon.flink.FlinkConnectorOptions.SINK_COMMITTER_CPU;
+import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_COMMITTER_MANAGED_MEMORY;
 import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_COMMITTER_MEMORY;
+import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_COMMITTER_OFFHEAP_MEMORY;
 import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_COMMITTER_OPERATOR_CHAINING;
 import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_MANAGED_WRITER_BUFFER_MEMORY;
 import static 
org.apache.paimon.flink.FlinkConnectorOptions.SINK_OPERATOR_UID_SUFFIX;
@@ -291,53 +294,75 @@ public abstract class FlinkSink<T> implements 
Serializable {
         if (!options.get(SINK_COMMITTER_OPERATOR_CHAINING)) {
             committed = committed.startNewChain();
         }
-        configureSlotSharingGroup(
-                committed, options.get(SINK_COMMITTER_CPU), 
options.get(SINK_COMMITTER_MEMORY));
+        configureCommitterSlotSharingGroup(
+                committed,
+                options.get(SINK_COMMITTER_CPU),
+                options.get(SINK_COMMITTER_MEMORY),
+                options.get(SINK_COMMITTER_MANAGED_MEMORY),
+                options.get(SINK_COMMITTER_OFFHEAP_MEMORY));
         return committed.sinkTo(new 
PaimonDiscardingSink<>(table)).name("end").setParallelism(1);
     }
 
     public static void configureSlotSharingGroup(
             SingleOutputStreamOperator<?> operator,
             double cpuCores,
-            @Nullable MemorySize heapMemory) {
-        configureSlotSharingGroup(operator, cpuCores, heapMemory, null);
+            @Nullable MemorySize heapMemory,
+            @Nullable MemorySize managedMemory,
+            @Nullable MemorySize offHeapMemory) {
+        applySlotSharingGroupResources(
+                operator,
+                cpuCores,
+                heapMemory,
+                managedMemory,
+                offHeapMemory,
+                SINK_WRITER_MEMORY,
+                SINK_WRITER_MANAGED_MEMORY,
+                SINK_WRITER_OFFHEAP_MEMORY);
     }
 
-    public static void configureSlotSharingGroup(
+    public static void configureCommitterSlotSharingGroup(
             SingleOutputStreamOperator<?> operator,
             double cpuCores,
             @Nullable MemorySize heapMemory,
-            @Nullable MemorySize managedMemory) {
-        configureSlotSharingGroup(operator, cpuCores, heapMemory, 
managedMemory, null);
+            @Nullable MemorySize managedMemory,
+            @Nullable MemorySize offHeapMemory) {
+        applySlotSharingGroupResources(
+                operator,
+                cpuCores,
+                heapMemory,
+                managedMemory,
+                offHeapMemory,
+                SINK_COMMITTER_MEMORY,
+                SINK_COMMITTER_MANAGED_MEMORY,
+                SINK_COMMITTER_OFFHEAP_MEMORY);
     }
 
-    public static void configureSlotSharingGroup(
+    private static void applySlotSharingGroupResources(
             SingleOutputStreamOperator<?> operator,
             double cpuCores,
             @Nullable MemorySize heapMemory,
             @Nullable MemorySize managedMemory,
-            @Nullable MemorySize offHeapMemory) {
+            @Nullable MemorySize offHeapMemory,
+            ConfigOption<MemorySize> heapOption,
+            ConfigOption<MemorySize> managedOption,
+            ConfigOption<MemorySize> offHeapOption) {
         if (managedMemory != null) {
             checkArgument(
                     heapMemory != null,
-                    "'%s' requires '%s' to configure the writer slot sharing 
group.",
-                    SINK_WRITER_MANAGED_MEMORY.key(),
-                    SINK_WRITER_MEMORY.key());
+                    "'%s' requires '%s' to configure the slot sharing group.",
+                    managedOption.key(),
+                    heapOption.key());
             checkArgument(
-                    managedMemory.getBytes() > 0,
-                    "'%s' must be positive.",
-                    SINK_WRITER_MANAGED_MEMORY.key());
+                    managedMemory.getBytes() > 0, "'%s' must be positive.", 
managedOption.key());
         }
         if (offHeapMemory != null) {
             checkArgument(
                     heapMemory != null,
-                    "'%s' requires '%s' to configure the writer slot sharing 
group.",
-                    SINK_WRITER_OFFHEAP_MEMORY.key(),
-                    SINK_WRITER_MEMORY.key());
+                    "'%s' requires '%s' to configure the slot sharing group.",
+                    offHeapOption.key(),
+                    heapOption.key());
             checkArgument(
-                    offHeapMemory.getBytes() > 0,
-                    "'%s' must be positive.",
-                    SINK_WRITER_OFFHEAP_MEMORY.key());
+                    offHeapMemory.getBytes() > 0, "'%s' must be positive.", 
offHeapOption.key());
         }
         if (heapMemory == null) {
             return;
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/CommitterMemoryTest.java
similarity index 53%
copy from 
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
copy to 
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/CommitterMemoryTest.java
index 5c7da97f72..5808964316 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/CommitterMemoryTest.java
@@ -27,10 +27,8 @@ import org.apache.flink.core.memory.ManagedMemoryUseCase;
 import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
 import org.apache.flink.runtime.jobgraph.JobVertex;
 import org.apache.flink.streaming.api.datastream.DataStream;
-import org.apache.flink.streaming.api.datastream.DataStreamSource;
 import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
 import org.apache.flink.streaming.api.graph.StreamGraph;
-import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.CsvSource;
 import org.junit.jupiter.params.provider.ValueSource;
@@ -40,161 +38,182 @@ import java.util.Collections;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-/** Tests for the writer slot sharing group's task off-heap memory budget. */
-class WriterOffHeapMemoryTest extends CommitterTestBase {
+/** Tests for the committer slot sharing group's memory resources. */
+class CommitterMemoryTest extends CommitterTestBase {
 
     @ParameterizedTest
-    @CsvSource({"128 mb, 134217728", "1 gb, 1073741824", "1536 kb, 1572864", 
"512 kb, 524288"})
-    void testOffHeapResourcesPreserveBytes(String offHeapMemory, long 
expectedBytes)
-            throws Exception {
+    @CsvSource({
+        "128 mb, , 134217728, 0",
+        "1 gb, , 1073741824, 0",
+        "1536 kb, , 1572864, 0",
+        "512 kb, , 524288, 0",
+        ", 128 mb, 0, 134217728",
+        ", 1 gb, 0, 1073741824",
+        ", 1536 kb, 0, 1572864",
+        ", 512 kb, 0, 524288"
+    })
+    void testMemoryResourcesPreserveBytes(
+            String offHeap, String managed, long offHeapBytes, long 
managedBytes) throws Exception {
         FileStoreTable table =
                 createFileStoreTable(
                         options -> {
-                            options.setString("sink.writer-memory", "512 mb");
-                            options.setString("sink.writer-offheap-memory", 
offHeapMemory);
+                            options.setString("sink.committer-memory", "256 
mb");
+                            if (offHeap != null) {
+                                
options.setString("sink.committer-offheap-memory", offHeap);
+                            }
+                            if (managed != null) {
+                                
options.setString("sink.committer-managed-memory", managed);
+                            }
                         });
         StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
-        DataStream<Committable> written = write(env, table);
-        StreamGraph graph = env.getStreamGraph();
-        String writerGroup = written.getTransformation().getName();
-        ResourceProfile resources = 
graph.getSlotSharingGroupResource(writerGroup).get();
-        
assertThat(resources.getTaskOffHeapMemory().getBytes()).isEqualTo(expectedBytes);
-        
assertThat(resources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(512));
-        assertThat(resources.getManagedMemory()).isEqualTo(MemorySize.ZERO);
+        write(env, table);
+        ResourceProfile resources = committerResources(env.getStreamGraph());
+        
assertThat(resources.getTaskOffHeapMemory().getBytes()).isEqualTo(offHeapBytes);
+        
assertThat(resources.getManagedMemory().getBytes()).isEqualTo(managedBytes);
+        
assertThat(resources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(256));
         
assertThat(resources.getCpuCores().getValue().doubleValue()).isEqualTo(1.0);
-        graph.getStreamNodes().stream()
-                .filter(n -> !n.getOperatorName().startsWith("Source:"))
-                .forEach(n -> 
assertThat(n.getSlotSharingGroup()).isEqualTo(writerGroup));
-        
assertThat(writerVertex(graph).getSlotSharingGroup().getResourceProfile())
-                .isEqualTo(resources);
     }
 
     @ParameterizedTest
     @ValueSource(booleans = {false, true})
-    void testOffHeapAndManagedResourcesAreIndependent(boolean 
managedAllocator) throws Exception {
+    void testWriterAndCommitterResourcesAreIndependent(boolean 
managedAllocator) throws Exception {
         FileStoreTable table =
                 createFileStoreTable(
                         options -> {
                             options.setString("sink.writer-cpu", "2.5");
                             options.setString("sink.writer-memory", "512 mb");
-                            options.setString("sink.writer-offheap-memory", 
"128 mb");
-                            options.setString("sink.writer-managed-memory", 
"64 mb");
+                            options.setString("sink.writer-offheap-memory", 
"32 mb");
+                            options.setString("sink.writer-managed-memory", 
"16 mb");
                             options.setString(
                                     "sink.use-managed-memory-allocator",
                                     String.valueOf(managedAllocator));
                             
options.setString("sink.managed.writer-buffer-memory", "256 mb");
-                            options.setString("sink.committer-memory", "32 
mb");
                             options.setString("sink.committer-cpu", "0.25");
+                            options.setString("sink.committer-memory", "256 
mb");
+                            options.setString("sink.committer-offheap-memory", 
"64 mb");
+                            options.setString("sink.committer-managed-memory", 
"128 mb");
                         });
         StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
         DataStream<Committable> written = write(env, table);
         StreamGraph graph = env.getStreamGraph();
-        ResourceProfile writerResources =
+        ResourceProfile writer =
                 
graph.getSlotSharingGroupResource(written.getTransformation().getName()).get();
-        
assertThat(writerResources.getTaskOffHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(128));
-        
assertThat(writerResources.getManagedMemory()).isEqualTo(MemorySize.ofMebiBytes(64));
-        
assertThat(writerResources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(512));
-        
assertThat(writerResources.getCpuCores().getValue().doubleValue()).isEqualTo(2.5);
+        
assertThat(writer.getCpuCores().getValue().doubleValue()).isEqualTo(2.5);
+        
assertThat(writer.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(512));
+        
assertThat(writer.getTaskOffHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(32));
+        
assertThat(writer.getManagedMemory()).isEqualTo(MemorySize.ofMebiBytes(16));
         
assertThat(written.getTransformation().getManagedMemoryOperatorScopeUseCaseWeights())
                 .isEqualTo(
                         managedAllocator
                                 ? 
Collections.singletonMap(ManagedMemoryUseCase.OPERATOR, 256)
                                 : Collections.emptyMap());
-        String committerGroup =
-                graph.getStreamNodes().stream()
-                        .filter(n -> n.getOperatorName().startsWith("Global 
Committer"))
-                        .findFirst()
-                        .get()
-                        .getSlotSharingGroup();
-        ResourceProfile committerResources =
-                graph.getSlotSharingGroupResource(committerGroup).get();
-        
assertThat(committerResources.getTaskOffHeapMemory()).isEqualTo(MemorySize.ZERO);
-        
assertThat(committerResources.getManagedMemory()).isEqualTo(MemorySize.ZERO);
-        
assertThat(committerResources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(32));
-        
assertThat(committerResources.getCpuCores().getValue().doubleValue()).isEqualTo(0.25);
+        ResourceProfile committer = committerResources(graph);
+        
assertThat(committer.getCpuCores().getValue().doubleValue()).isEqualTo(0.25);
+        
assertThat(committer.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(256));
+        
assertThat(committer.getTaskOffHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(64));
+        
assertThat(committer.getManagedMemory()).isEqualTo(MemorySize.ofMebiBytes(128));
     }
 
     @ParameterizedTest
     @ValueSource(booleans = {false, true})
-    void testAbsentOptionPreservesExistingResources(boolean explicitHeap) 
throws Exception {
+    void testAbsentOptionsPreserveExistingResources(boolean explicitHeap) 
throws Exception {
         FileStoreTable table =
                 createFileStoreTable(
                         options -> {
                             if (explicitHeap) {
-                                options.setString("sink.writer-memory", "512 
mb");
+                                options.setString("sink.committer-cpu", 
"0.25");
+                                options.setString("sink.committer-memory", 
"256 mb");
                             }
                         });
         StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
         write(env, table);
+        StreamGraph graph = env.getStreamGraph();
         ResourceProfile resources =
-                
writerVertex(env.getStreamGraph()).getSlotSharingGroup().getResourceProfile();
+                
committerVertex(graph).getSlotSharingGroup().getResourceProfile();
         if (explicitHeap) {
+            assertThat(resources).isEqualTo(committerResources(graph));
+            
assertThat(resources.getCpuCores().getValue().doubleValue()).isEqualTo(0.25);
+            
assertThat(resources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(256));
             
assertThat(resources.getTaskOffHeapMemory()).isEqualTo(MemorySize.ZERO);
+            
assertThat(resources.getManagedMemory()).isEqualTo(MemorySize.ZERO);
         } else {
             assertThat(resources).isEqualTo(ResourceProfile.UNKNOWN);
         }
     }
 
-    @Test
-    void testLegacyResourceOverloadPreservesManagedMemory() {
-        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
-        DataStreamSource<Integer> operator = env.fromData(1);
-        FlinkSink.configureSlotSharingGroup(
-                operator,
-                2.5,
-                org.apache.paimon.options.MemorySize.ofMebiBytes(512),
-                org.apache.paimon.options.MemorySize.ofMebiBytes(64));
-        operator.print();
-        ResourceProfile resources =
-                
env.getStreamGraph().getSlotSharingGroupResource(operator.getName()).get();
-        
assertThat(resources.getTaskOffHeapMemory()).isEqualTo(MemorySize.ZERO);
-        
assertThat(resources.getManagedMemory()).isEqualTo(MemorySize.ofMebiBytes(64));
-        
assertThat(resources.getTaskHeapMemory()).isEqualTo(MemorySize.ofMebiBytes(512));
-        
assertThat(resources.getCpuCores().getValue().doubleValue()).isEqualTo(2.5);
-    }
-
-    @Test
-    void testOffHeapMemoryRequiresHeap() throws Exception {
+    @ParameterizedTest
+    @ValueSource(strings = {"sink.committer-offheap-memory", 
"sink.committer-managed-memory"})
+    void testMemoryRequiresCommitterHeap(String option) throws Exception {
         FileStoreTable table =
                 createFileStoreTable(
-                        options -> 
options.setString("sink.writer-offheap-memory", "128 mb"));
+                        options -> {
+                            // Writer heap must not satisfy the committer's 
prerequisite.
+                            options.setString("sink.writer-memory", "512 mb");
+                            options.setString(option, "128 mb");
+                        });
         assertThatThrownBy(() -> 
write(StreamExecutionEnvironment.getExecutionEnvironment(), table))
                 .isInstanceOf(IllegalArgumentException.class)
-                .hasMessageContaining("sink.writer-offheap-memory")
-                .hasMessageContaining("sink.writer-memory");
+                .hasMessageContaining(option)
+                .hasMessageContaining("sink.committer-memory")
+                .hasMessageNotContaining("sink.writer-");
     }
 
     @ParameterizedTest
-    @ValueSource(strings = {"0 b", "-1 mb", "invalid"})
-    void testInvalidOffHeapMemoryIsRejected(String offHeapMemory) throws 
Exception {
+    @CsvSource({
+        "sink.committer-offheap-memory, 0 b",
+        "sink.committer-offheap-memory, -1 mb",
+        "sink.committer-offheap-memory, invalid",
+        "sink.committer-managed-memory, 0 b",
+        "sink.committer-managed-memory, -1 mb",
+        "sink.committer-managed-memory, invalid"
+    })
+    void testInvalidMemoryIsRejected(String option, String value) throws 
Exception {
         FileStoreTable table =
                 createFileStoreTable(
                         options -> {
-                            options.setString("sink.writer-memory", "512 mb");
-                            options.setString("sink.writer-offheap-memory", 
offHeapMemory);
+                            options.setString("sink.committer-memory", "256 
mb");
+                            options.setString(option, value);
                         });
         assertThatThrownBy(() -> 
write(StreamExecutionEnvironment.getExecutionEnvironment(), table))
                 .isInstanceOf(IllegalArgumentException.class)
-                .hasMessageContaining("sink.writer-offheap-memory");
+                .hasMessageContaining(option)
+                .hasMessageNotContaining("sink.writer-");
     }
 
     private DataStream<Committable> write(StreamExecutionEnvironment env, 
FileStoreTable table) {
-        DataStream<InternalRow> source =
-                env.fromData(InternalRow.class, GenericRow.of(1, 1L))
-                        .name("upstream")
-                        .slotSharingGroup("main");
+        DataStream<InternalRow> input =
+                env.fromData(InternalRow.class, GenericRow.of(1, 
1L)).slotSharingGroup("main");
         FlinkSink<InternalRow> sink = new FixedBucketSink(table, null);
-        DataStream<Committable> written = sink.doWrite(source, "test-user", 2);
-        sink.doCommit(written, "test-user");
+        DataStream<Committable> written = sink.doWrite(input, "test-user", 2);
+        assertThat(
+                        sink.doCommit(written, "test-user")
+                                .getTransformation()
+                                .getInputs()
+                                .get(0)
+                                .getManagedMemoryOperatorScopeUseCaseWeights())
+                .isEmpty();
         return written;
     }
 
-    private JobVertex writerVertex(StreamGraph graph) {
+    private ResourceProfile committerResources(StreamGraph graph) {
+        String group =
+                graph.getStreamNodes().stream()
+                        .filter(n -> n.getOperatorName().startsWith("Global 
Committer"))
+                        .findFirst()
+                        .get()
+                        .getSlotSharingGroup();
+        ResourceProfile resources = 
graph.getSlotSharingGroupResource(group).get();
+        
assertThat(committerVertex(graph).getSlotSharingGroup().getResourceProfile())
+                .isEqualTo(resources);
+        return resources;
+    }
+
+    private JobVertex committerVertex(StreamGraph graph) {
         for (JobVertex vertex : graph.getJobGraph().getVertices()) {
-            if (vertex.getName().startsWith("Writer")) {
+            if (vertex.getName().startsWith("Global Committer")) {
                 return vertex;
             }
         }
-        throw new AssertionError("Writer vertex not found");
+        throw new AssertionError("Committer vertex not found");
     }
 }
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
index 5c7da97f72..39f2633937 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/sink/WriterOffHeapMemoryTest.java
@@ -143,7 +143,8 @@ class WriterOffHeapMemoryTest extends CommitterTestBase {
                 operator,
                 2.5,
                 org.apache.paimon.options.MemorySize.ofMebiBytes(512),
-                org.apache.paimon.options.MemorySize.ofMebiBytes(64));
+                org.apache.paimon.options.MemorySize.ofMebiBytes(64),
+                null);
         operator.print();
         ResourceProfile resources =
                 
env.getStreamGraph().getSlotSharingGroupResource(operator.getName()).get();

Reply via email to