Repository navigation
Reclaim objects left by a DROP interrupted on a plain_rewritable disk - #118465
alexey-milovidov wants to merge 61 commits into
Conversation
|
Workflow [PR], commit [1af106a] Summary: ❌
AI ReviewSummaryReviewed head Findings❌ Blockers
Missing context / blind spots
Tests
Final VerdictStatus: ❌ Block Close both key-containment gaps and add the focused regressions above. Two new inline findings were submitted together in one review; no existing threads were reopened or replied to. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes13 object files changed (+137.21 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units34 translation units recompiled, 239 s compile time in total, 33 of them have a recent master baseline. |
|
🕵 The single red check on Both failures are distributed-plan tests, in a subsystem this pull request does not touch (it changes
The harness re-ran both in isolation and each passed 3/3 ( This exact pair is tracked in #118626: failing fleet-wide since 2026-09-06 on Root cause and fixes are already in progress: a fail point armed with
I have not re-run the job: the leak comes from a neighbouring test in the same batch, so a re-run is a coin flip until #118863 lands, at which point merging |
|
📊 Cloud Performance Report 🟢 AI verdict: This PR only changes plain_rewritable disk metadata: blob-removal markers, locks on blobs shared between files, writing metadata in a single write, and cleanup when the disk loads. None of that runs in ClickBench or TPC-H SELECTs, so no flagged change can reasonably be traced to it. The 7-17% slowdowns in the GROUP BY queries (Q16, Q18, Q31-Q34) all fall inside master's normal range, and two clickbench runs shared a host. Q20's -41.4% stays an improvement because it meets the hard trust thresholds and CPU dropped with it, but nothing in the diff explains it; a baseline or build difference is more likely, so do not credit it to this PR. clickbench🟢 1 improved · Flagged queries (8 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…e-narrow-metadata-lock Pull in #118465: the leftovers of a committed removal live under reserved `__removed.` names with a marker object, so `load` never ingests them and the initial load reclaims them. This addresses the review finding that a failed post-commit cleanup could leave scratch objects that a later `SYSTEM DROP DISK METADATA CACHE` would load as metadata. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…etry the marker cleanup in `undo` On a read-only disk, a refresh or a `SYSTEM DROP DISK METADATA CACHE` reload no longer drops the subtree of a pending removal: nothing can be removing it in this process, so it keeps being shown under its original path, as on the initial load. Only a writable non-initial load skips it. `RemoveRecursiveOperation::undo` now removes the tombstone marker through `undoWithRetries`, like the other marker cleanups, so that a transient object storage error does not stop the rollback of the transaction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…LoadResult` Master added a fast path in `MetadataStorageFromPlainRewritableObjectStorage::load` that reuses the known `DirectoryRemoteInfo` of an unchanged directory without reading its `prefix.path`. This PR added the `is_orphaned` and `object_path` fields to `DirectoryLoadResult`, so the new initializer has to fill them. A directory found in the snapshot is never an orphaned removal: those are never put into the layout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-effort The deletion of objects left by unfinished removals runs after the layout is already installed. A failure there must not prevent the disk from loading: the leftovers stay hidden while their markers exist, and the markers are removed last, so the cleanup is retried on the next start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ames Names of the shape of `generateRemovedName` created by older versions are ordinary data, and `copyObject` overwrites the destination. Generate the temporary names of `UnlinkMetadataFileOperation`, `MoveFileOperation` (`replaceFile`) and `RemoveRecursiveOperation` until they are absent from the filesystem snapshot and distinct from each other. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e-drop-orphans Master added real hard links and the explicit file lists to `plain_rewritable`. Conflict resolution: - `RemoveRecursiveOperation`: the blobs to delete are collected in `execute` (as on master, keeping the blobs shared with files outside of the removed subtree), but the data objects and the `prefix.path` objects are kept apart and deleted in `finalize` in two passes before the tombstone marker, as in this PR. - `UnlinkMetadataFileOperation` and `MoveFileOperation`: the metadata-only paths of master need no temporary copies; the blob-copy paths use the reserved, marked temporary names. - `checkNotReservedPath` is kept for `createHardLink`, `moveFile`, `replaceFile`. - The reclamation on load deletes the blobs of an orphaned directory by their blob keys, and skips the blobs that are still referenced by a live directory with an explicit file list (hard links). The root files directory is listed for the leftovers of committed removals even when the root has an explicit file list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
|
…s of implicit directories The startup rollback of a pending `RemoveRecursive` rewrote only the logical path of the `prefix.path` object, dropping the explicit file list and the blob keys of a directory with hard links. Serialize the full contents with `serializePrefixPath`. The cleanup of orphaned blobs subtracted only the keys referenced by live explicit directories, but the source side of a hard link stays in an implicit directory under its default key. Subtract the keys of all live directories, including the root, whose files are listed only after the other directories. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kers if a directory is unreadable `LocalObjectStorage` writes to the final key directly, so a process that dies while writing a tombstone marker can leave it empty or truncated. Previously any content that did not start with `pending\n` was taken as a committed removal, and a truncated pending marker rolled the subtree back to a truncated path. Now both forms end with the removed name (committed: exactly the removed name; pending: `pending\n<path>\n<removed name>`), and any other content is malformed: nothing under that name is loaded, moved back, or deleted, and the marker stays. Also, a directory object without a logical path may be a directory of a pending removal whose `prefix.path` was being rewritten when the process died. It cannot be moved back, so in that case the pending markers are kept instead of being deleted after the rollback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/118465/802f6cede412a36d459a9cddb9f71312c9a14523/pr/ast_fuzzer_amd_release_oracle/job.log ( |
…not be read When reading the metadata object of a listed directory failed with `NO_SUCH_KEY`, Azure `NotFound`, or `ENOENT`, the directory was silently skipped, so it contributed no references to the reconciliation of the blob-removal markers. A transient `404` on a directory that still links a blob named by a marker would then delete the live blob permanently. Treat such a skipped read as an incomplete inventory, the same as an empty directory object: keep the pending markers and the blobs until a later load reads every directory. Add `UnreadableDirectoryKeepsBlobRemovalMarkers`, which injects `ENOENT` on the read of the directory that links the blob; it fails without the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 Merged The only red check on 026f4b0 is |
|
🕵 Merged The only red check on e4670fd is |
|
🕵 Merged The only red check on f0ebe7e was
The new push re-runs the sync. |
|
🕵 Merged |
|
🕵 Merged |
…is incomplete, validate keys of markers When a directory object could not be read on startup, its references are unknown. The blob-removal markers were already kept in that case, but the objects of committed recursive removals were still deleted: a blob shared with a file of the unreadable directory looked unreferenced and was deleted with the subtree and its marker. Now nothing is reclaimed on such a load; the leftovers stay hidden behind their markers and the next start retries. The key of a blob is taken from the content of a blob-removal marker and the blob is deleted, so an absolute key, `.`/`..` components, NULs, or a key under `__meta` could name an object outside of the blobs of the disk. Such markers are now `Malformed` and cause no deletion. The target of a pending replacement, which is overwritten from its backup, is checked the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oved blob referenced during rollback The keys of the blobs of a directory in the explicit form are read from its `prefix.path`, and the blobs of an orphaned subtree are deleted on load. Only the keys of blob-removal markers were checked with `isValidBlobKey`, so an absolute key (or one with `..`, or under `__meta`) in a damaged or forged file list could name an object outside of the disk. `parsePrefixPath` now rejects such keys with `INCORRECT_DATA`, which makes the load fail and deletes nothing. The metadata-only branch of `MoveFileOperation::undo` restored the target directory before the source one. After a cross-directory replacement only the target references the moved blob, so a process that died between the two rollback writes (or a rewrite of the source that failed for good) left the blob linked from nowhere, and no marker named it. The rewrites are now reversed in the reverse order of `execute`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…validKeyRemovesNothing` Co-Authored-By: Claude Opus 5.5 <[email protected]>
… disk The name of a file may contain a line feed, and then the key of its blob contains it too. A hard link writes this key to the explicit file list of the target directory (`prefix.path`), where it is escaped with `writeEscapedString`. `isValidBlobKey` rejected a line feed, so `parsePrefixPath` threw `INCORRECT_DATA` for such a file list on the next load, and the disk could not be loaded. `isValidBlobKey` no longer rejects a line feed: it only keeps the containment checks. The marker of a blob removal now escapes the key the same way as the file list instead of refusing a key with a line feed, so the last link to such a blob in an explicit directory can be removed. The content of the marker still ends with a line feed that is not escaped, so a torn content is never taken for a complete one. The new unit test `HardLinkOfFileWithLineFeedInName` covers the round trip of the marker, the reload of the metadata, and the removal of the last link. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: No performance change can be attributed to this PR. It only changes how plain_rewritable object-storage disks write and recover their metadata: blob-removal markers, locks on shared blobs, atomic metadata writes and cleanup at startup. The only flagged row, clickbench Q10 (+20.7%, 111 ms vs 92 ms), was held at not_sure automatically because it falls inside master's recent 83–115 ms range and this query is noisy on master. That call is consistent with the diff: Q10 is a read-only COUNT(DISTINCT) aggregation that never runs the changed metadata transaction or startup-loading code, so there is no reason to contest it. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…cement `makePendingReplaceTombstoneContent` rejected a target whose name contains a line feed, because a line feed separates the fields of the marker. So an existing file with such a name, which is a valid name on a `plain_rewritable` disk, could not be replaced by `replaceFile`. Such a name is now written escaped (like in the file list of `prefix.path`) under a separate prefix, `PENDING_REPLACE_ESCAPED_TOMBSTONE_PREFIX`, and parsed symmetrically. The content for a name without a line feed is not changed, so the markers stay readable by the versions that know only `PENDING_REPLACE_TOMBSTONE_PREFIX`, and an old marker with a backslash in the name is not misread as an escaped one. The new unit test `ReplaceOfFileWithLineFeedInName` covers the round trip of the content, torn contents, a replacement that fails and is undone, a rollback of an interrupted replacement on the next load, and a successful replacement. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged The only CI failure on d5acb7c, |
| return out.str(); | ||
| } | ||
|
|
||
| bool PlainRewritableLayout::isValidBlobKey(std::string_view blob_key) |
There was a problem hiding this comment.
[Blocker] Reject qualified object paths before accepting a blob key
isValidBlobKey accepts s3://other-bucket/victim.bin: it is relative to std::filesystem, contains no NUL or traversal component, and does not start with __meta. An empty common key prefix is supported by getS3URI; in that configuration constructBlobObjectKey preserves this string. S3ObjectStorage::groupByBucket then calls splitBucketAndKey, which interprets it as bucket other-bucket, key victim.bin.
Consequently, a supplied blob-removal marker, or an explicit file list of a committed recursive removal, can make startup delete an object in another bucket using the disk's credentials. A standalone probe using this validator and the repository's trySplitFullyQualifiedObjectPath confirmed the accepted key and cross-bucket routing; this was not a full server reproduction.
Please reject qualified paths as well as filesystem traversal, and add a recovery regression with an empty disk prefix and a sentinel in another bucket. Check the namespace interpretation used by the S3 consumer, not only filesystem relativity.
| /// The blobs of a directory are deleted with it (also by the reclamation on the initial load), so a key that | ||
| /// would name an object outside of the blobs of this disk (in another prefix, or in `__meta`) is never taken | ||
| /// from a damaged or forged file list. | ||
| if (!PlainRewritableLayout::isValidBlobKey(file.blob_key)) |
There was a problem hiding this comment.
[Blocker] Apply blob-key containment to snapshot-loaded entries too
This check protects prefix.path, but the existing snapshot.bin load path bypasses it. readPlainRewritableSnapshot reads FileRemoteInfo::blob_key without validation (Metadata/PlainRewritableSnapshotFile.cpp:190), and a read-only disk applies that layout directly (MetadataStorageFromPlainRewritableObjectStorage.cpp:1279). A well-formed snapshot can therefore give a file the key /other-prefix/victim.bin; getStorageObjectsIfExist passes it to constructBlobObjectKey, whose filesystem join discards the configured prefix, and S3ObjectStorage::readObject reads that key without a containment check. The same gap exists for a default key derived from a snapshot-supplied DirectoryRemoteInfo::remote_path.
Thus the relative-key invariant being enforced here still does not hold across the persisted representations, and supplied snapshot metadata can redirect reads outside the disk's namespace. This alternate path is pre-existing, but remains uncovered by the containment fix.
Please validate the effective key from getBlobKey for snapshot entries as well, or enforce containment centrally before constructing an object key. Add a read-only snapshot regression with an outside-prefix sentinel and cover both explicit and default blob keys.
Closes: #114051
Related: #111804
Related: #118490
On a
plain_rewritabledisk, operations commit a change in the metadata first and delete the objects infinalize. If the server is killed in between, the objects must not stay in the bucket forever. The main part of the fix is already onmaster. It came in through #118490, which was based on an earlier version of this branch: reserved removed names, tombstone markers, rollback of pending removals and replacements, and reclamation on the initial load.This PR adds the remaining pieces on top of
master:unlinkFile, the metadata-onlymoveFile/replaceFile, and a rewrite of a file to a new blob) drop the last link to a blob by rewritingprefix.path, and delete the blob only infinalize. Nothing under the prefix of an explicit directory is listed on load, so a kill in between leaked the blob forever. Such an operation now writes a marker with the key of the blob first (PlainRewritableLayout::BLOB_REMOVAL_TOMBSTONE_PREFIX).finalizedeletes the marker after the blob, andundodeletes it after restoringprefix.path. On the writable initial load, the blob is deleted if no live directory links it anymore and kept otherwise. Then the marker is deleted.prefix.pathwas being rewritten), or the metadata object of the root is empty (an interrupted rewrite of the root's explicit file list), the markers of pending removals and blob removals are kept instead of being deleted.copyObjectwould overwrite an existing look-alike name created by an older version.RemoveRecursiveOperation::undoremoves its marker throughundoWithRetries.PlainRewritableLayout::PENDING_REPLACE_ESCAPED_TOMBSTONE_PREFIX), so an existing file with such a name can be replaced byreplaceFile. The content of the marker for any other name is not changed.KeyLocks). This way the transaction that removes the last link sees it in its own snapshot and removes the blob through the marker, instead of the blob losing its last link only when the changes are published. A path that an earlier operation of the same transaction moved a file or directory to is resolved back through the moves, so a removal after a move takes the same locks.A new case is added to
test_s3_plain_rewritable_crash_recovery:test_unlinked_blob_of_explicit_directory_is_reclaimed.The serialization by
KeyLocksis covered by the new unit testsConcurrentUnlinkOfDifferentLinksToSharedBlobandParallelUnlinkOfDifferentLinksToSharedBlob(also with a move followed by an unlink).BlobRemovalMarkersOfInterruptedCleanupruns a real unlink, replacement, and rewrite in an explicit directory with failing deletions infinalize, and checks that the markers name the old blobs and that the next load reclaims them.EmptyRootMetadataKeepsBlobRemovalMarkerscovers the empty root metadata object.ReplaceOfFileWithLineFeedInNamecovers the replacement of a file with a line feed in its name, including the rollback of an interrupted replacement on the next load.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a permanent leak of objects in object storage on
plain_rewritabledisks (such ass3_plain_rewritable) when the server is killed after removing or replacing a file in a directory with an explicit file list (hard links) but before the blob is deleted. Such blobs are now deleted when the server loads the disk metadata on the next start.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/118465]