Repository navigation
Conversation
MergeTreeData::dropDetached renamed detached/<part> to detached/deleting_<part> and unlinked it without ever fsync'ing the detached directory, and consulted no durability setting. A rename or unlink is durable only once the parent directory is fsync'd, so a power loss in the filesystem journal window could roll the directory-entry changes back and the acknowledged-dropped detached part reappeared. Gate the fsync on the existing fsync_part_directory setting (default false, no behavior change by default): acquire one directory sync guard per involved disk on the detached directory before the rename and hold it across the rename and removal. The guards are declared before PartsTemporaryRename so they outlive it and also cover the rollback rename on the error path. Uses the disk-agnostic IDisk::getDirectorySyncGuard (local disks fsync, object storage no-op). Closes: ClickHouse#111349 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-1:20260722-110200 |
Internal second-model review (adjudicated) - click to expandAn independent second model reviewed this change before it was opened. All findings and dispositions below; nothing is a blocker. Blockers: none. Majors:
Nits:
|
|
cc @Michicosun - could you review this? It makes |
|
Workflow [PR], commit [b57431f] Summary: ❌
AI ReviewSummaryThis PR makes Findings❌ Blockers
Final VerdictChanges requested: the fix is correct for |
| { | ||
| if (!synced_disks.emplace(rename_info.disk->getName()).second) | ||
| continue; | ||
| if (auto guard = rename_info.disk->getDirectorySyncGuard(fs::path(relative_data_path) / DETACHED_DIR_NAME)) |
There was a problem hiding this comment.
DiskLocal and DiskEncrypted are fixed here, but this still does nothing for supported object-storage tables with local metadata. DiskObjectStorage does not override IDisk::getDirectorySyncGuard, so this line gets the default nullptr; meanwhile MergeTreeData::checkAlterPartitionCanBeExecuted still allows DROP_DETACHED_PARTITION on MetadataStorageType::Local disks, and their metadata rename/remove path still goes through MetadataStorageFromDiskTransaction::commit() to plain moveDirectory / removeRecursive calls on the local metadata disk with no sync. That leaves the same post-ack power-loss resurrection window open for this supported carrier of the feature.
Could we delegate DiskObjectStorage::getDirectorySyncGuard to the underlying metadata disk when the metadata storage is MetadataStorageType::Local, or otherwise scope/reject that layout explicitly?
There was a problem hiding this comment.
Confirmed and correct on all three points: DiskObjectStorage does not override getDirectorySyncGuard (default IDisk returns nullptr), checkAlterPartitionIsPossible allows DROP_DETACHED_PARTITION on MetadataStorageType::Local, and the metadata moveDirectory/removeRecursive in MetadataStorageFromDiskTransactionOperations are unsynced. So the object-storage-with-local-metadata layout keeps the window open.
Keeping this PR scoped to local disks (DiskLocal/DiskEncrypted), where the #111349 repro lives and the fix is proven, for two reasons:
getDirectorySyncGuardis a sharedIDiskprimitive with 23 call sites (partrenameTo,MergeTreeDataWriter,DistributedAsyncInsert*,VersionMetadataOnDisk,DeleteBitmapFileOps, ...). DelegatingDiskObjectStorage::getDirectorySyncGuardto the metadata disk changes durability/perf for all of them, which is a broad change on its own.- The directory guard alone would not close the object-storage window anyway: the metadata file operations (
WriteFileOperationand friends) are also unsynced, so the complete object-storage fix is the multi-leg metadata-durability change (file sync + dir sync), not a one-liner here.
Rejecting the layout is not an option since it removes currently-working functionality. The limitation is documented (the no-object-storage tag on the test and the no-op note in the description). Tracking the object-storage local-metadata durability gap as separate follow-up work alongside the rest of the metadata-durability effort.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
CI finish ledger — b57431fEvery failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260722-183000 |
|
Fixing PRs for the That row is emitted by the stress harness itself (
Fixed by, all merged:
The object-storage variant of the same family is pinned by #111922 (open). Verification: all three merge commits are ancestors of master, and the signature stops dead in CIDB. Boot failures caused by Nothing about this failure was related to this PR. |
|
Fixing PR for the The failure is the plain-rewritable |
Closes: #111349
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ALTER TABLE ... DROP DETACHED PART/PARTITIONnow fsyncs thedetacheddirectory when thefsync_part_directoryMergeTree setting is enabled, so an acknowledged drop of a detached part is no longer rolled back by a power loss (the removed part could previously reappear).Description
MergeTreeData::dropDetachedrenamesdetached/<part>todetached/deleting_<part>and then unlinks it, but never fsync'd thedetacheddirectory and consulted no durability setting. A rename or unlink is durable only once the parent directory is fsync'd, so after a power loss in the filesystem journal window the directory-entry changes could roll back and the acknowledged-dropped detached part reappeared intact. Reported and reproduced 3/3 with adm-flakeypower-loss simulation in #111349.Fix, gated on the existing
fsync_part_directorysetting (defaultfalse, so no behavior change by default): before the rename, acquire one directory sync guard per involved disk on thedetacheddirectory and hold it across the rename and the removal; the guard fsyncs the directory on destruction. The guards are declared beforePartsTemporaryRenameso they outlive it and also cover the rollback rename on the error path. This uses the disk-agnosticIDisk::getDirectorySyncGuard(local disks fsync; object storage is a no-op), matching the existingfsync_part_directoryhandling for part directories inIMergeTreeDataPart::renameTo.Test:
04620_drop_detached_part_fsyncasserts theDirectorySyncProfileEvent is emitted forDROP DETACHED PARTwhenfsync_part_directory = 1and not when0, and that the part is removed in both cases.