Skip to content

Cherry pick #122211 to 26.3: Undo a filesystem cache reservation when the key directory cannot be created - #123261

Merged
PedroTadim merged 6 commits into
backport/26.3/122211from
cherrypick/26.3/122211
Oct 2, 2026
Merged

PedroTadim merged 6 commits into
backport/26.3/122211from
cherrypick/26.3/122211

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #122211

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

CheSema and others added 5 commits September 25, 2026 13:01
…created

`FileCache::doTryReserve` created the key's directory last, after the
segment had already recorded the reservation - `setQueueIterator`,
`reserved_size += size`, and the size added to the main queue. When
`create_directories` failed (no space or no inodes left), it returned
false without undoing any of it. The segment was left `EMPTY` yet holding
a queue entry, which `FileSegment::complete` asserts against, and the main
queue kept counting the size. A later reservation of the same segment then
took the fast path that assumes an existing queue entry, skipped creating
the directory, and its write failed.

Create the directory after eviction, so a full cache disk can still admit
once space is reclaimed, and before the segment records the reservation.
On failure undo what the exception path above already undoes: invalidate a
freshly added queue entry, or give back the size added to an existing one.
The per-query queue is left as the exception path leaves it; its
accounting is being fixed in #114165.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The `create_directories` failure path undid the reservation with its own
copy of the exception path's rollback, without the `main_size_incremented`
guard - correct only because the flag is always set by the time that path
runs. Both paths now call one lambda, so they cannot drift apart. Also
trims the comments in the fix and its test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A failed `reserve` leaves the segment `PARTIALLY_DOWNLOADED_NO_CONTINUATION`,
so nothing reserves that segment again. The test now releases it, which
removes it, and caches the same offset in a new segment.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`FileSegmentsHolder` has its own `reset` method, so `holder.reset()` on the
`FileSegmentsHolderPtr` triggers `readability-ambiguous-smartptr-reset-call`.
Assign `nullptr` instead, as done elsewhere in the same file.

Build log: https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/PRs/77374/5a3ecfa4951c635875947dbdb572ebfcccf3d14f/pr/build_arm_tidy/build_clickhouse/build_clickhouse.log

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…-directory

Undo a filesystem cache reservation when the key directory cannot be created
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 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 Oct 1, 2026
- `FileCache.cpp`: the release branch lacks the `main_size_incremented` rollback that master's `rollback_main_entry` builds on, and its `createBaseDirectory` returns `bool` and throws for errors other than a full, read-only or inaccessible disk. The base directory is still created before the reservation is marked, and both a `false` return and an exception undo it: a new entry is invalidated, an existing one gives `size` back with `decrementSize`.
- `gtest_filecache.cpp`: a regular file at the key path makes `createBaseDirectory` throw here, so `ReserveUndoneWhenKeyDirectoryCannotBeCreated` expects the exception instead of a `false` return; the size checks and the later successful download are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim merged commit 7f5f667 into backport/26.3/122211 Oct 2, 2026
1 check passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/122211 branch October 2, 2026 11:06
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