Repository navigation
Conversation
Preparation for the flat projection storage format (#108443): the layout-independent half of that work. The part-storage layer is reworked around an explicit owned projection set with struct Projection descriptors, seeded from the checksums.txt manifest, replacing ad-hoc ".proj" string paths and directory walks. On-disk format and behavior of healthy parts are unchanged. - IDataPartStorage gains getProjections/setProjections (the owned set; reads throw if it was never seeded, so residue of an unrelated same-named part is never silently adopted), detectProjections (an explicit disk-truth probe for the few places that must look at the disk), createProjection/renameProjection/removeProjection/ removeProjectionResidue, and getProjectionStorageForWrite, which requires the descriptor produced by createProjection so a writer can never build over an unswept directory. freezeRemote is folded into freeze(dst_disk). - checksums.txt is the authoritative manifest of which projections a part owns: loadProjections loads only manifest-listed projections, and mutations fold carried (hardlinked) projections into the new part's checksums before finalize, so the manifest commits atomically with the part. - checkDataPart iterates the declared projections against a disk scan: an owned-but-missing projection is reported broken instead of silently skipped, and a projection whose own checksums.txt is missing gets it recomputed from data and persisted. - The owned set is seeded from the manifest-driven disk probe only on the part LOAD path (loadColumnsChecksumsIndexes). The write path relies on the set maintained by createProjection/renameProjection: a probe at mutation finalize would miss directories still staged in a deferred object-storage transaction and lose the projection, surfacing as a query-time FILE_DOESNT_EXIST on a vacated tmp_mut_ path. - Tests: a gtest for the owned-set invariants; integration coverage for manifest desync/repair, CHECK TABLE classification, packed-storage projection lifecycle, and the object-storage rebuild/carry matrix ({full,packed} x {local,s3}) asserting fail-closed via CHECK TABLE. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [347ced2] Summary: ✅
AI ReviewSummaryThis PR reworks projection ownership around an explicit per-part owned set and fixes several real projection desync cases, but the invariant is not yet applied consistently. I found two correctness holes where a same-named stray projection directory can still escape the Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 879/971 (90.53%) · Uncovered code |
| if (IDataPartStorage::Projection::dirNameType(file_name) == IDataPartStorage::Projection::Status::Live) | ||
| owned_projection_dirs.push_back(file_name); | ||
| for (const auto & projection : metadata_snapshot->projections) | ||
| owned_projection_dirs.push_back(IDataPartStorage::Projection::dirName(projection.name, false)); |
There was a problem hiding this comment.
loadColumnsChecksumsIndexes is still treating a metadata-declared projection directory as owned even when checksums.txt never committed it. A concrete trace is a part created with materialize_projections_on_insert = 0: if a stray p.proj appears on disk, startup leaves it unloaded, but this candidate list still makes getProjections return it. The later hardlink-carry path in MutateTask and the packed freeze path in DataPartStorageOnDiskPacked both trust getProjections as authoritative, so that stray directory gets carried into the new part or shadow copy. That breaks the "checksums.txt is the commit point" contract the PR is trying to establish.
| const auto exception_message = getCurrentExceptionMessage(true); | ||
| /// A projection the part owns (loaded from its manifest or listed in checksums.txt) but whose | ||
| /// directory is gone is broken, not absent; skip only projections this part never materialized. | ||
| if (!projection_on_disk && !loaded && !checksums_txt.files.contains(projection_file)) |
There was a problem hiding this comment.
This skip condition flips as soon as a declared projection directory exists on disk, even if the parent manifest never listed it. In the repair path that means a stray same-named p.proj stops being ignored: loadChecksums calls checkDataPart, projection_on_disk is true, we compute projection_checksums, and lines 457-460 add p.proj to the regenerated checksums.txt. So a part that previously followed the "checksums.txt is authoritative" rule can adopt residue just because its own manifest was lost.
| /*initialize=*/ !to_detached && !params.external_transaction); | ||
|
|
||
| return frozen_storage; | ||
| seedFrozenCopy(*new_storage); |
There was a problem hiding this comment.
By the time we reach seedFrozenCopy, the base freeze / clonePart path has already copied the whole part directory recursively. That means Full storage still carries residue.proj and *.tmp_proj into shadow or moved clones even though the new owned-set API is supposed to be the authority for projection lifecycle. The packed path below was rewritten to recurse from getProjections; this base path still bypasses that invariant for Full parts.
|
Dear @arsenmuk, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
Changelog category (leave one):
Changelog entry:
Rework projection handling in the MergeTree part storage layer around an explicit, manifest-driven projection set. Fixes projections lost by mutations on object-storage disks;
CHECK TABLEnow reports a projection the part owns but whose directory is missing as broken instead of skipping it, and regenerates a projection's lostchecksums.txtfrom data instead of failing the whole part.Preparation for the flat projection storage format (#108443) — the layout-independent half, split out to be reviewable on its own. The on-disk format is unchanged; behavior of healthy parts is unchanged.
Major changes
Owned projection set on
IDataPartStorage. Each part storage tracks the projections its part owns asProjectiondescriptors (getProjections/createProjection/renameProjection/removeProjection), replacing ad-hoc".proj"string paths and directory walks across the create/rename/freeze/remove/check paths.checksums.txtis the authoritative manifest: only manifest-listed projections are loaded, and an on-disk directory the manifest does not list is not adopted at load.Fix: mutations lost projections on object-storage disks (query-time
FILE_DOESNT_EXISTon a vacatedtmp_mut_*path). Object-storage disks run deferred transactions (Do not use fake tx for object storage disks #89658), so a disk probe at mutation finalize cannot see the rebuilt projection's still-queued rename; the owned set is now maintained by the write path itself and probed from disk only on part load. Covered by the newtest_os_*matrix ({full, packed} × {local, s3}).Fix:
CHECK TABLE/ part load report a projection the part owns but whose directory is missing as a broken projection (previously skipped silently), and regenerate a projection's missingchecksums.txtfrom data (previously this failed the whole part).Side changes
checksums.txtbefore finalize, so the manifest commits atomically with the part.checksums.txtrestores the projection entries (previously the repaired manifest silently dropped every projection).freezeRemoteis folded intofreeze(dst_disk); packedfreezecopies projections from the owned set instead of a disk walk, so residue directories are not carried into clones.createProjection, sweeping stale residue of a failed same-named attempt before download.RENAMErepoints loaded projection sub-part storages (their roots kept the old table path).<name>.projname, independent of the on-disk layout.MergeTreeData::reclaimStaleTemporaryDirectory.test_projection_storage_format— manifest desync/repair,CHECK TABLEclassification, packed-storage projection lifecycle, and the object-storage rebuild/carry matrix.Exact scenarios changed (vs master)
CHECK TABLEon a part owning a projection whose directory is missing: reports broken projection; was silent (c).CHECK TABLE/ load of a projection missing its ownchecksums.txt: recomputed and persisted; previously failed the part (d).checksums.txt: ignored (not adopted); previously could be picked up by the disk walk.test_broken_projections(the pre-existing suite) passes unchanged.