Skip to content

Iceberg commit retry backoff - #133240

Merged
alesapin merged 12 commits into
masterfrom
iceberg-commit-retry-backoff
Nov 23, 2026
Merged

alesapin merged 12 commits into
masterfrom
iceberg-commit-retry-backoff

Conversation

@alesapin

@alesapin alesapin commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

  • Merged into: 26.12.1.328-master (included in 26.12 and later)

alesapin and others added 4 commits November 20, 2026 14:29
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
…y-backoff

# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5335349]

Summary: ✅


AI Review

Summary

The PR defers Iceberg metadata initialization until a sink receives rows and adds randomized exponential backoff before retrying conflicting commits. Reviewed head 5335349cadb8492f8e7f3d431329b129fcda828a, including all prior discussion. The earlier schema-corruption findings are addressed in the current code. Two previously dismissed major concerns remain; neither warrants reposting or reopening its thread. No new inline findings.

Missing context / blind spots
  • ⚠️ No built ClickHouse binary is available in this checkout, so runtime regressions and contention measurements were not reproduced locally. The current-head targeted stateless report returned no test results; a completed run of the relevant tests would close this validation gap.
Findings

⚠️ Majors

  • src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1747: The retry wait ignores an expired deadline in timeout_overflow_mode = 'break'. QueryStatus::checkTimeLimit returns false in this mode, but the wait discards it. CancellationChecker does not cancel the query for this mode, and a single executor thread cannot perform its next deadline check until the sink returns. After a conflict, an expired insert can therefore finish the sampled delay, reread metadata, and attempt another commit while retaining its thread and locks. Both backoff settings set to 60000 make the first retry capable of waiting almost a minute. Propagate the failed check out of the wait and retry loop while preserving cleanup of uncommitted files. [dismissed by author -- https://github.com/Iceberg commit retry backoff #133240#discussion_r4643664798] The return value is still ignored in the current code.

  • src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1705: The default retry delays lack evidence under sustained contention. The new test compares metadata listings for two sequential, single-block inserts and never reaches the retry branch. Existing conflict tests establish eventual correctness; the four-stream bulk-write benchmark does not establish the throughput/latency tradeoff when repeated conflicts grow the bound to 5000 ms. Provide reproducible measurements comparing disabled backoff with the defaults, recording metadata listings, completed inserts per second, and insert latency. [dismissed by author -- https://github.com/Iceberg commit retry backoff #133240#discussion_r4643344902] No contention measurements or focused benchmark accompany the current performance claim.

Tests
  • ⚠️ Cover the new planned/current field-ID comparison with a focused regression: preserve a stale planned schema, rename a field and add another under its old name, then assert rejection before a snapshot is published. Include a nested field. Existing 04329_iceberg_insert_stale_schema_field_id_107268 only tests names absent from the current schema; it would still pass if checkFieldIdsKept were removed.
  • ⚠️ Exercise an expired timeout_overflow_mode = 'break' deadline during a forced-conflict backoff, with one executor thread and one insert stream, and verify prompt termination and uncommitted-file cleanup.
  • ⚠️ Supply the contention measurements described above; the empty-sink listing assertion proves only the lazy-initialization benefit.
Final Verdict

Status: ⚠️ Request changes

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.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 20, 2026
@scanhex12 scanhex12 self-assigned this Nov 20, 2026
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]>
@clickhouse-gh clickhouse-gh Bot added the comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... label Nov 20, 2026
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5335349ca with master 3dac6f430 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

123 translation units recompiled, 964 s compile time in total, 123 of them have a recent master baseline.

Job report

alesapin and others added 3 commits November 23, 2026 12:05
…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]>
alesapin and others added 3 commits November 23, 2026 13:21
… 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]>
@alesapin
alesapin added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit b74965f Nov 23, 2026
383 of 384 checks passed
@alesapin
alesapin deleted the iceberg-commit-retry-backoff branch November 23, 2026 21:23
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants