Skip to content

Canonicalize KeeperMap primary key metadata writes - #116369

Merged
skuznetsov-clickhouse merged 2 commits into
masterfrom
codex/canonicalize-keepermap-pk-writes
Aug 26, 2026
Merged

skuznetsov-clickhouse merged 2 commits into
masterfrom
codex/canonicalize-keepermap-pk-writes

Conversation

@skuznetsov-clickhouse

@skuznetsov-clickhouse skuznetsov-clickhouse commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #115642

Why

ClickHouse 26.6 started storing a redundant outer pair of parentheses around a
single-expression KeeperMap primary key. A 26.4 server expects the previous
spelling and can reject that metadata during a rolling upgrade or rollback.

The tolerant reader fix was merged first in #115642/#70018 and backported in
#70229/#70230. This PR stops new KeeperMap paths from producing the incompatible
spelling.

What changed

For a single-expression primary key, format the already-parsed expression AST
without its top-level parenthesized flag. This avoids reparsing with unrelated
parser limits and preserves parentheses required inside the expression.

Expression-list spelling is deliberately unchanged because the tolerant reader
canonicalizes one complete expression. Existing Keeper znodes are never
rewritten; the change applies only when new metadata is created.

Compatibility and rollout

This targets 26.8 and must be backported to 26.6, where the writer spelling first
changed.

Deploy the tolerant reader to every existing 26.6/26.7 peer before deploying
this writer change. An unpatched 26.6/26.7 reader still rejects the canonical
26.4 spelling; the mixed-version test includes that expected failure boundary.

Tests

  • Incremental clickhouse build on the disposable dev VM.
  • Keeper-backed stateless regression: baseline reference mismatch, patched
    candidate exact reference match.
  • 13/13 preregistered Chaos Lab mixed-version cases matched for 26.4, 26.6,
    26.7, and 26.8, including rolling restart/rollback and no-rewrite checks.
  • Final AST candidate reproduced the exact persisted output after removing the
    writer-side reparse.

No documentation update is needed: this restores an internal persisted spelling
and does not change the SQL interface.

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

KeeperMap now writes single-expression primary keys without redundant outer parentheses, so metadata created by newer servers remains readable by ClickHouse 26.4 during supported rolling upgrades and rollbacks.


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

Version info

  • Merged into: 26.9.1.158 (included in 26.9 and later)
  • Backported to: 26.8.1.2014, 26.7.6.52, 26.6.4.59

Newer writers persist an optional outer pair of parentheses around a single primary-key expression. Older readers reject the shared KeeperMap definition during mixed-version upgrades.

Reuse the compatibility canonicalizer when creating metadata so new paths use the older spelling. Preserve required parentheses, expression-list spelling, and existing znodes.

Add a Keeper-backed regression covering canonical writes, legacy attach/read behavior, and the expression-list fallback.

Verified with an incremental build, an exact baseline/candidate stateless run, the 13-case Chaos Lab mixed-version matrix, and local hostile review.
Canonicalize the already-parsed single-expression AST instead of sending formatted text back through parser defaults. Clone the expression, clear only its top-level parenthesized flag, and keep expression-list spelling unchanged. This covers DDL accepted with raised parser limits while preserving required inner parentheses.

Verified with an incremental ClickHouse build and an exact Keeper-backed stateless candidate/reference run.
@skuznetsov-clickhouse skuznetsov-clickhouse added pr-bugfix Pull request with bugfix, not backported by default v26.6-must-backport labels Aug 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2cff955]

Summary: ✅


AI Review

Summary

This PR changes the KeeperMap metadata writer to strip only the top-level parenthesized flag from single-expression primary keys while leaving multi-expression lists unchanged, which matches the reader-side compatibility boundary already implemented in #115642. I traced the only metadata-write path in StorageKeeperMap, checked the attach-time compatibility logic against the new writer behavior, and reviewed the new 05043 Keeper-backed regression coverage; I did not find a remaining correctness or compatibility issue in the current code.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

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

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

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2cff955c0 with master 583fc5270 (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 710.09 MiB 707.05 MiB -3.04 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

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

Job report

@nikitamikhaylov nikitamikhaylov self-assigned this Aug 25, 2026
@skuznetsov-clickhouse
skuznetsov-clickhouse added this pull request to the merge queue Aug 26, 2026
Merged via the queue into master with commit 1a47863 Aug 26, 2026
354 of 356 checks passed
@skuznetsov-clickhouse
skuznetsov-clickhouse deleted the codex/canonicalize-keepermap-pk-writes branch August 26, 2026 12:26
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 26, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 26, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 26, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 26, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 26, 2026
Backport #116369 to 26.8: Canonicalize KeeperMap primary key metadata writes
nikitamikhaylov added a commit that referenced this pull request Aug 31, 2026
Backport #116369 to 26.6: Canonicalize KeeperMap primary key metadata writes
nikitamikhaylov added a commit that referenced this pull request Aug 31, 2026
Backport #116369 to 26.7: Canonicalize KeeperMap primary key metadata writes
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants