Repository navigation
Description
Describe what's wrong
PR #99623 fixed parts with unknown projections being marked as lost, but the fix is incomplete on the receiver side (replica that fetches the part). After a successful fetch, a subsequent CHECK TABLE or the background part-check thread calls checkDataPart and fails with NO_FILE_IN_DATA_PART, marking the part as broken and triggering an infinite re-fetch loop.
Root cause:
downloadPartToDisk (fixed by #99623) patches data_checksums in memory so the immediate checkEqual passes — but checksums.txt is still written to disk verbatim from the sender, including the pp.proj entry that was never transferred (because the projection is unknown, getProjectionParts() returns 0 for it so send_projections loop skips it).
When checkDataPart later runs on replica 2:
projections_on_diskis built by iterating the part directory for.projsubdirectories —pp.projdoes not exist on disk, soprojections_on_diskstays empty for it.getProjectionParts()does not includepp(unknown projection).- The new guard added by redo Part with unknown projections should not be marked as lost forever #99623 —
if (!projections_on_disk.empty())— does not fire. checksums_txt(loaded from disk) still haspp.proj.checksums_datadoes not havepp.proj(directory never existed on disk).checksums_txt.checkEqual(checksums_data)throwsNO_FILE_IN_DATA_PART.
The part is marked broken → re-fetched from replica 1 → same outcome → infinite loop.
The fix in checkDataPart.cpp only handles the local-attach case (.proj directory exists on disk but is unknown to the table, i.e. projections_on_disk is non-empty). It does not handle the fetch case (checksums.txt references a .proj entry whose directory was never transferred).
Does it reproduce on the most recent release?
Yes — introduced/unblocked by #99623 (merged 2026-03-21).
How to reproduce
Requires ReplicatedMergeTree with 2 replicas and a ZooKeeper/Keeper.
-- On both replicas:
CREATE TABLE t (x Int32, y Int32, PROJECTION p (SELECT x, y ORDER BY x))
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/t', '{replica}')
PARTITION BY intDiv(y, 100) ORDER BY y
SETTINGS max_parts_to_merge_at_once = 1;
-- On replica 1:
INSERT INTO t SELECT number, number FROM numbers(7);
ALTER TABLE t ADD PROJECTION pp (SELECT x, count() GROUP BY x);
ALTER TABLE t MATERIALIZE PROJECTION pp SETTINGS mutations_sync=2;
ALTER TABLE t DETACH PARTITION 0;
-- On replica 2: remove the detached copy so it is forced to re-fetch later
ALTER TABLE t DROP DETACHED PARTITION 0 SETTINGS allow_drop_detached=1;
-- On replica 1: drop projection while part is detached, then re-attach
ALTER TABLE t DROP PROJECTION pp;
ALTER TABLE t ATTACH PARTITION 0;
-- On replica 2: sync, then run CHECK TABLE
SYSTEM SYNC REPLICA t;
SELECT count() FROM t; -- returns 7 (data is fine)
CHECK TABLE t; -- fails: NO_FILE_IN_DATA_PART for pp.projThe SELECT succeeds because data is intact. CHECK TABLE fails because checksums.txt references pp.proj but the directory was never transferred. The background ReplicatedMergeTreePartCheckThread will then mark the part as broken and re-fetch it from replica 1, creating a loop.
The same state can be reproduced without replication — manually remove a .proj directory from a detached part whose checksums.txt still references it, then attach and run CHECK TABLE:
# After the detach step above:
rm -rf /var/lib/clickhouse/data/default/t/detached/<part_name>/pp.projALTER TABLE t ATTACH PARTITION 0;
SELECT count() FROM t; -- 7, works
CHECK TABLE t; -- Code: 226. NO_FILE_IN_DATA_PART: No file pp.proj in data partSuggested fix
In checkDataPart.cpp, after the existing new block (which handles projections whose directories exist on disk), also remove from checksums_txt any .proj entries that are referenced in checksums_txt but absent from checksums_data (i.e., whose directory was never on disk):
/// Also handle the case where checksums_txt references a .proj entry whose
/// directory is absent from disk entirely (e.g. receiver after an inter-replica
/// fetch of a part with an unknown projection — checksums.txt was transferred
/// but the .proj directory was not).
for (auto it = checksums_txt.files.begin(); it != checksums_txt.files.end(); )
{
if (it->first.ends_with(".proj") && !checksums_data.has(it->first))
{
is_broken_projection = true;
it = checksums_txt.files.erase(it);
}
else
++it;
}The test 03822_attach_with_unknown_projection.sh should also add CHECK TABLE t_unknown_proj_2 after SYSTEM SYNC REPLICA t_unknown_proj_2 to cover this path.
Related
- redo Part with unknown projections should not be marked as lost forever #99623 (incomplete fix)
- Part with unknown projections should not be marked as lost forever #95952 (original fix, reverted)
- Revert "Part with unknown projections should not be marked as lost forever" #95991 (revert of Part with unknown projections should not be marked as lost forever #95952)
Activity
CheSema commentedon Mar 23, 2026
It looks like you are ready to bring PR with the test and the fix, is that right?
zlareb1 commentedon Mar 23, 2026
sure, I will make the fix.
Fix checkDataPart failing with NO_FILE_IN_DATA_PART for fetched parts…
Add dedicated SQL test for checkDataPart with fetched part and unknow…
fix(MergeTree): strip phantom projection entries from in-memory check…
test: add CHECK TABLE on replica 2 after fetch with unknown projection
fix(MergeTree): strip phantom .proj entries in checkDataPart before c…
zlareb1 commentedon May 5, 2026
@groeneai please fix this in a separate PR.
groeneai commentedon May 5, 2026
@zlareb1 — fix PR up: #104098.
Root cause: when a replica fetches a part with an unknown projection, the sender's
getProjectionPartsexcludes it so the.proj/subdirectory is not transferred, butchecksums.txtis copied verbatim and still references it. The receiver'scheckDataPartthen throwsNO_FILE_IN_DATA_PARTfromcheckEqual, the part is marked broken, and the cycle repeats indefinitely.Fix: strip orphan
.projentries fromchecksums_txtbeforecheckEqualwhen the corresponding directory is not on disk — mirrors the existing PR #99623 block that handles the symmetric local-attach variant.Includes a new regression test (
04203_100413_check_table_unknown_projection_after_fetch.sh) that exercises the fetch path and verifiesCHECK TABLEsucceeds on the receiving replica. Verified 20/20 passes with random settings; pre-fix the test fails deterministically withPart 0_5_5_0 looks broken. Removing it and will try to fetch..Reviewers pinged: @CheSema (original #99623 author) and @KochetovNicolai (comp-projections).
zlareb1 commentedon Aug 12, 2026
@groeneai should this still be open? or we can close this?
groeneai commentedon Aug 12, 2026
Fixed on master, but not in any active release branch, so I would hold off closing it.
The fix landed inside #108118 (merged 2026-07-22), commit 04235cb by @ Algunenano:
checkDataPartnow also drops leftoverchecksums.txtentries for.projdirectories that are unknown to the metadata and absent on disk, before the base-partcheckEqual. My #104098 is closed as superseded by it, and #108118's version is the better one since it keeps genuine base-file corruption fatal on fetch.I checked by running it rather than by reading the code, using the non-replicated variant from the issue (drop
pp.projfrom a detached part, drop the projection, re-attach,CHECK TABLE):CHECK TABLEpasses, data intact,OPTIMIZE FINALsucceeds.0_5_5_0 0 Code: 226. DB::Exception: No file pp.proj in data part. (NO_FILE_IN_DATA_PART)The part is genuinely in the reported state in both runs: after
ATTACHitschecksums.txtstill listspp.projwith no such directory on disk, sochecksums.txtis not being regenerated underneath the check.The new block is absent from
checkDataPart.cppon all five active release branches. 26.7, 26.6 and 26.5 carry only the earlier #99623 in-memory patch, which is the incomplete state this issue was filed about; 26.3 and 25.8 predate #99623 entirely.Two things worth knowing before you decide:
03822_attach_with_unknown_projection.shdoes not cover this case, despite its comment claiming the fetch path. It runsCHECK TABLEonly on the sending replica; on the fetching replica it assertsSELECT count()and the sums, and the point of this issue is that theSELECTsucceeds whileCHECK TABLEfails. CIDB agrees: over the last 30 days it is 98 OK and 0 FAIL on 26.7, 122 OK on 26.6, 113 OK on 26.5, green on every branch where the bug still reproduces.I can send a test-only PR adding a
CHECK TABLEassertion on the receiving replica in 03822, which would both pin master and fail honestly on the release branches, if you or @ CheSema want that. The backport is a separate call: the useful hunk is about 20 lines ofcheckDataPart.cpp, so labelling #108118 as a whole is probably not what you want. Closing is your call, not mine.fix(MergeTree): strip phantom projection entries from in-memory check…
test: add CHECK TABLE on replica 2 after fetch with unknown projection
fix(MergeTree): strip phantom .proj entries in checkDataPart before c…