Repository navigation
Cherry pick #119850 to 26.7: Do not create a disk defined in SQL while deciding whether ALTER ... MODIFY SETTING disk is allowed - #124004
Merged
Conversation
…an name Two locations of a disk created by a `disk(...)` clause were not confined: The name of the disk is used verbatim as a path component of the state the server keeps for it - the metadata storage builds `<clickhouse path>/disks/<name>/` and creates that directory - so a name containing a path separator or `..` relocated server-managed state to any directory the server can write to, `user_scripts/` among them. The name must now be a plain name. The `custom_local_disks_base_directory` fence was applied only to disks that report `isRemote() == false`, which `DiskObjectStorage` never does - not even when its backing object storage is the local filesystem, where `path` is a plain directory that the query just named, and where the metadata is written to the local filesystem as well. The fence now asks whether the backing storage is local instead, and covers both locations. This is a backward incompatible change for a disk defined in SQL as `object_storage` over `local`: such a disk now requires `custom_local_disks_base_directory` to be configured and its `path` and `metadata_path` to be inside it, the same requirement that `type = local` disks have had. Disks defined in the server configuration are not affected, and neither is attaching a table that already uses such a disk. Finally, the entries that `DatabaseCatalog::maybeRemoveDirectory` is asked to remove are exactly the ones that failed the "is a directory" test, so they can be regular files, and widening a regular file's mode to `S_IRWXU` makes it executable. Removal needs write and execute permissions on the directory whose entries are unlinked, not any permission on the entry itself, so only a directory gets its mode widened now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…disks These tests define a disk backed by the local filesystem in SQL and give it a path next to the data directory rather than inside `disks/`, which this change confines them to. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… the server Two corrections, both found by the functional tests. A relative path of a disk backed by the local filesystem was resolved against the working directory of the process, which is not a property of the server: it is `/` under systemd, the log directory when running as a daemon, and the directory the server happened to be started from otherwise. So the same definition described a different location on the next start, and no directory could be said to contain it. Such a path is now resolved against the directory of the server, which is what every such definition already means in the environments where it works today. The metadata path of an object storage disk is resolved the same way. The containment check asked the created disk for its path, which sees through a disk that refers to a disk of the server configuration: a `cache` disk over a configured local disk was refused because of the path the administrator gave that disk. The check now reads the locations out of the disk definition, so it covers exactly what the query named - and it runs before the disk is created, so a rejected definition also creates no directory. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ctory The working directory of the server process, which the filesystem resolves a relative path against, is not a property of the server: it is `/` under systemd, the log directory when running as a daemon, and the directory the server was started from otherwise - and it is not the data directory in the test environment either. A relative path therefore named a different place depending on how the server was started, and no directory could be said to contain it. A relative path of a disk defined in SQL is now resolved against `custom_local_disks_base_directory`, so it is inside that directory by construction, and the definition keeps naming the same place on the next start. An absolute path still has to be inside that directory. Both the data and the metadata location of the disk are resolved in the disk definition before the disk is created, so the disk uses exactly the location that was checked. Because of that, the tests that give their disk a relative path did not need to change after all; only the one test that built an absolute path out of the data directory of the server had to name the base directory instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… test The disks the test creates on purpose stay registered for the lifetime of the server, so a pattern over `system.disks` counted them on the second run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…finition An `ATTACH TABLE` that writes the disk out in the query names a location just as a `CREATE TABLE` does, so it is checked the same way; only loading a table from the metadata the server already stored is not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A `type = local` disk passes the path to the filesystem exactly as it was given, so there is nothing to resolve for it, and the check that runs after it is created is truthful as it stands. Its wording matters too: a test reads the configured base directory out of that message. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Resolving a relative path against the base directory made the disk write somewhere the definition did not name, which in the test environment is a directory shared by every job on the runner rather than the sandbox of the run - a leftover from an earlier run then broke the `plain_rewritable` metadata of a later one, and the whole shard with it. The check now compares the location exactly as the definition gives it, which is also exactly how the disk uses it. A relative path is resolved by the filesystem against the working directory of the process - `/` under systemd - so it is inside the base directory only by accident, and the tests that had one now name the base directory instead, the way the tests of `type = local` disks already did. `04103` becomes a shell test for that reason, and gives its disk a per-run directory: its metadata lives in that directory, so a leftover from another run is not inert. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… by its type Two locations escaped the fence. A multi-location `DiskObjectStorage` builds one object storage per `locations.<name>` child, each with its own backend and its own `path`, so an `include` could resolve a local child behind a root that names a remote backend, and the check only ever looked at the root. And a plain `type = local` disk was checked only after `DiskFactory::create` had built and started it, so `DiskLocal::setup` created the rejected directory first, and `ALTER TABLE ... MODIFY SETTING disk = disk(type = local, ...)` slipped past entirely: it resolves the disk once with `is_loading_from_existing_metadata`, which memoizes it in `Context::getOrCreateDisk`, and the stricter pass that follows finds the disk already there and never runs the check. Both are now checked before the disk is created, by one rule: every backend of the resolved configuration - the root and every `locations.<name>` child - whose type starts with `local` has its `path` checked. The check that runs after the disk is created stays as a backstop for the local disks whose directory the definition does not name outright. Its exemption for the backup disk went by the disk name, which the query chooses, so `disk(name = 'backup', type = local, path = '/etc/')` avoided the only fence a plain local disk had. It goes by the type of the disk now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`05217` covers `ALTER TABLE ... MODIFY SETTING disk = disk(type = local, ...)`, a disk named `backup`, and the absence of a directory for a disk the fence rejected. The integration test covers a `locations.<name>` child that an `include` resolves to a local backend outside the base directory. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…allowed `ALTER TABLE ... MODIFY SETTING disk = disk(type = local, path = '...')` was rejected, and yet left the disk registered and its directory created. Several computations that run before the statement is known to be allowed rebuild the settings the table would end up with - `AlterCommands::apply` for the implicit index settings, `checkAlterIsPossible` for the projection and part-format checks, `checkColumnFilenamesForCollision` - and each of them applied the whole change list as if it came from stored metadata, which resolves the `disk` setting, and resolving it creates and registers the disk. None of those computations reads the `disk` setting, so they now apply the changes with `applyChangesLeavingDiskUnresolved`, which leaves it alone. The settings update itself, `MergeTreeData::changeSettings`, still resolves it - by then the statement has passed the check. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…al-paths Master gained #110665, which moved the `custom_local_disks_base_directory` fence into the disk factories (`DiskLocal`, the local object storage, `metadata_path`, `encrypted`, every `locations.<name>` child), added the disk-name check, and dropped the name-based `backup` exemption. That covers the checks this branch added to `DiskFromAST.cpp`, so the file is taken from master as is, and `05216`, which duplicated master's `05212_custom_disk_local_paths_confined`, is removed. The `custom_local_disks_base_directory` key this branch added to `test_attach_backup_from_s3_plain` is already on master. What master does not cover is kept: the factory checks run only for `!attach`, and the computations that rebuild the post-`ALTER` settings resolved `disk` as if it came from stored metadata, which created and registered an unchecked disk. `refreshSettingsDerivedMetadata`, which replaced the inline block in `AlterCommand::apply`, now uses `applyChangesLeavingDiskUnresolved` as well. The `DatabaseCatalog::maybeRemoveDirectory` change is dropped, as asked in review, to keep this fix minimal for backporting.
Since #110665 the path check runs inside the disk factory, and the server log line of the exception is forwarded to the client by `--send_logs_level`, so the message appears twice on stderr. Stop at the first match. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e fence tests `alter_effective_settings` left `disk` at its default, so the diff passed to `checkMergeTreeSettingsConstraints` missed a change of `disk` on a table that had none, and reported one on every ALTER of a table that had one. Resolve the new `disk` there instead, as a fresh definition when it changes, so the fence runs before anything registers the disk. Extend 05217 to a local object storage disk, an outside `metadata_path`, a table without a SETTINGS clause, and a constant `merge_tree_disk` constraint. `test_dynamic_disk_include_locations_child_local_path_is_fenced` never reached the path check: a `type = object_storage` disk with an `include` and no literal `object_storage_type` is treated as possibly S3 and rejected with ACCESS_DENIED first. Lift the S3 credentials restriction for that query. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Do not create a disk defined in SQL while deciding whether `ALTER ... MODIFY SETTING disk` is allowed
Resolve the conflicts of the cherry-pick of #119850 to 26.7. On 26.7, `refreshSettingsDerivedMetadata` does not exist (the implicit index refresh is inline in `AlterCommands::apply`), and the post-ALTER effective settings in `MergeTreeData::checkAlterIsPossible` are built inside the replay check instead of in `checkAlterEligibility`. The change is ported to those places: the implicit index refresh and `checkColumnFilenamesForCollision` and the part format check use `applyChangesLeavingDiskUnresolved`, and the effective settings for the constraints check resolve `disk` with `is_loading_from_existing_metadata = !disk_setting_changed` under `local_context`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #119850
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job