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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to