Skip to content

Fix wrong logic of removeDirectory of s3 plain disk - #106281

Merged
Michicosun merged 11 commits into
ClickHouse:masterfrom
RinChanNOWWW:fix-plain-disk
Jul 7, 2026
Merged

Michicosun merged 11 commits into
ClickHouse:masterfrom
RinChanNOWWW:fix-plain-disk

Conversation

@RinChanNOWWW

@RinChanNOWWW RinChanNOWWW commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

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 wrong logic of MetadataStorageFromPlainObjectStorageTransaction::removeDirectory

Version info

  • Merged into: 26.7.1.611 (included in 26.7 and later)

@Michicosun Michicosun self-assigned this Jun 2, 2026
@Michicosun Michicosun added the can be tested Allows running workflows for external contributors label Jun 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ebaae42]

Summary: ✅


AI Review

Summary

This PR fixes the plain-disk removeDirectory prefix bug by making removeDirectory a non-recursive rmdir check and moving object deletion into removeRecursive, plus it adds focused gtests for the flat-file cases and cache invalidation. The remaining problem is that removeRecursive still is not actually recursive on plain storage, so nested descendants under the target prefix survive.

Findings

❌ Blockers

  • [src/Disks/DiskObjectStorage/MetadataStorages/Plain/MetadataStorageFromPlainObjectStorage.cpp:226-230] [dismissed by author -- https://github.com/Fix wrong logic of removeDirectory of s3 plain disk #106281#discussion_r3513226179] removeRecursive still walks only one level. listDirectory/iterateDirectory collapse a prefix to its immediate children ([src/Disks/DiskObjectStorage/MetadataStorages/Plain/MetadataStorageFromPlainObjectStorage.cpp:109-143]), so for root/A/B/file.txt this loop sees only root/A and unlinkFile("root/A", ...) removes a non-existent object instead of descending to root/A/B/file.txt. I still consider it real because the changed test coverage stays flat ([src/Disks/tests/gtest_metadata_plain_disk.cpp:115-182]), while callers such as DataPartStorageOnDiskBase::removeRecursive ([src/Storages/MergeTree/DataPartStorageOnDiskBase.cpp:1032-1037]) use disk.removeRecursive for whole part directories that can contain nested subdirectories (for example projections), so this still leaks blobs and leaves recursive cleanup incomplete. Suggested fix: either recurse through directory entries using existsFile/iterateDirectory, or switch to a recursive object listing under path, and add a regression with at least one nested subdirectory.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: make removeRecursive actually recursive for MetadataStorageFromPlainObjectStorage and cover a nested-subdirectory case in the regression tests.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 2, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.60% 85.60% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.80% +0.00%

Changed lines: Changed C/C++ lines covered: 84/85 (98.82%) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun added this pull request to the merge queue Jul 7, 2026
@Michicosun
Michicosun removed this pull request from the merge queue due to a manual request Jul 7, 2026
@Michicosun
Michicosun added this pull request to the merge queue Jul 7, 2026
Merged via the queue into ClickHouse:master with commit 0328aa4 Jul 7, 2026
175 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @RinChanNOWWW @Michicosun — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently missing):

  • Why: The PR body contains only the changelog template with no explanation of the original bug (wrong object key from using the logical path instead of getKeyForPath) or why removeDirectory now throws CANNOT_RMDIR.

  • Suggested addition:

    Explain: the old removeDirectory removed children using StoredObject(it->path()) (the logical path) as the object key instead of getKeyForPath(common_key_prefix, path), so on plain storage it silently removed nothing. removeRecursive now iterates children via unlinkFile (correct key + object_metadata_cache invalidation), and removeDirectory now follows rmdir semantics (throws CANNOT_RMDIR on non-empty directories).

Ignore this if the current title/body is intentional.

@RinChanNOWWW
RinChanNOWWW deleted the fix-plain-disk branch July 8, 2026 02:25
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Aug 11, 2026
Antalya 26.6 Backport of ClickHouse#106281, ClickHouse#111483 - Restrict local object access only for user files path
UnamedRus pushed a commit to UnamedRus/ClickHouse that referenced this pull request Aug 12, 2026
Fix wrong logic of removeDirectory of s3 plain disk
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Fix wrong logic of removeDirectory of s3 plain disk
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 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.

6 participants