You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Guosmilesmile (via GitHub)" <gi...@apache.org> on 2026/07/16 11:09:53 UTC

[PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Guosmilesmile opened a new pull request, #17251:
URL: https://github.com/apache/iceberg/pull/17251

   Closes https://github.com/apache/iceberg/issues/17140
   
   `IcebergSink#addPreCommitTopology` uses a `.global()` shuffle to force all committables to subtask 0 of the downstream committer operator, so that commits only happen on a single subtask.
   
   Even though only subtask 0 will ever receive a `CommitRequest`, every committer subtask still eagerly loads the Iceberg table and creates a worker thread pool in its constructor.
   
   This pr add code to avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 . 


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#issuecomment-5068494332

   Merged to main.
   Thanks @Guosmilesmile for the PR, @mxm for the review and @krisnaru for reporting!


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary merged PR #17251:
URL: https://github.com/apache/iceberg/pull/17251


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "Guosmilesmile (via GitHub)" <gi...@apache.org>.
Guosmilesmile commented on code in PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#discussion_r3595142097


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergCommitter.java:
##########
@@ -88,31 +89,43 @@ class IcebergCommitter implements Committer<IcebergCommittable> {
       int workerPoolSize,
       String sinkId,
       IcebergFilesCommitterMetrics committerMetrics,
-      boolean tableMaintenanceEnabled) {
+      boolean tableMaintenanceEnabled,
+      int subtaskId) {
     this.branch = branch;
     this.snapshotProperties = snapshotProperties;
     this.replacePartitions = replacePartitions;
     this.committerMetrics = committerMetrics;
     this.tableLoader = tableLoader;
-    if (!tableLoader.isOpen()) {
-      tableLoader.open();
+    this.tableMaintenanceEnabled = tableMaintenanceEnabled;
+    this.subtaskId = subtaskId;
+
+    if (subtaskId == 0) {
+      if (!tableLoader.isOpen()) {
+        tableLoader.open();
+      }
+
+      this.table = tableLoader.loadTable();
+      this.maxContinuousEmptyCommits =
+          PropertyUtil.propertyAsInt(table.properties(), MAX_CONTINUOUS_EMPTY_COMMITS, 10);
+      Preconditions.checkArgument(
+          maxContinuousEmptyCommits > 0, MAX_CONTINUOUS_EMPTY_COMMITS + " must be positive");
+      this.workerPool =
+          ThreadPools.newFixedThreadPool(
+              "iceberg-committer-pool-" + table.name() + "-" + sinkId, workerPoolSize);

Review Comment:
   Right, add  comment on it.



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "Guosmilesmile (via GitHub)" <gi...@apache.org>.
Guosmilesmile commented on code in PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#discussion_r3595143710


##########
flink/v2.1/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergCommitter.java:
##########
@@ -1156,6 +1159,54 @@ public void testDeleteFiles() throws Exception {
     }
   }
 
+  @TestTemplate
+  public void testCommitterOnSubtaskZeroLoadsTable() throws Exception {
+    TableLoader spyLoader = spy(tableLoader);
+    IcebergFilesCommitterMetrics metric = mock(IcebergFilesCommitterMetrics.class);
+    IcebergCommitter committer =
+        new IcebergCommitter(
+            spyLoader, branch, Collections.emptyMap(), false, 10, "sinkId", metric, false, 0);
+
+    verify(spyLoader).open();
+    verify(spyLoader).loadTable();
+
+    committer.close();
+  }
+
+  @TestTemplate
+  public void testCommitterOnNonZeroSubtaskSkipsTableLoad() throws Exception {
+    TableLoader spyLoader = spy(tableLoader);
+    IcebergFilesCommitterMetrics metric = mock(IcebergFilesCommitterMetrics.class);
+    IcebergCommitter committer =
+        new IcebergCommitter(
+            spyLoader, branch, Collections.emptyMap(), false, 10, "sinkId", metric, false, 1);
+
+    verify(spyLoader, never()).open();
+    verify(spyLoader, never()).loadTable();
+
+    committer.close();
+  }

Review Comment:
   Make sense. Change ut to use TestHarness



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "mxm (via GitHub)" <gi...@apache.org>.
mxm commented on code in PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#discussion_r3594940520


##########
flink/v2.1/flink/src/test/java/org/apache/iceberg/flink/sink/TestIcebergCommitter.java:
##########
@@ -1156,6 +1159,54 @@ public void testDeleteFiles() throws Exception {
     }
   }
 
+  @TestTemplate
+  public void testCommitterOnSubtaskZeroLoadsTable() throws Exception {
+    TableLoader spyLoader = spy(tableLoader);
+    IcebergFilesCommitterMetrics metric = mock(IcebergFilesCommitterMetrics.class);
+    IcebergCommitter committer =
+        new IcebergCommitter(
+            spyLoader, branch, Collections.emptyMap(), false, 10, "sinkId", metric, false, 0);
+
+    verify(spyLoader).open();
+    verify(spyLoader).loadTable();
+
+    committer.close();
+  }
+
+  @TestTemplate
+  public void testCommitterOnNonZeroSubtaskSkipsTableLoad() throws Exception {
+    TableLoader spyLoader = spy(tableLoader);
+    IcebergFilesCommitterMetrics metric = mock(IcebergFilesCommitterMetrics.class);
+    IcebergCommitter committer =
+        new IcebergCommitter(
+            spyLoader, branch, Collections.emptyMap(), false, 10, "sinkId", metric, false, 1);
+
+    verify(spyLoader, never()).open();
+    verify(spyLoader, never()).loadTable();
+
+    committer.close();
+  }

Review Comment:
   I would prefer more of an end-to-end test, e.g. using a Minicluster or a TestHarness which utilizes the entire path. This is a critical code path and a simple unit test IMHO is not enough.



##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/IcebergCommitter.java:
##########
@@ -88,31 +89,43 @@ class IcebergCommitter implements Committer<IcebergCommittable> {
       int workerPoolSize,
       String sinkId,
       IcebergFilesCommitterMetrics committerMetrics,
-      boolean tableMaintenanceEnabled) {
+      boolean tableMaintenanceEnabled,
+      int subtaskId) {
     this.branch = branch;
     this.snapshotProperties = snapshotProperties;
     this.replacePartitions = replacePartitions;
     this.committerMetrics = committerMetrics;
     this.tableLoader = tableLoader;
-    if (!tableLoader.isOpen()) {
-      tableLoader.open();
+    this.tableMaintenanceEnabled = tableMaintenanceEnabled;
+    this.subtaskId = subtaskId;
+
+    if (subtaskId == 0) {
+      if (!tableLoader.isOpen()) {
+        tableLoader.open();
+      }
+
+      this.table = tableLoader.loadTable();
+      this.maxContinuousEmptyCommits =
+          PropertyUtil.propertyAsInt(table.properties(), MAX_CONTINUOUS_EMPTY_COMMITS, 10);
+      Preconditions.checkArgument(
+          maxContinuousEmptyCommits > 0, MAX_CONTINUOUS_EMPTY_COMMITS + " must be positive");
+      this.workerPool =
+          ThreadPools.newFixedThreadPool(
+              "iceberg-committer-pool-" + table.name() + "-" + sinkId, workerPoolSize);

Review Comment:
   Can we add a comment why we are only initializing for `subtaskId == 0`?



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "mxm (via GitHub)" <gi...@apache.org>.
mxm commented on PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#issuecomment-5069273105

   Thanks for the PR @Guosmilesmile and thanks for merging @pvary! This still needs backporting @Guosmilesmile.


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0 [iceberg]

Posted by "Guosmilesmile (via GitHub)" <gi...@apache.org>.
Guosmilesmile commented on PR #17251:
URL: https://github.com/apache/iceberg/pull/17251#issuecomment-5069300207

   > Thanks for the PR @Guosmilesmile and thanks for merging @pvary! This still needs backporting @Guosmilesmile.
   
   Thanks,I'll submit the backport later.


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org