Skip to content

Remove parts on plain_rewritable disks without copying their files - #123303

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:plain-rewritable-part-removal-without-copies
Oct 2, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:plain-rewritable-part-removal-without-copies

Conversation

@groeneai

@groeneai groeneai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123275

Changelog category (leave one):

  • Performance Improvement

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

Removing data parts from a disk with metadata_type = plain_rewritable (cleanup of outdated parts, TRUNCATE, DROP PARTITION, DROP TABLE) no longer copies every file of the part to a temporary object before deleting it, and no longer holds the disk metadata lock for those copies. The part directory is removed with one batched delete request. Closes #123275.

Description

DataPartStorageOnDiskBase::clearDirectory removed a complete part file by file. On plain_rewritable each file unlink copies the blob to a temporary key (so the unlink can roll back), deletes the source and later the copy, and the copy and delete run under the disk-wide metadata lock. The recursive removal, so far used only for incomplete parts, moves the directory metadata and deletes all objects after the lock, with no copies.

This adds IDisk::prefersRecursiveRemoval (false by default; local disks keep the per-file path). DiskObjectStorage returns true for plain_rewritable metadata, also behind a cache disk, DiskEncrypted forwards it, and clearDirectory takes the recursive branch when it is set. The unlink operation is unchanged: as @ Michicosun noted on the issue, its copy is what makes the transaction rollback work.

Both branches delete the same objects on these disks. The only thing dropped is the Cannot quickly remove directory error log for unexpected files in a part directory. Listing a directory is in memory on plain_rewritable, so I can keep that check if you prefer.

TRUNCATE of 200 wide parts with 20 columns, local MinIO:

duration CopyObject delete calls
master 133.9 s 27,400 55,200
this PR 12.4 s 0 400

The new test checks that TRUNCATE makes no copies on s3_plain_rewritable and on encrypted_s3_plain_rewritable_cache. It fails on master. The existing plain_rewritable stateless tests and the integration test test_s3_plain_rewritable, which checks the bucket is empty after DROP TABLE SYNC, pass.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1258-master (included in 26.10 and later)
  • Backported to: 26.9.32.13, 26.8.41.7

groeneai and others added 2 commits October 1, 2026 16:13
`DataPartStorageOnDiskBase::clearDirectory` removes a complete part file by file
(`removeSharedFiles` + `removeDirectory`). On a disk with `plain_rewritable` metadata every
`unlinkFile` is a `MetadataStorageFromPlainObjectStorageUnlinkMetadataFileOperation`, which
copies the blob to a temporary `__root/<random>` key so that the unlink can be undone, deletes
the source, and deletes the copy in `finalize`. The copy and the source delete run inside
`commit` under the disk-wide metadata mutex, so outdated-part cleanup, `TRUNCATE`,
`DROP PARTITION` and `DROP TABLE` issue one `CopyObject` (a multipart copy for big files) and
two deletes per file, and every other metadata write on the disk queues behind them
(issue ClickHouse#123275: `S3CopyObject` at 3.2/s sustained, 41k outdated parts backlogged).

The recursive branch, so far used only for incomplete or empty-checksum parts, maps to
`MetadataStorageFromPlainObjectStorageRemoveRecursiveOperation`: one `prefix.path` PUT per
directory under the mutex, and one batched `removeObjectsIfExist` for all objects in
`finalize`, with no copies. The copy in the unlink operation stays: it is what makes the
unlink roll back with the transaction.

Add `IDisk::prefersRecursiveRemoval`, false by default (on local disks the per-file branch is
the fast path). `DiskObjectStorage` answers true for `plain_rewritable` metadata, which the
cache metadata wrapper forwards through `getType`, and `DiskEncrypted` forwards it to its
delegate. `clearDirectory` takes the recursive branch when the disk prefers it. Both branches
ignore the keep-shared-data inputs on `plain_rewritable`, so the deleted objects are the
same; the only thing dropped is the "Cannot quickly remove directory" log for unexpected
files in a part directory.

Measured on a local MinIO, `TRUNCATE` of 200 wide parts with 20 columns: 133.9 s, 27,400
`CopyObject` and 55,200 delete calls before; 12.4 s, 0 copies and 400 delete calls after.

Closes ClickHouse#123275

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say the recursive removal deletes objects in bulk, not in one request (deletes are batched).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 1, 2026
@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ❌ A failed batched delete in the recursive op's best-effort finalize orphans the part's blobs while the part counts as removed DISAGREE The per-file branch has the same property: its unlink deletes the temporary __root/<random> copy in the same best-effort finalize (MetadataOperationsHolder::finalize), so a failure there orphans the same bytes. The copy only makes the pre-commit phase undoable. #118465 reclaims both kinds of leftovers.
2 ⚠️ The test cannot detect a failed or non-batched recursive delete DISAGREE There is no retry on either branch to assert. The test fails on master and when the DiskObjectStorage or DiskEncrypted override is reverted. test_s3_plain_rewritable checks the bucket is empty after DROP TABLE SYNC.
3 💡 "one request" is imprecise: deletes are batched per 1000 keys, with a per-object fallback AGREE, noted Wording only, holds for typical parts.
4 💡 DiskPlainRewritable*DirectoryRemoved is no longer incremented for part removals (only RemoveDirectoryOperation counts) AGREE, noted Observability only, no test uses it.
5 💡 Each projection directory still gets its own recursive removal before the part directory AGREE, noted Still zero copies; folding them would restructure remove().

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261001-162700

@groeneai
groeneai requested review from CheSema and Michicosun October 1, 2026 17:01
Comment thread src/Disks/IDisk.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6d30cd2]

Summary: ✅


AI Review

Summary

This PR switches DataPartStorageOnDiskBase::clearDirectory to the recursive removal path on disks that explicitly opt in via IDisk::prefersRecursiveRemoval, and wires that preference through DiskObjectStorage, the cache metadata wrapper, and DiskEncrypted. I did not find any correctness, safety, or contract regressions in the current diff: on plain_rewritable, the recursive path matches the existing part-removal semantics that this PR is targeting while avoiding the per-file copy path, and the added stateless test covers both plain and encrypted cached plain_rewritable disks.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6d30cd2.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 15/17 (88.24%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 1, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thank you 💌

@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... label Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 633c68d3-e499-4cea-8d68-dd316bcb1ad3
  • MIRAI run: e4084562-ad44-4bc9-9d64-dd2de77c2c83
  • PR check IDs:
    • clickbench_2778086_1790880791
    • clickbench_2778093_1790880792
    • clickbench_2778109_1790880792
    • tpch_adapted_1_official_2778128_1790880792
    • tpch_adapted_1_official_2778143_1790880791
    • tpch_adapted_1_official_2778157_1790880792

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6d30cd2e3 with master 0da3d28e1 (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

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

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit 798227b Oct 2, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 18, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #123303 to 26.9: Remove parts on `plain_rewritable` disks without copying their files
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #123303 to 26.8: Remove parts on `plain_rewritable` disks without copying their files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plain_rewritable: part removal copies every blob before deleting it

7 participants