Skip to content

Fix KeeperMap metadata compatibility with redundant parentheses - #115642

Merged
skuznetsov-clickhouse merged 4 commits into
masterfrom
codex/fix-keepermap-parenthesized-metadata
Aug 21, 2026
Merged

skuznetsov-clickhouse merged 4 commits into
masterfrom
codex/fix-keepermap-parenthesized-metadata

Conversation

@skuznetsov-clickhouse

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

Copy link
Copy Markdown
Contributor

Related: #114188

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

Allow KeeperMap readers to accept shared metadata when equivalent primary keys differ only by redundant outer parentheses.

Problem

KeeperMap stores the table definition in Keeper and previously compared its primary-key expression as formatted text. Builds that serialize the same expression as either key or (key) therefore reject an otherwise compatible shared table definition during CREATE-against-existing-path and ATTACH/startup.

Implementation

  • keep the existing writer spelling and never rewrite compatible shared metadata;
  • parse stored and local primary-key expressions and normalize only redundant outer parentheses that wrap one complete expression;
  • require the remaining input to be exact normal formatter output, preserving strict rejection of malformed, terminated, commented, or genuinely different definitions;
  • use the same compatibility check in CREATE-against-existing-path and ATTACH/startup;
  • split columns from the primary-key section using its structural newline-delimited header.

This is intentionally a reader-side compatibility fix. A patched node accepts either spelling, but an unpatched node may still reject metadata serialized in the spelling it does not understand. Therefore every version participating in a rolling deployment must contain this fix; in particular, the same reader change must be backported to 26.4. Rewriting the shared znode here would not solve compatibility safely because it could replace the spelling with one rejected by another unpatched peer.

The implementation uses parser and formatter APIs present in both current master and 26.4. It does not depend on formatIgnoringRedundantParentheses() added by #114188, so the same compatibility rule can be backported to 26.4.

Tests

The stateless SQL regression covers both directions (key stored with (key) local and (key) stored with key local), verifies that compatible CREATE and ATTACH do not rewrite the Keeper znode, and checks data access after ATTACH. It also verifies rejection of a different key, malformed (key, and terminated key; metadata, plus a primary-key expression containing the metadata header text.

Red-before was reproduced with embedded Keeper on official ClickHouse 26.4.5.143 and 26.7.1.1315: after changing stored metadata from key to (key), DETACH + ATTACH left the table in INVALID_STATE (Code 668). Local git diff --check and a snapshot-bound hostile review passed. Green-after remains a CI gate for this commit and for the future 26.4 backport.


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

Version info

  • Merged into: 26.8.1.1874 (included in 26.8 and later)
  • Backported to: 26.7.6.6, 26.6.4.11

Mixed-version servers can serialize equivalent KeeperMap primary key expressions as either key or (key), causing shared metadata validation to reject a compatible table definition.

Normalize new metadata and compare parsed canonical primary keys while retaining strict rejection of malformed or genuinely different definitions. Add an integration regression that seeds the legacy Keeper state directly.

Local checks: git diff --check; Python byte-compilation; SQL syntax parsing. Full build and integration execution are deferred to CI because this worktree has no initialized submodules or container runtime.
Seed legacy parenthesized Keeper metadata through system.zookeeper, verify canonical writer and strict rejection cases, and remove the Python-only fixture. Also size the compatibility parser to the already-loaded expression instead of the unrelated default query limit.

Verified red-before on official 26.7.1.1315 with chctl, git diff checks, and a snapshot-bound Luna Max hostile review. Full green execution remains CI-gated.
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0b07b3]

Summary: ✅


AI Review

Summary

This PR teaches patched KeeperMap nodes to treat primary key: key and primary key: (key) as equivalent on CREATE and ATTACH, and the new stateless test covers that reader-side tolerance. I do not think it fully delivers the rolling-upgrade compatibility promised in the title and description, because it deliberately leaves already-parenthesized metadata untouched in Keeper; unpatched 26.4 peers on the same shared path still reject that raw text.

Findings

❌ Blockers

  • [src/Storages/StorageKeeperMap.cpp:521-523, 760-765; tests/queries/0_stateless/05024_keeper_map_parenthesized_metadata.sql:49-60] The new compatibility check only makes patched servers tolerant of stored primary key: (key) metadata; it never repairs the znode, and the regression now explicitly asserts that the stored metadata remains primary key: (key)\n after CREATE and ATTACH. That means an unpatched 26.4 replica on the same shared Keeper path still sees the old raw text and keeps failing the same metadata check during a rolling deployment, so the mixed-version contract is still broken for already-polluted paths. Suggested fix: either restore a safe versioned write-back to canonical metadata once semantic equality is proven, or narrow the PR/changelog contract to patched-reader compatibility only and document that old replicas still cannot rejoin a path whose metadata was already serialized as (key).
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: address the remaining mixed-version incompatibility for already-parenthesized metadata, or explicitly narrow the promised behavior so the PR no longer claims to fix rolling-upgrade compatibility across patched and unpatched replicas.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 69/85 (81.18%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 20, 2026
Comment thread src/Storages/StorageKeeperMap.cpp Outdated
{
const auto canonical_zk_pk = tryCanonicalPrimaryKey(zk_pk);
const auto canonical_local_pk = tryCanonicalPrimaryKey(local_pk);
pk_equal = canonical_zk_pk && canonical_local_pk && *canonical_zk_pk == *canonical_local_pk;

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.

isMetadataStringEqual only makes the current server tolerant of stored primary key: (key); it never repairs the znode after proving semantic equality. If a buggy/newer replica has already written (key), this branch returns success but leaves Keeper unchanged, so an older reader such as 26.4 still sees the same raw text and rejects the table on the same shared path. To actually restore mixed-version compatibility, this path needs to rewrite zk_metadata_path back to the canonical metadata_string once the canonicalized forms compare equal.

Equivalent primary-key metadata with redundant parentheses was accepted but left unchanged, so older replicas could keep rejecting the shared definition. Normalize only the primary-key suffix through a versioned Keeper CAS, preserve stored column metadata, and retry concurrent changes. Extend the SQL regression to verify the persisted repair.
@mstetsyuk mstetsyuk self-assigned this Aug 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c0b07b319 with master d9e065c8f (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 704.52 MiB 701.47 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

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

Job report

Writer-side canonicalization and znode repair make rolling mixed versions unsafe and depend on a formatter unavailable in 26.4. Keep the writer spelling and shared metadata untouched, and normalize only redundant whole-expression parentheses while comparing metadata in CREATE and ATTACH paths.

Extend the SQL regression to cover both spelling directions, unchanged stored metadata, ATTACH, malformed and terminated input, and a delimiter inside the expression. Verified with git diff --check, red-before probes on official 26.4.5 and 26.7.1, and snapshot-bound hostile review; green-after remains a CI gate.
@skuznetsov-clickhouse

Copy link
Copy Markdown
Contributor Author

Addressed by narrowing the changelog and PR contract to patched-reader compatibility. This change intentionally does not rewrite shared Keeper metadata: patched nodes accept both key and (key), while an unpatched node may still reject the spelling it does not understand. The same reader fix therefore needs to be present in every participating release line, including the planned 26.4 backport. A write-back would not be safe during a mixed-version rollout because it could replace the shared spelling with one rejected by another unpatched peer. The SQL regression covers both spelling directions and verifies that compatible CREATE/ATTACH leave the znode unchanged.

@skuznetsov-clickhouse
skuznetsov-clickhouse added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit 400ba9d Aug 21, 2026
353 of 354 checks passed
@skuznetsov-clickhouse
skuznetsov-clickhouse deleted the codex/fix-keepermap-parenthesized-metadata branch August 21, 2026 19:06
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 21, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 21, 2026
Backport #115642 to 26.7: Fix KeeperMap metadata compatibility with redundant parentheses
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 21, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 21, 2026
Backport #115642 to 26.6: Fix KeeperMap metadata compatibility with redundant parentheses
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 28, 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.4-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants