Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0#17251
Open
Guosmilesmile wants to merge 3 commits into
Open
Flink: Avoid unnecessary TableLoader.loadTable() in IcebergCommitter subtasks > 0#17251Guosmilesmile wants to merge 3 commits into
Guosmilesmile wants to merge 3 commits into
Conversation
4 tasks
mxm
reviewed
Jul 16, 2026
Comment on lines
+1162
to
+1188
| @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(); | ||
| } |
Contributor
There was a problem hiding this 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.
Contributor
Author
There was a problem hiding this comment.
Make sense. Change ut to use TestHarness
Comment on lines
+102
to
+114
| 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); |
Contributor
There was a problem hiding this comment.
Can we add a comment why we are only initializing for subtaskId == 0?
Contributor
Author
There was a problem hiding this comment.
Right, add comment on it.
mxm
approved these changes
Jul 17, 2026
mxm
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks @Guosmilesmile!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17140
IcebergSink#addPreCommitTopologyuses 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 .