Repository navigation
Fix INSERT into a Set or Join table on a plain_rewritable disk - #132449
alexey-milovidov merged 4 commits into
Conversation
…rectory A new `Set` or `Join` table on a `plain_rewritable` disk creates `<path>/tmp` with `createDirectories`, which records only the leaf, so `<path>` exists only as a virtual node. The first INSERT then `replaceFile`s `tmp/<n>.bin` into it and the commit throws `LOGICAL_ERROR: Directory '...' is virtual`. The stateless test covers the Set/Join INSERT. The gtests cover a move and a hard link (also with hard links disabled) into a virtual directory, a concurrent removal of the virtual target, and a concurrent replacement of it by a directory in the explicit form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… or linked into it On a `plain_rewritable` disk `createDirectoryRecursive` writes a `prefix.path` only for the leaf, so its ancestors exist only as virtual nodes. Writing a file into such a directory already materializes it (ClickHouse#91935, in `generateObjectKeyForPath`), but `moveFile`/`replaceFile` and `createHardLink` did not, and their commit threw `LOGICAL_ERROR: Directory '...' is virtual`. That is hit by the first INSERT into every `Set`/`Join` table on such a disk (`StorageSetOrJoinBase::restore` creates `<path>/tmp`, and the INSERT then `replaceFile`s `tmp/<n>.bin` into `<path>`), by a `Join` mutation, and by `clickhouse-disks move`/`link`. The new `materializeVirtualDirectory` is called for the target directory of a move and of a hard link. It plans a `CreateDirectoryOperation` for it in a new materialize-only mode and records the directory in the uncommitted state, so the move or link plans against a real, empty, implicit directory. Like the write path, it registers `useMissingDirectory`, so a commit fails with `DIRECTORY_ALREADY_EXISTS` when another transaction materialized or replaced the directory in between (the move, the real hard link and the hard-links-disabled copy were all planned for the implicit form). The materialize-only operation throws `DIRECTORY_DOESNT_EXIST` when the directory was removed in between, instead of recreating it. A target directory that does not exist at all still fails as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the sentence in materializeVirtualDirectory that narrated the new code's useMissingDirectory precondition (it is in the fix commit message). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review of the diff (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20261117-182800 |
|
cc @Michicosun, could you review this? On plain_rewritable, moveFile/replaceFile and createHardLink now materialize a target directory that exists only as a virtual parent, like writes already do, so the first INSERT into a Set or Join table on such a disk no longer hits the 'Directory is virtual' logical error. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261117-164501 |
|
Workflow [PR], commit [3a04983] Summary: ✅
AI ReviewSummaryPR #132449 fixes moves and hard links into virtual directories on Final Verdict✅ Approve |
Michicosun
left a comment
There was a problem hiding this comment.
look how materialization works for create file and do the same, do not change all operations with additional flag just to support corner case
Review: ClickHouse#132449 (review) The target directory of a move or a hard link is now materialized exactly as `generateObjectKeyForPath` materializes the parent of a new file: `useMissingDirectory` plus `createDirectoryRecursive`. The `materialize_only` mode of `CreateDirectoryOperation` is removed, so the operations are the same as on master. As for a write, a target directory removed by a concurrent transaction after the move was planned is recreated by the move instead of failing it. The `ConcurrentRemoveOfVirtualMoveTarget` test, which pinned the removed mode, is dropped. A move into a directory that does not exist at all still fails as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline. |
|
Thanks, done in 3a04983: the One consequence, the same as for a write: if a concurrent transaction removes the virtual target after the move was planned, the move recreates the directory instead of failing (checked in a gtest, the moved file is intact after a restart). I dropped the gtest that pinned the old behavior and updated the description. |
AI review of a later commit does not approve the PR, see the AI Review comment.
|
Thanks @Michicosun I was going to ask your help |
Backport #132449 to 26.11: Fix `INSERT` into a `Set` or `Join` table on a `plain_rewritable` disk
Cherry pick #132449 to 26.10: Fix `INSERT` into a `Set` or `Join` table on a `plain_rewritable` disk
Related: #131994
Related: #91935
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
LOGICAL_ERRORDirectory '...' is virtualon the firstINSERTinto aSetorJointable whosedisksetting names aplain_rewritabledisk, onALTER TABLE ... DELETEof such aJointable, and onclickhouse-disks moveorlinkinto a directory thatmkdir --parentscreated only as a parent.Description
On 26.10 (also 26.8 and 26.3, checked on 26.10.4.207, 26.8.37.168 and 26.3.63.123),
INSERT INTOaSetorJointable withSETTINGS disk = '<plain_rewritable disk>'fails withLOGICAL_ERROR: Directory 'store/...' is virtual, which aborts debug and sanitizer builds. Found by La Casa Del Dolor: report.On
plain_rewritable,createDirectoryRecursivewrites aprefix.pathonly for the leaf, so the ancestors exist only as virtual directories.StorageSetOrJoinBase::restorecreates<path>/tmp, which leaves the table directory virtual, and theINSERTthen movestmp/<n>.bininto it. Writing a file into a virtual directory already materializes it (#91935); moving or hard-linking a file into one did not.moveFile/replaceFileandcreateHardLinknow materialize a virtual target directory the same waygenerateObjectKeyForPathdoes for a new file (useMissingDirectory+createDirectoryRecursive), with the semantics of a write: if another transaction materializes or replaces the directory before the commit, the commit fails withDIRECTORY_ALREADY_EXISTS; if it removes the directory, the commit recreates it. Of two concurrent firstINSERTs into a fresh table one succeeds and the other can fail withDIRECTORY_ALREADY_EXISTS(retryable); today both fail withLOGICAL_ERROR.Validation: the new stateless test (
SetandJoin, read back afterDETACH/ATTACH) aborts the server on master and passes with the fix (30/30 randomized runs). Two gtests cover a move and a hard link with hard links on and off, and a concurrent replacement of the target; removing theuseMissingDirectoryguard makes the latter fail.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132449]
Version info
26.12.1.200-master(included in26.12and later)26.11.1.2926