Skip to content

Fix alter with custom disk - #109199

Merged
Michicosun merged 8 commits into
masterfrom
fix-alter-with-custom-disk
Jul 4, 2026
Merged

Michicosun merged 8 commits into
masterfrom
fix-alter-with-custom-disk

Conversation

@Michicosun

@Michicosun Michicosun commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

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

This patch fixes ALTERS for MergeTree tables for which the disk setting was specified.

Fixes: #63019

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7c77c06]

Summary: ✅


AI Review

Summary

This PR fixes the BAD_GET path from issue #63019 by normalizing disk settings during ALTER, but the new normalization still runs in several paths that are supposed to be validation-only. Rejected DDL can therefore still register custom disks or create table directories on target disks before the metadata change commits, so the patch is not ready to merge.

Missing context / blind spots
  • ⚠️ No local build/test run: this checkout has no build directory, and the direct Praktika S3 report for PR 109199 exposed no per-job test breakdown, so this review is based on code tracing and the current PR discussion.
Findings

❌ Blockers

  • [src/Storages/MergeTree/MergeTreeData.cpp:5252-5288] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/109199#discussion_r3514789450] changeSettings resolves disk(...) and creates relative_data_path / detached on the new disk before sanityCheck and before the metadata commit paths in StorageMergeTree / StorageReplicatedMergeTree finish. A later exception only restores the old settings; it never removes the created directories or the transient custom disk. The failure is sticky: a retry to the same disk will now trip the existsDirectory(relative_data_path) check and fail even though the previous ALTER never committed.
    Suggested fix: postpone disk registration and directory creation until after all later checks that can still throw, or record the new disk/directories and remove them in every rollback path.

⚠️ Majors

  • [src/Storages/AlterCommands.cpp:1024] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/109199#discussion_r3514789446] AlterCommand::apply now resolves built-in disk settings while it is only recomputing implicit minmax flags for new_metadata. That reaches Context::getOrCreateDisk with is_loading_from_existing_metadata = true, so any later validation failure in checkAlterIsPossible still leaves a custom disk registered globally. With an explicit name=..., the stale registration can make a later valid DDL fail with "already configured as a custom disk" even though no table ever committed it.
    Suggested fix: keep this pre-validation recomputation path side-effect free. The minmax flags do not depend on disk, so skip resolving/applying disk here or use a validation-only helper that never calls createCustomDisk.
  • [src/Storages/ProjectionsDescription.cpp:274-327] getProjectionFromAST now resolves disk(...) before it enforces the projection setting allowlist. A rejected WITH SETTINGS disk = disk(...) projection therefore creates/registers the custom disk first and only afterwards throws Setting disk is not allowed for projections, leaking global disk state from invalid DDL.
    Suggested fix: reject disallowed projection settings on the raw with_settings->changes before calling applyChanges, or special-case disk so it is never resolved on the projection path.
Final Verdict

❌ Request changes. The original ALTER exception from issue #63019 is addressed, but rejected DDL still mutates global disk state and, on the main changeSettings path, can leave persistent table directories behind on the target disk.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 2, 2026
@azat azat self-assigned this Jul 2, 2026
Comment thread src/Storages/AlterCommands.cpp Resolved
auto merge_tree_settings = result.index ? result.index->getDefaultSettings() : std::make_shared<MergeTreeSettings>();
if (projection_definition->with_settings)
merge_tree_settings->applyChanges(projection_definition->with_settings->changes);
merge_tree_settings->applyChanges(projection_definition->with_settings->changes, query_context, isLoadingFromExistingMetadata(mode));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

applyChanges now resolves disk before the projection allowlist check below. A query like PROJECTION p (...) WITH SETTINGS disk = disk(type = local, path = '...') will create/register the custom disk first and only then throw Setting disk is not allowed for projections, leaving global disk state behind from an invalid DDL.

The projection allowlist needs to run before applyChanges here, or disk needs to be rejected without ever calling resolveDiskSetting.

@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.60% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.80% +0.10%

Changed lines: Changed C/C++ lines covered: 83/89 (93.26%) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun added this pull request to the merge queue Jul 4, 2026
Merged via the queue into master with commit a6127fc Jul 4, 2026
174 checks passed
@Michicosun
Michicosun deleted the fix-alter-with-custom-disk branch July 4, 2026 20:50
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 4, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Aug 22, 2026
Antalya 26.6 Backport of ClickHouse#109199 - Fix alter with custom disk
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Custom disk setting (SETTINGS disk = disk(...)) breaks alters on the table

3 participants