Repository navigation
Do not let a local object storage remove its own root directory - #119119
Conversation
`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.
|
Workflow [PR], commit [2836aaf] Summary: ✅
AI ReviewSummaryThis PR fixes the empty-directory cleanup in Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 2836aaf.
Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
|
🕵 The cause and the fix are already known: #119136 stops indexing absolute ELF symbols as addresses, which inflated The test added by this pull request, Related: #119136 |
…orage-removes-own-root
Co-Authored-By: Claude Fable 5.1 <[email protected]>
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]>
…orage-removes-own-root
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]>
LocalObjectStorage::removeObjectremoves the parent directories of a deleted blob that became empty, walking up whiledir != root && pathStartsWith(dir, root).rootisweakly_canonicalof thepathof the disk and is therefore absolute, butdircomes fromresolvePathRelativelyToKeyPrefix, which keeps the path relative whenpathis relative. A relativedirnever compares equal to the absoluteroot, whilepathStartsWithresolves both against the working directory and answerstrue, 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
writeObjectrecreates only the direct parent of a blob, so nothing else that lives in that directory survives. In particular, the defaultmetadata_pathof thelocalmetadata storage is<clickhouse path>/disks/<disk name>/, and a relativepathis resolved against the working directory of the server, which is its data path in the standard layout, so a disk defined withobject_storage_type = 'local'andpath = 'disks/<its own name>/'deletes its own metadata directory while checking access at startup, and the nextCREATE TABLEon it fails withfilesystem 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
pathis 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):
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 relativepathremoving 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 whosepathpointed at the directory of its ownlocalmetadata became unusable.Workflow [PR]
Sync PR [sync-upstream/pr/119119]
Version info
26.10.1.1514-master(included in26.10and later)