Skip to content

Do not let a local object storage remove its own root directory - #119119

Merged
alexey-milovidov merged 11 commits into
masterfrom
fix-local-object-storage-removes-own-root
Oct 4, 2026
Merged

alexey-milovidov merged 11 commits into
masterfrom
fix-local-object-storage-removes-own-root

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

LocalObjectStorage::removeObject removes the parent directories of a deleted blob that became empty, walking up while dir != root && pathStartsWith(dir, root). root is weakly_canonical of the path of the disk and is therefore absolute, but dir comes from resolvePathRelativelyToKeyPrefix, which keeps the path relative when path is relative. A relative dir never compares equal to the absolute root, while pathStartsWith resolves both against the working directory and answers true, so the root directory of the object storage was removed as well once it became empty; the walk stopped only one level higher.

The root is created once, when the disk is created, and writeObject recreates only the direct parent of a blob, so nothing else that lives in that directory survives. In particular, the default metadata_path of the local metadata storage is <clickhouse path>/disks/<disk name>/, and a relative path is resolved against the working directory of the server, which is its data path in the standard layout, so a disk defined with object_storage_type = 'local' and path = 'disks/<its own name>/' deletes its own metadata directory while checking access at startup, and the next CREATE TABLE on it fails with filesystem error: in create_directory: No such file or directory [.../disks/<disk name>/store].

Both paths are now brought into the same form before they are compared. Found while writing a test for #118662. The same happens when an absolute path is not in the canonical form (e.g. contains ..): the keys of the blobs keep that form, while the root is canonicalized. The test uses such a path, so that it does not depend on the working directory of the server.

Related: #118662

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):

Fixed a disk with object_storage_type = 'local' and a relative path removing its own root directory once the last blob in it was deleted. Anything else stored in that directory was lost with it; in particular, a disk whose path pointed at the directory of its own local metadata became unusable.


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

Version info

  • Merged into: 26.10.1.1514-master (included in 26.10 and later)

`LocalObjectStorage::removeObject` removes the parent directories of a deleted blob that became empty,
walking up while `dir != root && pathStartsWith(dir, root)`. `root` is `weakly_canonical` of the `path` of
the disk and is therefore absolute, but `dir` comes from `resolvePathRelativelyToKeyPrefix`, which keeps the
path relative when `path` is relative. A relative `dir` never compares equal to the absolute `root`, while
`pathStartsWith` resolves both against the working directory and answers `true`, so the root directory of
the object storage was removed as well once it became empty; the walk stopped only one level higher.

The root is created once, when the disk is created, and `writeObject` recreates only the direct parent of a
blob, so nothing else that lives in that directory survives. In particular, the default `metadata_path` of
the `local` metadata storage is `<clickhouse path>/disks/<disk name>/`, and `clickhouse-server` changes its
working directory to its data path, so a disk defined with `object_storage_type = 'local'` and
`path = 'disks/<its own name>/'` deletes its own metadata directory while checking access at startup, and
the next `CREATE TABLE` on it fails with
`filesystem error: in create_directory: No such file or directory [.../disks/<disk name>/store]`.

Both paths are now brought into the same form before they are compared.
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2836aaf]

Summary: ✅


AI Review

Summary

This PR fixes the empty-directory cleanup in LocalObjectStorage::removeObject by canonicalizing the blob parent path before comparing it with the canonicalized storage root. That closes the relative / non-canonical path case where the cleanup walk could delete the object storage root itself after the last blob was removed. The new stateless test exercises the non-canonical-path variant and checks the root directory both before and after blob cleanup. I do not see an unresolved correctness issue in the implementation or its coverage.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 2836aaf.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.20% +0.10%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... labels Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2836aafaa with master b94acbe31 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 2493c465d; 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

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

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Fast test (arm_darwin) is red on 05076_error_trace_file_offsets, which is not related to this change: the test asserts on max(address_end) of system.symbols, and it is failing the same way on 14 unrelated pull requests today, as well as on master in Stateless tests (amd_release, parallel, 1/2).

The cause and the fix are already known: #119136 stops indexing absolute ELF symbols as addresses, which inflated max(address_end) by a factor of about 1.7 million, so countIf(x > max(address_end)) came out as 0 instead of 1 - exactly the diff seen here.

The test added by this pull request, 05161_local_object_storage_keeps_its_root, passed in the same run.

Related: #119136

alexey-milovidov and others added 6 commits September 10, 2026 18:37
The root of a `local` object storage with a relative `path` is resolved against the working
directory of the server, and the test derives its location from the path of the `default`
disk, which coincides with it only in the test configuration. Verify that the directory exists
while the table still has blobs, so a mismatch in the layout does not look like the root being
removed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexey-milovidov and others added 4 commits October 2, 2026 14:24
The `Fast test` failed because the server there no longer runs with its data
directory as the working directory, so the relative `path` of the disk was
resolved outside of `custom_local_disks_base_directory` and rejected.

Use an absolute `path` that is not in the canonical form (it goes through
`disks/../disks/`) instead: the keys of the blobs keep the `..`, while the root
is canonicalized, so it reproduces the same bug regardless of the working
directory. Verified that the test fails without the fix and passes with it.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119119&sha=62386f0f3302042139e59a61cc176188976c41e2&name_0=PR&name_1=Fast%20test
#119119

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The path of a custom `local` disk must be inside `custom_local_disks_base_directory`,
which is not under the path of the `default` disk in the fast test. Use `CLICKHOUSE_DISKS_FILES`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119119&sha=7b68129e569d6c71e80c0905ce95261a64eb7a08&name_0=PR&name_1=Fast%20test
#119119

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Oct 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
Merged via the queue into master with commit 11d8557 Oct 4, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-local-object-storage-removes-own-root branch October 4, 2026 17:51
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... 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.

2 participants