Skip to content

Keep S3 retries of cleanup when the query or merge is cancelled - #130818

Merged
CheSema merged 2 commits into
masterfrom
cleanup-blocker-s3-retries
Nov 12, 2026
Merged

CheSema merged 2 commits into
masterfrom
cleanup-blocker-s3-retries

Conversation

@CheSema

@CheSema CheSema commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Related: #128185
Related: #127813

The S3 client does not retry in a thread whose query or merge is cancelled, and cleanup may run in such a thread. A failed OPTIMIZE ... DRY RUN PARTS cancels its query and then its merge, so the merge aborts the multipart uploads of its other writers with one attempt, and one transient error leaves an incomplete upload. A failed projection merge, a killed OPTIMIZE or INSERT, and the abort of copyS3File behave the same.

Now WriteBufferFromS3::abortMultipartUpload, the multipart abort of copyS3File, DiskObjectStorageTransaction::undo and IMergeTreeDataPart::removeIfNeeded hold ThreadStatus::QueryCancellationBlocker, as MergeTreeData::Transaction::rollback does. Trade-off: during an S3 outage, this cleanup can delay a killed query or shutdown, as the cleanup of background merges already does.

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 incomplete multipart uploads and orphaned blobs left on S3 when a cleanup request after a failed or cancelled query or merge failed once with a transient error: the cleanup now keeps its S3 retries after the cancellation.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2107-master (included in 26.11 and later)

…once

Fails on master: the merge aborts the upload of its other writer after the
query is cancelled, and the S3 client does not retry the abort there.
Hold `ThreadStatus::QueryCancellationBlocker` in `WriteBufferFromS3::abortMultipartUpload`,
the multipart abort of `copyS3File`, `DiskObjectStorageTransaction::undo` and
`IMergeTreeDataPart::removeIfNeeded`.
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [16d34d5]

Summary: ✅


AI Review

Summary

The PR preserves configured S3 cleanup retries after query or merge cancellation by adding ThreadStatus::QueryCancellationBlocker around multipart aborts, disk-transaction undo, and temporary-part removal. It adds a focused regression test for an unfinished multipart upload left by a failed OPTIMIZE ... DRY RUN PARTS when the first abort encounters a transient error. No actionable findings in the current diff.

Missing context / blind spots
  • ⚠️ Integration execution remains unverified: no built ClickHouse binary is available locally, and the inspected Praktika integration report contained no test results. A completed run of test_failed_dry_run_retries_multipart_abort, including bugfix validation against the base revision, would close this gap.
Final Verdict

Status: ✅ Approve. No code changes requested; runtime validation remains pending as noted above.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 11, 2026
@CheSema
CheSema marked this pull request as ready for review November 11, 2026 14:40
CheSema added a commit that referenced this pull request Nov 11, 2026
Cleanup that must still reach S3 runs under `QueryCancellationBlocker`
(#130818), so it keeps waiting.
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Nov 11, 2026
@CheSema
CheSema enabled auto-merge November 11, 2026 15:22
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 16d34d5a3 with master 63accaa2f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 687344e1e; 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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.64, programs/clickhouse-keeper ×0.63 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 13.0 s +9.3 s (+253%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.3 s +5.2 s (+239%)
Compile time of recompiled translation units

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

Job report

@CheSema
CheSema added this pull request to the merge queue Nov 12, 2026
Merged via the queue into master with commit fc8a491 Nov 12, 2026
203 checks passed
@CheSema
CheSema deleted the cleanup-blocker-s3-retries branch November 12, 2026 15:49
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 2026
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 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