Skip to content

Cherry pick #132449 to 26.10: Fix INSERT into a Set or Join table on a plain_rewritable disk - #133610

Merged
robot-clickhouse-ci-2 merged 6 commits into
backport/26.10/132449from
cherrypick/26.10/132449
Nov 25, 2026
Merged

robot-clickhouse-ci-2 merged 6 commits into
backport/26.10/132449from
cherrypick/26.10/132449

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #132449

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 5 commits November 17, 2026 16:48
…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 (#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]>
Review: #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]>
…to-virtual-dir

Fix `INSERT` into a `Set` or `Join` table on a `plain_rewritable` disk
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 22, 2026
Resolve the conflict in gtest_metadata_plain_rewritable_disk.cpp: keep the
26.10 side of the `ErrorCodes` declarations and add only
`DIRECTORY_ALREADY_EXISTS`. The conflicting master line, `INCORRECT_DATA`,
comes from #121431, which is not on 26.10 and is not needed by these tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

The only conflict is one line in src/Disks/tests/gtest_metadata_plain_rewritable_disk.cpp: on master, the ErrorCodes block next to the new DIRECTORY_ALREADY_EXISTS also declares INCORRECT_DATA, which comes from #121431. That PR is not on 26.10 and has no v26.10-must-backport label, so this cherry-pick will not resolve itself. I kept the 26.10 side and added only DIRECTORY_ALREADY_EXISTS. The source files merge without conflicts. Against backport/26.10/132449, the merge adds exactly the 141 lines of #132449 in its 5 files, identical to master, and removes nothing.

The bug is present on 26.10: with the official 26.10.11.7 build, the first INSERT into a Set table on a plain_rewritable disk fails with Directory '...' is virtual (LOGICAL_ERROR). A Debug build of the resolved tree with clang-22 passes 05816_set_join_on_plain_rewritable_disk and all 88 MetadataPlainRewritableDiskTest gtests. With the two source hunks reverted, 05816 and both new gtests fail.

I cannot push to cherrypick/26.10/132449. The merge is on my fork, and its first parent is this PR's head 6e49d66a9747, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.10-cherrypick-132449
git push origin FETCH_HEAD:cherrypick/26.10/132449

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Applied the resolution from the comment above: cherrypick/26.10/132449 is fast-forwarded to dcfb6e0d4c14 (parents: the previous head 6e49d66a9747 and backport/26.10/132449 at aabf8c7eb396).

I checked it independently: the diff against backport/26.10/132449 is the same 5 files and 141 added lines as #132449, and the patch differs from the original only in context (INCORRECT_DATA is not declared in the ErrorCodes block of gtest_metadata_plain_rewritable_disk.cpp on 26.10). A -fsyntax-only compile of gtest_metadata_plain_rewritable_disk.cpp on the resolved tree passes, and MetadataStorageFromPlainRewritableObjectStorage.cpp shows no errors in the changed code.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 5a41fc3 into backport/26.10/132449 Nov 25, 2026
2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.10/132449 branch November 25, 2026 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants