Repository navigation
Fix projection lost or stale on a replica that fetched parts before applying ADD PROJECTION - #123185
Conversation
A replica can fetch a part before it applies the ALTER that adds a
projection: the part keeps `<p>.proj` on disk and in its checksums, but
`loadProjections` only loads the projections of the table metadata at
load time, so `p` is never loaded. Merges then drop `p` ("Projection p
is not merged because some parts don't have it"), and the other replica
refetches the projection-less part after CHECKSUM_DOESNT_MATCH, so both
replicas lose it. Mutations skip `p`, hardlink its stale directory and
load it, so queries answered from the projection return pre-mutation
data; on packed part storage the hardlink fails with NOT_IMPLEMENTED
and the mutation never finishes.
Treat a projection listed in the part's checksums but not loaded like a
loaded one: merges rebuild it when every source part carries it, and
mutation planning and the lightweight-delete rebuild mode include it.
Commit-order projections keep their unconditional rebuild, which also
covers the ones `loadProjections` skips on purpose when the part's
`_block_number`/`_block_offset` is invalidated (e.g. a part adopted by
ATTACH or REPLACE PARTITION FROM).
After a lightweight delete the test checks the normal projection only
for presence and a remaining row, because a rebuilt normal projection
still returns the deleted rows (ClickHouse#111791); an aggregate projection checks
that the rebuild happened.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings over 2 rounds) plus my own review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261001-052100 |
|
Workflow [PR], commit [3c6624b] Summary: ✅
AI ReviewSummaryThis PR teaches merge and mutation planning to treat projections that exist only in Final Verdict
LLVM Coverage ReportMeasured on commit 3c6624b.
Changed lines: Changed C/C++ lines covered: 48/55 (87.27%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units277 translation units recompiled, 2794 s compile time in total, 277 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…er-projection-partial-mutation In `MutationsInterpreter::prepare`, this branch moved the rebuild of broken and missing commit-order projections into an earlier block that also reads their columns. Master (ClickHouse#123185) added `hasUnloadedProjection` to the projection loop. The loop now skips a projection the part does not have unless it is on disk but not loaded and is not a commit-order projection. Commit-order projections are already handled by the earlier block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a projection that a
ReplicatedMergeTreereplica fetched with a part before applying theALTER TABLE ... ADD PROJECTIONthat added it: merges dropped the projection, and mutations kept its pre-mutation data, so queries answered from the projection returned wrong results.Description
On 26.8 (measured on 26.8.10.6), after
ALTER TABLE ... ADD PROJECTIONon aReplicatedMergeTreewith concurrent inserts, a replica that fetched a part before applying that ALTER drops the projection on the next merge, or keeps the projection's pre-mutation data afterALTER UPDATE, so queries answered from the projection return wrong results.This makes
03715_projection_settings_zookeeperflaky (master job, 26.8 job): in both server logs a replica fetches a part while applying the ALTER and its merge logsProjection p2 is not merged because some parts don't have it.Root cause:
loadProjectionsloads only the projections of the table metadata at load time, so a part fetched ahead of its table keepsp.projin its checksums but never loadsp, and merges and mutation planning only look at loaded projections.Change: a projection that is in the part's checksums but not loaded is treated like a loaded one. Merges rebuild it when every source part has it; mutations include it in their rebuild decision, also for lightweight delete in
rebuildmode and on packed part storage (where the mutation failed forever withNOT_IMPLEMENTED). Commit-order projections keep their unconditional rebuild.Alternative: postpone
GET_PARTuntil the replica applies the pendingALTER_METADATA. I did not, because fetches are deliberately not ordered after metadata alters and anALTER_METADATAcan wait behind a long mutation, stalling replication of every new part.The new test fails on master and 26.8.10.6 and passes with the fix on compact, wide and packed parts.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123185]
Version info
26.11.1.22-master(included in26.11and later)