Skip to content

Promote ALP to beta via new tier-aware codec gating - #116337

Merged
rienath merged 13 commits into
masterfrom
alp-beta
Aug 28, 2026
Merged

rienath merged 13 commits into
masterfrom
alp-beta

Conversation

@rienath

@rienath rienath commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

With this PR, the maturity of a gated compression codec is defined by the declared tier of its enable_<codec>_codec setting. Promoting a codec becomes one word tier change. system.codecs gains a tier column. The codec to setting link is now declared at registration and validated at server startup.

On top of this mechanism, ALP is promoted to beta.

Changelog category (leave one):

  • Improvement

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

Compression codecs are now gated by dedicated settings whose declared tier defines the codec maturity. The ALP codec is promoted to beta (enable_alp_codec setting).


Workflow [PR]
Sync PR [sync-upstream/pr/116337]

Version info

  • Merged into: 26.9.1.255 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b0961ba]

Summary: ✅


AI Review

Summary

This PR moves codec maturity to the tier of the dedicated enable_<family>_codec setting, adds a tier column to system.codecs, and promotes ALP to beta. The direction is reasonable, but the current head still leaves the gate fail-open for missing builtin switches and keeps two real escape hatches around no-type/string-based codec entry points, so I would not approve it yet.

Findings

⚠️ Majors

  • [src/Compression/CompressionFactory.cpp:154-159, src/Compression/CompressionFactoryAdditions.cpp:199-204] The new gate no longer fails closed when the builtin switch is missing. getGateTier returns nullopt when enable_<family>_codec does not exist, and the validation path then skips the check entirely, so a newly added gated codec would silently show up as Production in system.codecs and be usable without any real switch. Suggested fix: make registration or getGateTier throw when a registered codec has no builtin enable_<family>_codec setting, and keep a reverse-direction test for that invariant.

  • [src/Storages/MergeTree/registerStorageMergeTree.cpp:932-942] [dismissed by author -- https://github.com/Promote ALP to beta via new tier-aware codec gating #116337#discussion_r3855327827] The new MergeTree setting check still accepts non-lossy float-only codecs when no column type is known. validateCodecString only rejects null-type codecs when isLossyCompression() is true, so default_compression_codec = 'ALP' or default_compression_codec = 'FPC' on a String table still passes metadata validation and then throws later on INSERT/merge. Pre-existing or not, this PR touches the exact validation boundary and still leaves beta ALP unusable there. Suggested fix: reject isFloatingPointTimeSeriesCodec() (or otherwise type-dependent codecs) on null-type setting paths, not only lossy codecs.

  • [src/Interpreters/TemporaryDataOnDisk.cpp:72-77, src/Storages/CompressionCodecSelector.h:78-87] [dismissed by author -- https://github.com/Promote ALP to beta via new tier-aware codec gating #116337#discussion_r3855327834] The dedicated gate is still not global. temporary_files_codec and the server <compression> selector construct codecs through get(...) without going through the new tier check, so ALP can still bypass enable_alp_codec entirely in spill and server-default compression paths. For ALP this is not just a policy leak: those paths compress arbitrary bytes and can fail on buffers that are not 8-byte aligned. Suggested fix: route these string-based entry points through validateCodec* with settings, or explicitly reject gated codecs there.

💡 Nits

  • [src/Core/Settings.cpp:8755-8757] enable_alp_codec is promoted to beta here, but src/Core/SettingsChangesHistory.cpp:69 still says it enables the experimental ALP codec. system.settings_changes, system.documentation, and the generated enable_alp_codec page read that history source, so users will keep seeing stale “experimental” wording. Suggested fix: update the history entry in the same PR.
Tests
  • ⚠️ The added coverage exercises column CODEC(ALP) and system.codecs, but not the new MergeTree setting-validation paths in registerStorageMergeTree / MergeTreeData::checkAlterSettings. A small stateless test around CREATE TABLE ... SETTINGS default_compression_codec = 'ALP' plus ALTER TABLE ... MODIFY|RESET SETTING would prove the new wiring.
  • ⚠️ 05024_codec_gate_settings_match_registered_codecs.sql now checks only the settings→codec direction. A focused check for the reverse invariant (every registered gated codec has a real builtin switch) would catch the current fail-open in getGateTier.
Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.30% 87.30% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 106/113 (93.81%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 25, 2026
/// profile, which is where such a config default can be legitimately allowed). `FORCE_RESTORE` is
/// documented to skip all sanity checks and is left alone.
if (args.mode != LoadingStrictnessLevel::FORCE_RESTORE && !local_settings[Setting::allow_experimental_codecs])
if (args.mode != LoadingStrictnessLevel::FORCE_RESTORE)

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.

validateCodecString still accepts float-only codecs in these no-column-type MergeTree settings. With enable_alp_codec = 1, default_compression_codec = 'ALP' passes here because the null-type guard only rejects lossy codecs; CompressionCodecALP is built with its fallback float_width = 8 and then reused as the table's implicit CODEC(Default) for every column. A non-float stream (for example a String column, or marks_compression_codec) will later hit Cannot compress with ALP codec, data size ... is not aligned to 8 at write time.

These settings need to reject codecs that only make sense for floating-point column payloads when column_type == nullptr, not just lossy codecs. A focused stateless test around default_compression_codec = 'ALP' on a non-float table would catch this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

True, but this is a pre-existing gap, not introduced here. @groeneai please open an issue with a repro. Be laconic

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Filed: #116374

Two corrections to the finding above, from running it on 26.7:

  • Not ALP-specific and needs no flag. FPC is non-experimental and hits the same gap: default_compression_codec = 'FPC' on a String column is accepted at CREATE and fails at INSERT with Code: 36 ... not applicable for String, while CODEC(FPC) on the column is rejected at CREATE. The missing guard is the column_type && term at CompressionFactoryAdditions.cpp:291, not the lossy-only null-type check.
  • marks_compression_codec = 'ALP' and primary_key_compression_codec = 'ALP' on a String table both insert fine, so the String-column claim for those two does not hold. primary_key_compression_codec = 'ALP' does fail, but only with a String sort key, and with Code: 270 ... not aligned to 8.

codec_family_name,
enable_setting_name);
const CodecEntry & entry = getEntry(codec_family_name);
if (const std::optional<SettingsTierType> tier = getGateTier(entry))

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.

This centralizes the dedicated gate, but only for callers that go through validateCodec*. We still have string-based codec entry points that call CompressionCodecFactory::get(...) directly, notably temporary_files_codec (src/Interpreters/TemporaryDataOnDisk.cpp) and the server <compression> selector (src/Storages/CompressionCodecSelector.h). After this PR, temporary_files_codec = 'ALP' or <method>ALP</method> still bypasses enable_alp_codec, so the new “tier is defined by the dedicated gate setting” rule is not actually global. For ALP it is worse than a pure gating leak, because those paths compress arbitrary spill/native bytes and can throw on buffers that are not 8-byte aligned.

If the gate is supposed to be the source of truth, every string-based codec entry point needs to validate through this path (or explicitly reject gated codecs) before constructing the codec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After this PR, temporary_files_codec = 'ALP' or <method>ALP</method> still bypasses enable_alp_codec

Correct. This PR is not a bug-fix to pre-existing problem

@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b0961bae6 with master 9d8eed34c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 711.97 MiB 708.91 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

1270 translation units recompiled, 8508 s compile time in total, 1270 of them have a recent master baseline.

Job report

@Algunenano Algunenano self-assigned this Aug 25, 2026

@Algunenano Algunenano left a comment

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.

I think that, since we are always using the family name in the setting, we can avoid changing the registration API and not pass the setting name; we can simply generate it and check that it exists

Comment thread src/Compression/CompressionFactory.cpp Outdated
{
const String expected_gate_name = fmt::format("enable_{}_codec", Poco::toLower(family_name));

if (gate_setting_name != expected_gate_name)

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 do we pass it during registration instead of generating it ourselves automatically?

@rienath rienath Aug 26, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for suggesting, really nice idea. Implemented

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.

Implemented is not quite true in the current code. getGateTier now does Settings::tryGetTierOfBuiltin(gate_setting_name) and simply returns nullopt when the builtin is missing (src/Compression/CompressionFactory.cpp:156-159), so a newly added codec without enable_<family>_codec is silently treated as ungated / Production instead of failing fast. The validation path in src/Compression/CompressionFactoryAdditions.cpp:199-204 then skips the check entirely.

The previous version threw a LOGICAL_ERROR for that case, so this refactor dropped the invariant that every gated codec must have a real builtin switch.

@mintlify

mintlify Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Aug 26, 2026, 11:35 AM

for (const auto & [name, entry] : family_name_with_codec)
if (!entry.gate_setting_name.empty())
result.push_back(entry.gate_setting_name);
for (const auto & family : family_name_with_codec)

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.

I don't like what AI is doing to our code :_(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is it the definition in if statement that upsets you? I quite like it and used it before "the awakening." Can remove if you prefer

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.

It's using for-if without brackets. It keeps doing it everywhere (also if-for) and so on. I consider anything that isn't a single statement should be inside brackets, and if is a multiple line statement

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Got it. I personally find it readable and more code fits into one screen. But I like a happy reviewer more: a5bb927

Valid minor improvement, but let's keep diff of this PR small

@rienath rienath left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Replied to both your comments, thanks for taking a look

Comment thread src/Compression/CompressionFactory.cpp Outdated
{
const String expected_gate_name = fmt::format("enable_{}_codec", Poco::toLower(family_name));

if (gate_setting_name != expected_gate_name)

@rienath rienath Aug 26, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for suggesting, really nice idea. Implemented

for (const auto & [name, entry] : family_name_with_codec)
if (!entry.gate_setting_name.empty())
result.push_back(entry.gate_setting_name);
for (const auto & family : family_name_with_codec)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is it the definition in if statement that upsets you? I quite like it and used it before "the awakening." Can remove if you prefer

Comment thread src/Core/Settings.cpp
@@ -8753,16 +8753,16 @@ Allows creation of tables with the `UNIQUE KEY` clause on MergeTree-family engin
If it is set to true, allow to specify any experimental compression codec.
)", EXPERIMENTAL) \
DECLARE(Bool, enable_alp_codec, false, R"(

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.

Promoting enable_alp_codec to BETA here leaves the history source stale: src/Core/SettingsChangesHistory.cpp:69 still says this setting enables the experimental ALP codec. system.settings_changes, system.documentation, and the generated enable_alp_codec page all read from that file, so users will keep seeing "experimental" after this change unless the history entry is updated in the same PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's ok, we do not rename the history source after promotion

Merged via the queue into master with commit fbc7824 Aug 28, 2026
699 of 704 checks passed
@rienath
rienath deleted the alp-beta branch August 28, 2026 12:37
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 28, 2026
alexey-milovidov added a commit that referenced this pull request Aug 29, 2026
Reconciled the PR with master's reworked codec gating (#116337): `ICompressionCodec::isExperimental`
is gone - a codec family is now gated by the tier of its `enable_<family>_codec` setting. `PCO`
keeps its `EXPERIMENTAL` tier, its `isExperimental` override is dropped, and the branch's
`experimentalCodecEnableSettingName` / `isExperimentalCodecEnabled` / `areExperimentalCodecsEnabled`
helpers are re-expressed on top of master's `getGateSettingName` / `getGateTier` as
`isCodecFamilyGated` / `isCodecStringGated` / `areCodecGatesSatisfied`. `system.codecs` gained a
`tier` column, so `01222_system_codecs` is updated.
alexey-milovidov pushed a commit to maxjustus/ClickHouse that referenced this pull request Nov 15, 2026
zxc 1.0.0 (ClickHouse#131071) freezes the wire format at v9; the upstream author
confirmed that later formats will be additive and that every future
decoder reads v9, and an audit of the 1.0.0 code found no defect.

Since ClickHouse#116337 a codec's maturity is the declared tier of its gate
setting, so moving `enable_zxc_codec` from EXPERIMENTAL to BETA is the
whole promotion: the gate error, `system.codecs.tier`,
`system.settings.tier` and `allow_feature_tier` all follow from it.
`allow_feature_tier` 1 and 2 now allow the setting; 3 still rejects it.

The 26.8 history record stays as released; a 26.11 record documents the
move, in the same shape as the other "moved to Beta" records. The rest of
the diff is text naming the tier: the codec docs badge and note, the
native protocol spec, the `01222_system_codecs` reference, the three
assertions on the gate message in `test_experimental_codec_config_default`
and two test comments. The default stays `false`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — b0961bae Deployed Aug 27, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

4 participants