Skip to content

Move experimental-codec MergeTree settings check into MergeTreeSettingsImpl::sanityCheck - #111700

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/move-experimental-codec-check-to-sanitycheck
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/move-experimental-codec-check-to-sanitycheck

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #111007

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

Description

Follow-up to #111007 (@rschu1ze asked to move the check into MergeTreeSettingsImpl::sanityCheck).

The allow_experimental_codecs gate for the codec-valued MergeTree settings (marks_compression_codec, primary_key_compression_codec, default_compression_codec) was enforced on CREATE in registerStorageMergeTree.cpp. This moves that CREATE-time enforcement into MergeTreeSettingsImpl::sanityCheck, right next to the existing lossy-codec validation of the same three settings.

sanityCheck runs on CREATE only, so the metadata-load paths that do not call it (short/full ATTACH, SECONDARY_CREATE, values inherited from the current <merge_tree> config defaults) keep a minimal counterpart in registerStorageMergeTree. The initiator-side ALTER MODIFY/RESET SETTING gate in checkAlterIsPossible is unchanged.

The session-level allow_experimental_codecs is not readable from the storage's global context inside sanityCheck, so it is threaded from local_settings through the storage constructors. The ALTER-apply path (changeSettings, also runs on replicas), the projections path (codec settings are not allowed there) and the server-startup config-default validation pass it as satisfied.

One intentional minor tightening: the old check lived only in the extended-definition branch, so a deprecated-syntax MergeTree(date, key, granularity) CREATE could still inherit an experimental codec from a <merge_tree> config default without the setting. Since sanityCheck runs for every CREATE, that corner of the config-default bypass is now closed too. It only makes an experimental codec correctly require its flag, so no valid workflow breaks.

Existing tests 04616_experimental_codec_in_merge_tree_settings, 04617_experimental_codec_attach_full_definition and test_experimental_codec_config_default cover CREATE, ALTER MODIFY/RESET, full/short ATTACH, the config-default-on-load gate, the stored-codec exemption and restart; the integration test gains a deprecated-syntax CREATE case.

…gsImpl::sanityCheck

The allow_experimental_codecs gate for the codec-valued MergeTree settings
(marks_compression_codec, primary_key_compression_codec, default_compression_codec)
was enforced in registerStorageMergeTree.cpp on CREATE. Move that CREATE-time
enforcement into MergeTreeSettingsImpl::sanityCheck, next to the existing lossy-codec
validation of the same three settings, which is the centralized place for MergeTree
settings sanity checks.

sanityCheck is invoked on CREATE only, so the metadata-load paths that do not run it
(SECONDARY_CREATE, short/full ATTACH, and values inherited from the current <merge_tree>
config defaults) keep a minimal counterpart in registerStorageMergeTree. That counterpart
now sits after the extended/deprecated syntax branches so both syntaxes are covered
uniformly (previously it lived in the extended-definition branch only). The initiator-side
ALTER MODIFY/RESET SETTING gate in checkAlterIsPossible is unchanged.

As a result, a deprecated-syntax MergeTree(date, key, granularity) table that inherits an
experimental codec from a <merge_tree> config default is now gated on both CREATE and load,
closing a corner of the config-default bypass that was previously open only for that syntax.

The session-level allow_experimental_codecs cannot be read from the storage's (global)
context inside sanityCheck, so it is threaded explicitly from local_settings through the
StorageMergeTree, StorageReplicatedMergeTree and MergeTreeData constructors. The
ALTER-apply path (changeSettings, which also runs on replicas), the projections path
(codec settings are not allowed there) and the server-startup config-default validation
pass it as satisfied.

Related: ClickHouse#111007

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

groeneai commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator Author
Internal second-model review - adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 findings across 1 full pass + 1 fix round + 1 delta recheck; final recheck: 0 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ Moving the CREATE check into sanityCheck newly gates deprecated-syntax MergeTree(date, ...) CREATEs (old check was only in the extended-definition branch). AGREE Kept sanityCheck gating all CREATEs (more correct: closes a corner of the same config-default bypass). Documented the tightening in the PR description; added a deprecated-syntax CREATE case to the integration test.
2 ❌ Deprecated-syntax metadata loads still bypass the gate: the load-path counterpart was also nested in the extended-definition branch, so a deprecated table re-attaching inherits a config-default experimental codec without the flag. AGREE - fixed Moved the load-path counterpart out of the extended branch to after both syntax branches, so extended and deprecated syntax are covered uniformly. Reproduced the bypass before the fix and confirmed it is gated after, on a Build-ID-verified binary. Added a deprecated-syntax DETACH/ATTACH case to the integration test.
3 💡 CI Fix or Improvement does not describe a server-side validation change. AGREE - fixed Changed the changelog category to Not for changelog (the ZXC feature and its gate are unreleased).

Severity: ❌ blocker / ⚠️ major / 💡 nit. All three findings were verified against the code and accepted. The final delta recheck returned 0 findings.

Session id: cron:clickhouse-author-slot-5:20260723-201800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a binary with the sanityCheck block disabled, clickhouse-client --allow_experimental_codecs 0 -q "CREATE TABLE t (x UInt64) ENGINE=MergeTree ORDER BY x SETTINGS default_compression_codec='ZXC'" is accepted; with the block it is rejected with BAD_ARGUMENTS.
b Root cause explained? This is @rschu1ze's requested relocation: the CREATE-time allow_experimental_codecs gate was scattered in registerStorageMergeTree.cpp; it belongs in MergeTreeSettingsImpl::sanityCheck, the centralized MergeTree-settings validator (which already validates these same 3 settings for lossy codecs).
c Fix matches root cause? Yes. The CREATE check now lives in sanityCheck; the load paths sanityCheck cannot reach keep a minimal, syntax-agnostic counterpart in registerStorageMergeTree.
d Test intent preserved / new tests added? Yes. Existing 04616/04617/test_experimental_codec_config_default are unchanged in intent and still pass; the integration test gains deprecated-syntax CREATE + ATTACH cases for the corner this PR closes.
e Both directions demonstrated? Yes. With the check disabled, CREATE with ZXC is accepted; with it, rejected. Confirmed on Build-ID-verified binaries.
f Fix is general across code paths? Yes. All 3 codec settings handled; all sanityCheck call sites updated (MergeTreeData ctor, changeSettings, ProjectionsDescription, Server.cpp startup x2) plus the wrapper and the gtest constructor.
g Fix generalizes across inputs? Yes. Verified across the CREATE / full-ATTACH / short-ATTACH / RESET / config-default / restart matrix for both extended and deprecated syntax, and the multi-codec case ('LZ4, ZXC').
h Backward compatible? Yes. No setting default or on-disk/wire format change. Tables carrying a codec stay loadable; a config default opted in via the default profile still survives restart. One intentional minor tightening (deprecated-syntax config-default now gated) only makes an experimental codec correctly require its flag; no valid workflow breaks; the feature is unreleased.
i Invariants and contracts preserved? Yes. Replica-apply is not re-gated (changeSettings passes the flag as satisfied); FORCE_RESTORE still skips all checks; the existing lossy-codec check is untouched; the initiator-only ALTER gate in checkAlterIsPossible is unchanged.

Session id: cron:clickhouse-author-slot-5:20260723-201800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze - this is the follow-up you asked for on #111007: the experimental-codec gate for the codec-valued MergeTree settings is moved into MergeTreeSettingsImpl::sanityCheck, with a minimal load-path counterpart in registerStorageMergeTree for the ATTACH/config-default paths that don't run sanityCheck.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fe17067]

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 80.60% 86.20% +5.60%
Functions 91.00% 92.00% +1.00%
Branches 72.50% 78.30% +5.80%

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

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 80dcc21

CI fully finished (Config + Finish Workflow SUCCESS, 2h22m buffer). The Linux Fast test passed (only the macOS Fast test (arm_darwin) flaked), so no PR-caused failure. Every failed check has an owner; only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / Server died infra — chronic macOS native-runner flake (24 unrelated PRs / 0 master in 48h; Linux Fast test passed) a fix task is moved to pending (issue #103235; investigating at full effort, fixing-PR link to follow here)
Upgrade check (amd_release) / Changed + New settings not reflected in settings changes history flaky/infra (165 PRs / 0 master in 7d; upgrade-check settings-history baseline) #104860 (merged) — join_runtime_filter_min_probe_rows SettingsChangesHistory entry
Upgrade check (amd_release) / Error message in clickhouse-server.log infra — DiskLocalCheckThread clickhouse_disk_checker teardown-race (0 master) #110773 (ours, open)
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260724-063000

@rschu1ze

Copy link
Copy Markdown
Member

Meh, this became too complex. Not worth continuing.

@rschu1ze rschu1ze closed this Jul 28, 2026
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-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants