Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-5:20260722-105200 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-5:20260722-105200 |
|
cc @hanfei1991 @tiandiwonder — could you review this? It makes |
|
Workflow [PR], commit [32d3ffe] Summary: ✅
|
| /// power loss erases the acknowledged snapshot (for a hardlink snapshot the directory entries | ||
| /// *are* the snapshot). Gated on `fsync_part_directory`; a no-op on remote disks; skipped | ||
| /// under an external transaction (its writes are not materialized on disk here). | ||
| if (params.fsync_part_directory && !params.external_transaction && !disk->isRemote()) |
There was a problem hiding this comment.
!disk->isRemote() turns the new durability path off for every DiskObjectStorage, but a same-disk FREEZE there still creates a brand-new local metadata tree under shadow/... via DiskObjectStorage::createHardLink / createDirectories. Those metadata transactions (MetadataStorageFromDiskTransaction::commit -> WriteFileOperation::execute) only rewrite files and directory entries; they do not sync either the files or their parent directories. So a power cut after an acknowledged FREEZE can still drop the snapshot for object-storage tables even with fsync_part_directory = 1.
If the intention is to close this bug for all supported FREEZE backends, this needs a durability step for the metadata-storage side as well. Otherwise we should reject or very explicitly surface that fsync_part_directory is unsupported for object-storage FREEZE, instead of silently no-oping here.
CI finish ledger — fd401daCI fully finished (Finish Workflow passed). Every failure below is a pre-existing chronic
Session id: cron:our-pr-ci-monitor:20260723-023000 |
ALTER TABLE ... DETACH PARTITION hardlink-clones the part into detached/ via makeCloneInDetached -> DataPartStorageOnDiskBase::freeze and fsyncs none of it, then commits an empty covering part that removes the rows from the active set (which IS fsynced when fsync_part_directory is on) and lazily deletes the original. The commit that removes the data is durable while the clone that preserves it is not, so on btrfs a power loss right after the acknowledgement rolls back the un-synced clone directory entries: detached/ ends up empty, the rows are gone from the active set, and the original is loaded as covered and cleaned up. The only copy of the detached data is destroyed. (ext4/xfs happen to persist the earlier clone through the single journal, an ordering accident.) DataPartStorageOnDiskBase::freeze now, when fsync_part_directory is set (and on a local disk, outside an external transaction), fsyncs the clone's part-directory subtree bottom-up (part dir plus projection subdirs, i.e. the hardlink entries) and every ancestor directory from the clone's immediate parent (detached/) up to and including the disk root. fsync(dir) persists the entries inside dir, not dir's own entry in its parent, and detached/ is created at table init without an fsync while normal part commits fsync only the child part dir, so the parent chain must be synced for the clone to survive a first-ever detach. freeze() returns before the caller commits the covering part, so this synchronous fsync orders the clone durable before that commit. Gated on the existing fsync_part_directory MergeTree setting (default false), so default behavior is unchanged and no SettingsChangesHistory entry is needed. A no-op on remote/object-storage disks (getDirectorySyncGuard returns nullptr). This is the DETACH variant of the same unsynced freeze/Backup clone path as issue ClickHouse#111331 (FREEZE, addressed in ClickHouse#111393); a FREEZE-only fix does not close it. Closes: ClickHouse#111382 Co-Authored-By: Claude fable-5 <[email protected]>
ALTER TABLE ... FREEZE builds the shadow/ snapshot with createDirectories + createHardLink and fsyncs none of it; the only sync in the FREEZE path is shadow/increment.txt. For a hardlink snapshot the data and inodes are already durable, but the new directory entries are not, so a power loss right after FREEZE acknowledges leaves nothing to archive even though every fsync-family setting was enabled on the table. DataPartStorageOnDiskBase::freeze now, when fsync_part_directory is set (and on a local disk, outside an external transaction), fsyncs the created part-directory subtree bottom-up (part dir plus projection subdirs, i.e. the hardlink entries) and every ancestor directory up to and including the disk root. The disk root is the durability boundary: freezePartitionsByMatcher creates shadow/ without an fsync, so only fsyncing the root persists the shadow directory entry on the first FREEZE. This mirrors the part-clone rename() path, which already takes a getDirectorySyncGuard when fsync_part_dir is set. Gated on the existing fsync_part_directory MergeTree setting (default false), so default behavior is unchanged and no SettingsChangesHistory entry is needed. Closes: ClickHouse#111331 Co-Authored-By: Claude fable-5 <[email protected]>
fd401da to
278ec05
Compare
DataPartStorageOnDiskPacked::freeze() is an independent override that never read fsync_part_directory, so the previous commit's FREEZE durability fix only covered Full part storage. A packed part (chosen when min_bytes_for_full_part_storage / min_rows_for_full_part_storage / min_level_for_full_part_storage is set) was still non-durable on FREEZE in two ways: its snapshot directory entries were unsynced, and its rewritten data.packed archive (FREEZE copies the whole archive because keep_metadata_version is false) was finalized but never fsynced. Extract the Full override's directory-sync block into a shared protected helper DataPartStorageOnDiskBase::syncFrozenPartDirectory and call it from both freeze overrides, and fsync the rewritten data.packed by requesting a member-buffer sync in the packed copy loop. The content sync uses the deferred need_sync flag that PackedFilesWriter::finalize propagates, so it also covers each projection's archive (the projection recursion runs under the part's shared transaction). Strengthen 04621_freeze_fsync_part_directory to exercise both the Full and Packed layouts explicitly with exact DirectorySync counts and a FileSync content oracle. Co-Authored-By: Claude fable-5 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review of the packed-storage extension by an independent model (engine: codex; 2 findings, both nits; bounded: 1 full pass + 1 fix round + delta rechecks).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-3:20260724-133100 |
|
Follow-up commit Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-3:20260724-133100 |
CI finish ledger — fd401daCI fully finished (Finish Workflow passed). Every failure below is a pre-existing chronic
Session id: cron:our-pr-ci-monitor:20260723-023000 |
…-freeze-fsync # Conflicts: # src/Storages/MergeTree/IDataPartStorage.h
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 45/45 (100.00%) · Uncovered code |
CI finish ledger - 21e0354CI fully finished: CIDB reports zero failing tests on this commit, and the one non-green check is the known
Evidence that this is the tracked arm_darwin family and not a new failure:
Session id: cron:our-pr-ci-monitor:20260728-233000 |
…-freeze-fsync The sibling DETACH PARTITION durability fix (ClickHouse#111426) merged into master on 2026-08-03 and carried the shared machinery this branch had introduced: syncDirectoryTree, the subtree+ancestor walk (now the free function fsyncFrozenCloneTree in DataPartStorageOnDiskBase), the ClonePartParams fsync_part_directory field, and the calls from both freeze overrides. Resolution therefore drops this branch's now-duplicated copies in favour of master's, rather than keeping both: - IDataPartStorage.h: identical fsync_part_directory member on both sides, only the doc comment differed. Took master's comment verbatim. - DataPartStorageOnDiskBase.{h,cpp}: dropped the private member function syncFrozenPartDirectory and its call, keeping master's equivalent free function fsyncFrozenCloneTree. Master's call site is strictly better placed: it runs after save_metadata_callback, so the freeze metadata the callback writes is covered by the same fsync. - DataPartStorageOnDiskPacked.cpp: dropped the duplicate directory-sync call, keeping master's. A naive keep-both would have walked and fsynced the whole clone subtree twice per frozen part. What remains unique to this branch is exactly the ClickHouse#111331 fix and its guard: the FREEZE call site in freezePartitionsByMatcher now populates fsync_part_directory from the table's setting (master only wires up the DETACH call site, so ALTER TABLE ... FREEZE still acknowledged a non-durable snapshot), the fsync of a rewritten data.packed archive's contents, and the 04621 regression test.
The merge with master brought in the sibling DETACH fix's projection handling,
which unconditionally clears fsync_part_directory before the nested per-
projection freeze. That is correct for the directory walk it was written for,
but the same flag also gates the fsync of a rewritten projection archive's
contents, so clearing it dropped the projection half of the FREEZE content
durability this branch adds. Test 04621 caught it deterministically:
packed proj content: projection archive synced FAILED
(FileSync on=2 off=1 delta=1, expected 2)
10 of 10 runs failed. Clear the flag only when nothing else already suppresses
the nested directory walk. In this freeze path the nested call always receives
external_transaction = dest_storage->transaction, and a non-null
external_transaction already excludes the nested directory walk via the
existing `!params.external_transaction` term of the fsync gate, so the subtree
is still walked exactly once from the top level while the projection archive's
contents are fsynced again.
Verified on the merged tree (build id 85e8b287): 04621 10/10 pass with the
guard, and reverting just the guard fails 3/3 with the signature above, so it
is load-bearing rather than defensive. The merged DETACH regression test 04622
also passes 10/10, so the shared path is unaffected: DETACH sets to_detached,
which skips the archive-rewriting branch entirely.
`.claude/CLAUDE.md` requires function names written as `f` rather than `f()`, and literal names wrapped in inline code. Also drop the cross-file rationale about which callers share the transaction: that belongs in the commit history (the previous commit states it), not at this line. Comment only; no behaviour change.
The setting-off arm only asserted the plain table's DirectorySync, while the projection run's count was collected and never checked. An implementation that gated the part directory correctly but fsynced projection subdirectories unconditionally would have produced the complete reference output, so the default-behaviour-unchanged contract was only half covered. Proven live rather than assumed: with the nested projection freeze forced to fsync regardless of the setting, the new assertion reports "with projection = 8 (expected 0)" and the test fails, while the unmutated binary still passes with an unchanged reference.
The content oracle only compared the setting-on and setting-off FileSync counts. A build that fsynced the rewritten archive unconditionally and then added the requested sync on top would produce the same deltas off a higher base, so the default-behaviour-unchanged half of the contract was unasserted. Assert the baseline as well. Freeze itself writes only increment.txt, so the setting-off count is 1 for both layouts; measured stable at 1 across six independent runs with settings randomization enabled. Proven live: with an extra unconditional write_buf sync in the archive copy loop the new line reports "baseline FileSync = 2 / with projection 3 (expected 1 and 1)" and the test fails, while the unmutated binary passes.
|
Merged master. The scope of this PR shrank substantially, so a note for whoever reviews it. The sibling What remains here is the part master does not do: One real defect came out of the merge rather than the conflict markers. Master's projection loop clears The flag is now cleared only when nothing else already suppresses the nested walk; a non-null I also strengthened the test's setting-off assertions, which covered only half the default-behaviour-unchanged contract: the projection run's Validated on the merged tree: 04621 10/10 and the merged 04622 |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 1cc6eddCI fully finished on this head: 174 of 174 check-runs completed (156 success, 17 skipped, Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The only failure on this head is that fuzzer-found logical error, and the build was produced Session id: cron:our-pr-ci-monitor:20260805-023000 |
…-freeze-fsync # Conflicts: # src/Storages/MergeTree/DataPartStorageOnDiskPacked.cpp # src/Storages/MergeTree/MergeTreeData.cpp
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ALTER TABLE ... FREEZEnow fsyncs the snapshot it creates when the table'sfsync_part_directorysetting is enabled: the snapshot directories and the chain up to the disk root, plus the rewrittendata.packedarchive for packed part storage. Previously the freeze path fsynced nothing butshadow/increment.txt, so a power loss right afterFREEZEwas acknowledged could erase the whole snapshot. Default behaviour is unchanged.Description
Closes: #111331
ALTER TABLE ... FREEZEbuilds its snapshot withcreateDirectoriespluscreateHardLink(Full storage), or by rewritingdata.packed(Packed storage), and fsyncs none of it. For a hardlink snapshot the file data is already durable but the new directory entries are not, so a power loss between the acknowledgement and the operator's archive step drops every new directory entry, i.e. the whole snapshot.The directory-fsync machinery this needs is already in master: the sibling
DETACH PARTITIONdurability fix (#111426) merged thefsync_part_directoryclone parameter,fsyncFrozenCloneTree, and the calls from both freeze overrides. It only wires up theDETACHcall site, soFREEZEstill acknowledged a non-durable snapshot. This PR is what remains:freezePartitionsByMatcherpopulatesfsync_part_directoryfrom the table setting, resolved once from the entry snapshot so a concurrentMODIFY SETTINGcannot split oneFREEZEacross parts.For packed storage,
FREEZErewrites thedata.packedarchive instead of hardlinking it, so the archive contents are fsynced too, for the part and for each projection.Gated on the existing
fsync_part_directorysetting (defaultfalse), so noSettingsChangesHistoryentry is needed. A no-op on remote/object disks, wheregetDirectorySyncGuardreturns nullptr.Verified via
ProfileEventsDirectorySyncandFileSyncon theFREEZEquery for both layouts, including the setting-off baselines. Regression test04621_freeze_fsync_part_directory.sh.Workflow [PR]
Sync PR [sync-upstream/pr/111393]