Skip to content

Allow alter commands for plain_rewritable metadata - #93882

Closed
korowa wants to merge 14 commits into
ClickHouse:masterfrom
korowa:enable-alter-plain-rewritable
Closed

korowa wants to merge 14 commits into
ClickHouse:masterfrom
korowa:enable-alter-plain-rewritable

Conversation

@korowa

@korowa korowa commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Allow alter commands and mutations for MergeTree tables with plain_rewritable metadata.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Details

Related to #91611

Since hard links creation is supported by plain_rewritable metadata, and implemented with copying object, make supportsHardLinks() to return true for plain_rewritable, and allow alter commands to be executed.

@korowa
korowa marked this pull request as draft January 11, 2026 17:26
@Michicosun Michicosun added the can be tested Allows running workflows for external contributors label Jan 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jan 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ace7e12]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, 1/3) FAIL
02818_memory_profiler_sample_min_max_allocation_size FAIL cidb
Stateless tests (amd_llvm_coverage, 2/3) FAIL
02293_http_header_full_summary_without_progress FAIL cidb
Performance Comparison (arm_release, master_head, 1/6) ERROR
Performance Comparison (arm_release, master_head, 2/6) ERROR
Performance Comparison (arm_release, master_head, 3/6) ERROR
Performance Comparison (arm_release, master_head, 4/6) ERROR
Performance Comparison (arm_release, master_head, 5/6) ERROR
Performance Comparison (arm_release, master_head, 6/6) ERROR

AI Review

Summary

This PR enables ALTER/mutations for plain_rewritable metadata by allowing hard-link semantics for rewritable object-storage metadata, adds cleanup of on-disk mutation files on drop for non-replicated MergeTree, and extends stateless coverage. High-level verdict: there is one blocker-level correctness regression in settings normalization for tables that already use custom disks.

Missing context
  • ⚠️ No CI report/log links were provided in this review task, so runtime coverage and flaky behavior could not be validated from CI artifacts.
Findings

❌ Blockers

  • [src/Storages/MergeTree/MergeTreeSettings.cpp:2260] normalizeSettingsChanges rejects string-form custom disk names via ensureDiskIsNotCustom. Existing tables can persist custom-disk settings as disk names in metadata, so unrelated ALTER paths may start failing when normalization is applied to current metadata (checkAlterIsPossible, checkColumnFilenamesForCollision).
    • Suggested fix: split normalization and validation. Keep normalization for comparison (disk(...) -> resolved name), but skip ensureDiskIsNotCustom validation when normalizing already-persisted/current metadata; enforce custom-disk restrictions only on new user input paths.
ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ❌ Normalization now rejects valid existing custom-disk metadata in alter-related flows.
SettingsChangesHistory.cpp ✅
PR metadata quality ✅
Safe rollout ⚠️ Rollout is not safe until custom-disk metadata regression is fixed.
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ❌ Block
  • Minimum required actions:
    • Fix normalizeSettingsChanges usage/logic so existing tables with persisted custom-disk metadata do not fail unrelated ALTER operations.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jan 11, 2026
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch 11 times, most recently from 2684f3c to 7120440 Compare January 20, 2026 07:22
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jan 20, 2026
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from 7120440 to 231b3d1 Compare January 20, 2026 08:03
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from 231b3d1 to d06894a Compare February 3, 2026 05:59
@korowa
korowa marked this pull request as ready for review February 3, 2026 08:48
@xeizmendi

Copy link
Copy Markdown

It's great! This looks like a great improvement, it would unlock separating the reading from the writing pipeline to scale horizontally as mentioned in #91611.
@korowa I think nobody is reviewing your PR because some checks failed.

Since hard links creation is supported by plain_rewritable metadata,
and implemented with copying object, make `supportsHardLinks()` to
return true for plain_rewritable, and allow alter commands to be
executed.
Not working yet due to different `disk` setting value in
storage metadata (original definition with disk function)
and storage_settings of MergeTreeData (replaced with the
disk name), which leads to datatype conflict during
alters.

Marking this as unsupported with proper error message.
Object storage disks don't support root directory recursive removal,
therefore final root directory cleanup for tables with table_disk
is a no-op.

Since mutation files are "known" objects that need to be cleaned up
on table drop, they now are removed explicitly.
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from d06894a to 3950f03 Compare February 23, 2026 07:00
Comment thread src/Storages/StorageMergeTree.cpp Resolved
@alexey-milovidov alexey-milovidov removed the manual approve Manual approve required to run CI label Mar 24, 2026
{
const auto disk = local_context->getDisk((*settings_from_storage)[MergeTreeSetting::disk]);
if (disk->isCustomDisk())
throw Exception(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not?

@korowa korowa Mar 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was not working due to disk setting type differences between origial DDL (disk function) and disk settings of MergeTreeData (stores only a name) -- fixed by c1e3c6b (could be done simper by reusing getOrCreate disk, since any alter would fail later, but seemed more safe not to create new disks during ALTER operations)

Comment thread src/Storages/MergeTree/MergeTreeData.h Resolved
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from 58ef013 to 2b4fedb Compare March 29, 2026 14:39
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch 2 times, most recently from c876178 to a7efaef Compare March 30, 2026 05:34
@korowa

korowa commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed azure tests as they now support alters, but flaky check may timeout because of running a bunch of unchanged tests (see #94641)

UPD: not fixed yet, and it doesn't look related to running unchanged tests.

@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from a7efaef to 94fb3af Compare March 30, 2026 08:20
@korowa
korowa marked this pull request as draft March 30, 2026 09:48
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch 4 times, most recently from 26e0614 to 56b5588 Compare April 3, 2026 09:18
To make alters on tables with custom disks pass, the disk setting
from Storage settings changes is normalized to only disk name.
The logic is similar to what MergeTreeSettings::loadFromQuery does,
except for prohibited creation of new custom disks.
@korowa
korowa force-pushed the enable-alter-plain-rewritable branch from 56b5588 to c1e3c6b Compare April 4, 2026 07:17
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member

The test 02859_replicated_db_name_zookeeper is fixed in #101952

if (auto disk_function_ast = getDiskFunctionAST(value))
value = DiskFromAST::getCustomDisk(disk_function_ast, context);
else
DiskFromAST::ensureDiskIsNotCustom(value.safeGet<String>(), context);

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.

normalizeSettingsChanges now runs on both existing table metadata (current_changes) and metadata-derived checks (checkColumnFilenamesForCollision), but this branch rejects any string disk name that points to a custom disk.

That makes existing valid tables with SETTINGS disk = disk(...) fail unrelated ALTER paths after the disk is normalized to its name (same table, no disk change). In other words, we reject pre-existing metadata, not just new user input.

Please split normalization from validation (e.g. normalize-only mode for existing/current metadata, validation only for user-provided new changes), otherwise ensureDiskIsNotCustom introduces a regression for ALTER on tables that already use custom disks.

@korowa korowa Apr 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this comment is correct, as the current_changes is taken from the Storage, not MergeTreeData, so it will contain an original definition of the custom disk via disk() which will later be normalized to the name without failing.

@alexey-milovidov

Copy link
Copy Markdown
Member

The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158

@clickhouse-gh

clickhouse-gh Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 94.02% (110/117) | lost baseline coverage: 8 line(s) · Uncovered code

Full report · Diff report

@korowa korowa closed this May 19, 2026
@xeizmendi

Copy link
Copy Markdown

@korowa why did you close the pull request? has it been abandoned?

@korowa

korowa commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@xeizmendi yes, it's abandoned, and I think it's not sufficient -- if you check tests/queries/0_stateless/03787_alter_s3_plain_rewritable_read_write.sh the flow, this PR offers, is quite painful:

  1. the user have to drop/create the readonly copy of the table (not the biggest issue, but still an issue)
  2. custom disks used for the readonly table should be different during each iteration
  3. stale custom disks used during previous versions of tables will still reside in disk registry until the server is restarted

So (just an opinion), in order to support more natural / user-friendly workflow for this usecase, there is more to be done than this PR contains for now.

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-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants