Repository navigation
Iceberg commit retry backoff - #133240
Iceberg commit retry backoff#133240
Conversation
An `IcebergStorageSink` lists the `metadata` directory to find the latest metadata file when it is created and again after every commit lost to a concurrent commit. With many concurrent writers this floods S3 with `ListObjects` requests and leads to `503 Slow Down`. - A sink reads the latest metadata on its first chunk instead of in the constructor. A parallel insert creates `max_insert_threads` sinks, and the ones that receive no data, for example most of the sinks of the nested per-block inserts of a `Distributed` table, no longer list at all. - A commit lost to a concurrent commit is retried after a random delay with an exponentially growing bound, set by the new settings `iceberg_insert_commit_retry_initial_backoff_ms` (10 ms) and `iceberg_insert_commit_retry_max_backoff_ms` (5000 ms), so that the writers that lost the same race do not collide again at once. The new base is read after the delay, in `rebaseOnLatestMetadata`, and no longer after the last failed attempt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-backoff # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-backoff # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
|
Workflow [PR], commit [5335349] Summary: ✅
AI ReviewSummaryThe PR defers Iceberg metadata initialization until a sink receives rows and adds randomized exponential backoff before retrying conflicting commits. Reviewed head Missing context / blind spots
Findings
Tests
Final VerdictStatus: Honor the failed deadline check, add regression coverage for the deadline and field-ID guards, and substantiate the default backoff with contention measurements. Leave the author's dismissed threads closed. |
The delay before a retry of a lost commit was waited in one `sleepForMilliseconds`, so `KILL QUERY` and `max_execution_time` were noticed only after it, up to `iceberg_insert_commit_retry_max_backoff_ms` later. Now it is waited in slices of at most 100 ms with `isCancelled` and `checkTimeLimit` checked between them. #133240 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y chunks `initializeFromLatestMetadata` and `rebaseOnLatestMetadata` looked up and read the latest metadata the same way, so they are one `readLatestMetadata` now: the first read sets up how the data files are written, a later one after a lost commit checks that the schema did not change and rebases the next attempt, keeping the partition spec and the sort order of the first read. `consume` returns early for a chunk without rows, so that such a chunk neither reads the latest metadata nor starts an empty data file. #133240 (comment) #133240 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units123 translation units recompiled, 964 s compile time in total, 123 of them have a recent master baseline. |
…y-backoff # Conflicts: # src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
The sink now reads the latest metadata on the first chunk, after the source started, so the schema could change between the planning of the insert and that read. The columns were matched by name in the latest schema, and a column renamed while another one was added under its name got the field id of the new column: an integer column of the insert was written under the id of a new string field. Like a write of the Java implementation, the columns are now matched in the schema the query planned them with: its id is pinned in the metadata snapshot, which `IDataLakeMetadata::write` receives now, and the schema itself is taken from the `schemas` of the latest metadata, which keeps the earlier schemas. The manifest records that schema, and the sort order is resolved in it. A commit still requires the current schema of its base not to change between attempts. #133240 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e` call of `gtest_delta_kernel` `IDataLakeMetadata::write` takes the metadata snapshot of the insert now, and the unit test still called it with the old arguments. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133240&sha=42696384acb2d661e0b41f3f60a16cb26bdf9534&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29 #133240 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fields The data files are written with the field ids of the schema the insert was planned with now, so an insert planned before a rename commits, and its values land in the renamed field, as with the Java implementation. The test checks that by reading the rows back. The renamed nested field is read as the whole tuple: reading the subcolumn `t.b` of a tuple whose element was renamed fails with `NOT_FOUND_COLUMN_IN_BLOCK` even for the file written before the rename. #133240 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…that denotes another field Writing the data files with the schema the insert was planned with made them unreadable when the schema changed in between: a reader takes the names of the columns in a file from the schema of its snapshot, which is the current schema of the base, so after a rename ORC returned NULL for the stored column and Avro failed. The data files are written with the current schema again, which the snapshot records, and the manifest records it as before. Instead, a column of the insert, or a nested field of it, must still denote the same field id in the current schema as in the schema the insert was planned with. A name given to another field meanwhile, as after a column is renamed and another one is added under its name, rejects the insert before any file is committed. A name absent from the current schema is rejected by `validateIcebergFieldIds` as before. #133240 (comment) #133240 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
… renamed fields" This reverts commit d3a4af0.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Now Iceberg Sink tries to fetch metadata snapshot lazily, when the first chunk of data arrives. Also introduced a settings to enable exponential backoffs for iceberg writes in case of conflicts.
Workflow [PR]
Sync PR [sync-upstream/pr/133240]
Version info
26.12.1.328-master(included in26.12and later)