Skip to content

Do not roll back an Iceberg commit that may be published - #132317

Open
CheSema wants to merge 41 commits into
masterfrom
s3-conditional-write-outcome
Open

CheSema wants to merge 41 commits into
masterfrom
s3-conditional-write-outcome

Conversation

@CheSema

@CheSema CheSema commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Related: #130811
Related: #130818
Related: #132744

An Iceberg commit could roll back after its vN.metadata.json was stored, e.g. after a lost upload response or a killed INSERT, and leave the table unreadable. Now the storage reports the outcome of the write (WriteBufferFromFileBase::getWriteOutcome). The commit rolls back only when nothing was applied; when the outcome is unknown, it fails with UNKNOWN_STATUS_OF_TRANSACTION and keeps its files.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix an Iceberg table that became unreadable when a commit was rolled back after its new metadata file was stored. When the outcome of the upload is unknown, the query now fails with UNKNOWN_STATUS_OF_TRANSACTION and keeps the files.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132317]

After a lost response only a later attempt tells whether a conditional write
landed. A killed query cut that attempt, so a published Iceberg commit counted
as lost and its rollback deleted the files of the new version. Run a
conditional `PutObject` or `CompleteMultipartUpload`, and the version hint
update after a published commit, under a `QueryCancellationBlocker`.
CheSema added a commit that referenced this pull request Nov 17, 2026
It also fixes a bug on master, so it moves to
#132317, which must merge first.
@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a2193ae]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, distributed plan, targeted) FAIL
test_grpc_protocol/test.py::test_ipv6_select_one FAIL cidb
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) FAIL
05813_iceberg_commit_with_invalid_metadata_compression_level FAIL cidb

AI Review

Summary

Reviewed head a2193ae4b4648ccab4cc8bda2782f1ccf82eb226. The PR tracks storage write outcomes so Iceberg keeps files referenced by potentially published metadata and reports UNKNOWN_STATUS_OF_TRANSACTION when publication cannot be established. The five previously reported implementation defects are addressed; no new inline findings remain. The author's scope decision is accepted: stale version-hint readers and non-atomic OneLake publication remain separately tracked in #133019 and #132744.

Missing context / blind spots
  • ⚠️ No local build directory or prebuilt binary was available, so tests were not run locally. Review evidence consists of code tracing, the supplied regression tests, and available CI reports; relevant unit and integration jobs should confirm execution of the new regressions.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 17, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 17, 2026
When the upload of `vN.metadata.json` was sent and failed without proof
either way, the commit counted as lost, and its rollback deleted the files
that the stored metadata file references. `writeMetadataFile` now throws
`UNKNOWN_STATUS_OF_TRANSACTION` then, and the callers keep the files.
An error of the hint read after the metadata file was published reached
the caller, which rolled back the published version.
@CheSema CheSema changed the title Do not let a killed query cut a conditional S3 write before it learns its outcome Do not roll back an Iceberg commit that may be published Nov 17, 2026
The client records whether an attempt may have been applied and proves
the outcome by the idempotency id. An unproven outcome marks the error,
which keeps its S3 error type. The client no longer blocks cancellation.
An unmarked S3 error proves that nothing was published, so the commit
rolls back instead of keeping orphan files.
An S3 error without the mark, for example from the check after the
upload, made the commit roll back a published version.
Any 3xx or 4xx counted as a refusal, also codes that some clients and
proxies give for no answer, such as 408 or 499.
An attempt on another thread, e.g. of an asynchronous call, would lose
its answer, so the write could be taken for not applied.
It records whether an attempt may have been applied and the outcome of
the write: applied, not applied, or unknown.
The tracker travels in `WriteSettings` to the request that publishes the
object. A conditional write without a tracker is a logical error, and an
exception inside an attempt counts as an attempt that may be applied.
The decision no longer depends on the type of the exception. A commit
killed after only refusals rolls back, and an upload that succeeded is
published even if the check after it fails.
A tracked attempt on another thread now reaches its tracker, and the
HTTP client checks each tracked attempt by the mark in its request.
…quest

The record lives on the request, and a scope private to the client finds
it through the thread. The caller's tracker gets the outcome for now.
`WriteBufferFromFileBase::getWriteOutcome` replaces the tracker that the
caller passed in `WriteSettings`. Iceberg reads it after the write.
The record of the attempts no longer leaves the client, so `ThreadPool`
does not carry it, and requests carry no mark.
`WriteBufferFromS3` reports `NotApplied` when an upload of a part fails,
also when `finalize` is never called.
@CheSema
CheSema marked this pull request as ready for review November 18, 2026 11:37
@CheSema
CheSema marked this pull request as draft November 18, 2026 11:38
The client marks an exception inside an attempt itself and decides the
outcome in one place. Wrapped buffers no longer forward the outcome, so
they count as not tracked.
The attempts of a publishing write go into its `AttemptsRecord`, which
the scope of the call points to. `isConditionalWriteAttempt` names the
check of `PocoHTTPClient`.
@scanhex12 scanhex12 self-assigned this Nov 18, 2026
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/S3/Client.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a2193ae4b with master a2c6c5559 (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.

Object file sizes

61 object files changed (+144.78 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Disks/IO/WriteBufferFromAzureBlobStorage.cpp.o 236.91 KiB 284.17 KiB +47.26 KiB (+19.95%)
src/CMakeFiles/clickhouse_common_io.dir/IO/S3/Client.cpp.o 1.53 MiB 1.57 MiB +45.16 KiB (+2.88%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

Comment thread src/IO/S3/Client.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants