Skip to content

Fix a mutated part losing files to the temporary directory cleanup - #111992

Merged
alexey-milovidov merged 14 commits into
masterfrom
fix-mutation-temp-dir-cleanup-race
Aug 13, 2026
Merged

alexey-milovidov merged 14 commits into
masterfrom
fix-mutation-temp-dir-cleanup-race

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Related: #107150
Related: #96376

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a race between a ReplicatedMergeTree mutation and the removal of old temporary directories that could publish a mutated part with some of its files missing, making reads of that part and all its later mutations fail.

Description

MutateFromLogEntryTask::finalize released mutate_task - and with it the RAII guard that registers tmp_mut_<part> in MergeTreeData::TemporaryParts - before calling MergeTreeData::Transaction::renameParts, which is what actually renames the directory on disk. Between those two points the temporary directory of an already precommitted part was not protected from clearOldTemporaryDirectories.

When the cleanup thread hit that window it started removing the directory while renameParts was moving it to the persistent name, so the part became active with part of its files already deleted while checksums.txt still listed all of them. From the failing job's node1 log, the three events are 850 µs apart:

19:34:46.048315  Renaming temporary part tmp_mut_97_0_0_0_7 to 97_0_0_0_7
19:34:46.049102  Removing temporary directory .../tmp_mut_97_0_0_0_7/     <- cleanup thread
19:34:46.049168  Renaming part to 97_0_0_0_7                              <- the actual rename

Reads of such a part fail, because MergeTreeMarksLoader derives the marks path from the part's own checksums and therefore expects the file to exist:

Code: 1001. DB::Exception: std::filesystem::filesystem_error: filesystem error:
in file_size: No such file or directory [".../97_0_0_0_7/foo2.cmrk2"]

and every following mutation of the part fails permanently, because it hardlinks the source part's files by the names listed in its checksums:

Code: 424. DB::ErrnoException: Cannot link .../97_0_0_0_7/foo2.bin to
.../tmp_mut_97_0_0_0_8/num2.bin ... (CANNOT_LINK)

This is the flaky test_rename_column/test.py::test_rename_distributed_parallel_insert_and_select. That test sets temporary_directories_lifetime = 1, which makes the window easy to hit; it has failed this way 12 times in the last two months, including twice on master. #107150 reported the same symptom from the reader's side and improved the error message without fixing the race.

Now the part is renamed while mutate_task is still alive, the way MergeTreeDataMergerMutator::renameMergedTemporaryPart already does for merges ("Explicitly rename part while still holding the lock for tmp folder to avoid cleanup"). mutate_task is still reset before checkPartChecksumsAndCommit, so the fallback fetch on a checksum mismatch (#96376) still runs with the guards released.

Every other caller of renameTempPartAndReplace with rename_in_transaction=true renames immediately afterwards; MutateFromLogEntryTask was the only one that did not.

Testing

04512_mutation_temp_dir_cleanup_race pauses a mutation right before the rename with a new pauseable failpoint and checks that the cleanup thread reports the directory as in use instead of removing it. It fails on the unfixed code (0 1 - the directory is removed, and the mutation then dies with Cannot set modification time to file) and passes with the fix (1 0), verified locally on a debug build in both directions.

Reported by: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=423ec1ba3ac4288ce5b934235be0c6700e0f7c14&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%201%2F8%29

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.1360 (included in 26.8 and later)
  • Backported to: 26.7.11.11, 26.6.9.11, 26.3.33.99

`MutateFromLogEntryTask::finalize` released `mutate_task` - and with it the RAII
guard that registers `tmp_mut_<part>` in `MergeTreeData::TemporaryParts` - before
calling `MergeTreeData::Transaction::renameParts`, which is what actually renames
the directory on disk. Between those two points the temporary directory of a part
that is already precommitted was not protected from `clearOldTemporaryDirectories`.

When the cleanup thread hit that window it started removing the directory while
`renameParts` was moving it to the persistent name, so the part became active with
part of its files already deleted while `checksums.txt` still listed all of them:

    19:34:46.048315  Renaming temporary part tmp_mut_97_0_0_0_7 to 97_0_0_0_7
    19:34:46.049102  Removing temporary directory .../tmp_mut_97_0_0_0_7/
    19:34:46.049168  Renaming part to 97_0_0_0_7

Reads of such a part fail with

    Code: 1001. DB::Exception: std::filesystem::filesystem_error: filesystem error:
    in file_size: No such file or directory [".../97_0_0_0_7/foo2.cmrk2"]

because `MergeTreeMarksLoader` derives the marks path from the part's checksums,
and every following mutation of the part fails permanently with

    Code: 424. DB::ErrnoException: Cannot link .../97_0_0_0_7/foo2.bin to
    .../tmp_mut_97_0_0_0_8/num2.bin ... (CANNOT_LINK)

Rename the part while `mutate_task` is still alive, the way
`MergeTreeDataMergerMutator::renameMergedTemporaryPart` already does for merges
("Explicitly rename part while still holding the lock for tmp folder to avoid
cleanup"). The reset of `mutate_task` stays where it was relative to
`checkPartChecksumsAndCommit`, so the fallback fetch on a checksum mismatch still
runs without the guards being held.

The window was introduced by #96376, which moved the reset in front of
`renameParts`. Every other caller of `renameTempPartAndReplace` with
`rename_in_transaction=true` renames immediately afterwards.

The new stateless test pauses a mutation right before the rename with a failpoint
and checks that the cleanup thread reports the directory as in use instead of
removing it.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=423ec1ba3ac4288ce5b934235be0c6700e0f7c14&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%201%2F8%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ir-cleanup-race

# Conflicts:
#	src/Common/FailPoint.cpp
#	src/Storages/MergeTree/MutateFromLogEntryTask.cpp
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2b09dc7]

Summary: ✅


AI Review

Summary

This PR moves MutateFromLogEntryTask::finalize to rename the precommitted mutated part on disk before releasing the TemporaryParts guard, closing the window where clearOldTemporaryDirectories could delete files from a part that was about to become active. The current head also includes a focused stateless regression test with failpoint synchronization for both the pre-rename and post-guard-release windows. I did not find remaining correctness, rollback, or coverage issues in the touched paths.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 19/19 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 27, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the only red on commit 9cde0cd7aaa was Integration tests (arm_binary, distributed plan, 3/4) → test_storage_nats/test_nats_jet_stream.py::test_nats_restore_failed_connection_without_losses_on_write (report). It is unrelated to this PR, which only touches MutateFromLogEntryTask::finalize and a failpoint. The fix is already in progress in #112828, which names this exact test as the flaky manifestation of the JetStream re-subscribe bug. Master has been merged here so CI re-runs on a current base.

The AI review pointed out that the test only observed the temporary
directory while the mutation task, and with it the `TemporaryParts`
guard, was still alive: the `rmt_mutate_task_pause_before_rename_part`
failpoint fires before both `transaction_ptr->renameParts()` and
`mutate_task.reset()`, so the assertion held for the old ordering as
well and the test could not detect a reintroduced race.

Add a second pauseable failpoint,
`rmt_mutate_task_pause_after_temporary_part_released`, right after
`mutate_task.reset()` — exactly the window the fix is about. With the
fix, the temporary directory has already been renamed under the guard
and there is nothing left to remove; with the old ordering it is still
on disk and no longer registered in `TemporaryParts`, so the cleanup
thread deletes it.

The test now synchronizes on the failpoints with
`SYSTEM WAIT FAILPOINT ... PAUSE` instead of polling for the first
cleanup log line, and waits for a counted number of finished cleanup
iterations (`Scheduling next cleanup` in `system.text_log`) before
sampling the decision, so both phases observe at least one full pass of
`clearOldTemporaryDirectories`.

Verified locally on a `ReplicatedMergeTree` server: the test passes
three times in a row with the fix, and fails deterministically
(`removed_after_release` becomes `1`) when `renameParts` is moved back
below `mutate_task.reset()`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the only red on commit 07aae64a was Stress test (amd_msan) → Logical error: Unexpected return type from A. Expected B. Got C. (STID: 1611-4523) (report). It is unrelated to this PR, which only touches MutateFromLogEntryTask::finalize and two failpoints, and it is the known fuzzer class tracked in #112315. Could you investigate and provide a fix in a separate PR — or link the fix here if one is already in progress? Master has been merged here so CI re-runs on a current base.

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

A fix is already in progress: #110338. It is the same defect, so no separate PR is needed.

One correction: this is not the #112315 class. Both share the error message, but the throw
sites differ. STID 1611-4523 (all 14 CIDB rows in 45 days) aborts in
MergeTreeIndexSet.cpp:485 -> MergeTreeIndexConditionSet::getPossibleGranules; STID
3262-472c aborts in ActionsDAG.cpp:1291/:967 -> executeActionForPartialResult. Two
defects pooled under one message.

The carrier here is 01786_explain_merge_tree.sh, whose table declares
index t_set t % 19 type set(4) granularity 2. MergeTreeIndexConditionSet rebuilds the
WHERE predicate onto the granule block, reusing the predicate's pre-resolved function nodes;
when the fuzzer mutates t % 19 = 16 into a Nullable-resolved form, equals is resolved at
Nullable(UInt8) while the granule column stays plain UInt8, so the result type invariant
trips. That matches the report's action line exactly:

FUNCTION equals(modulo(t, 19) :: 0, 16 :: 1) -> equals(modulo(t, 19), 16) Nullable(UInt8) : 7,
input block structure:modulo(t, 19) UInt8 UInt8(size = 5), 16 UInt8 Const(size = 5, UInt8(size = 1))

Deterministic on current master (90042b2):

SET enable_analyzer = 1;
CREATE TABLE t_1611 (t UInt32, INDEX t_set t % 19 TYPE set(4) GRANULARITY 2)
  ENGINE = MergeTree ORDER BY tuple()
  SETTINGS index_granularity = 2, min_bytes_for_wide_part = 0;
INSERT INTO t_1611 SELECT number FROM numbers(20);
SELECT count() FROM t_1611 WHERE (t % toNullable(19)) = 16 SETTINGS use_skip_indexes_on_data_read = 1;

Master aborts; with #110338 applied on top of the same commit it returns 1. I also checked
(t % 19) = toNullable(16) and the mixed-type ((t % 19) = 1) OR ((t % toNullable(19)) = 2)
form, both fixed.

Agreed it is unrelated to this PR: 11 distinct PRs plus one master hit (2026-07-10,
Stress test (amd_tsan)) carry it, and none of them touch the skip-index code.

#110338 has been open since 2026-07-14 and is unreviewed. Its CI is currently stuck on a
Config Workflow failure with 172 of 174 checks skipped, so I will get a clean run on it.

@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.50% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.80% 78.80% +0.00%

Changed lines: Changed C/C++ lines covered: 19/19 (100.00%) · Uncovered code

Full report · Diff report

Both `rmt_mutate_task_pause_before_rename_part` and
`rmt_mutate_task_pause_after_temporary_part_released` are server-global and pause
every `ReplicatedMergeTree` mutation. Under `set -e` a timed-out
`SYSTEM WAIT FAILPOINT ... PAUSE` or a failing `wait_for_cleanup_iterations` exited the
script before the explicit `SYSTEM DISABLE FAILPOINT` calls, leaving the failpoints armed
for the rest of the stateless run. Disable them unconditionally from an `EXIT` trap;
disabling a pauseable failpoint also resumes the threads paused at it.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the only red on 56d94aae was Performance Comparison (arm_release, master_head, 1/6, 4/6, 5/6), and every failing query there fails in both the old and the new run (dotProduct, group_by_multiple_strings, hash_table_sizes_stats, map_bucketed_serialization, polymorphic_parts_m, polymorphic_parts_s, set) — 14 unstable queries, 0 slower, so this is perf-harness noise unrelated to this PR (which only changes MutateFromLogEntryTask::finalize ordering, a failpoint, and one stateless test). Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111992&sha=latest&name_0=PR — if the arm perf shards are systematically unstable, a separate PR would be welcome.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Measured it, and "the arm shards are systematically unstable" does not hold. Base rate over 30d of master_head runs (pull_request_number = 0, default.checks): arm 12,300 unstable rows / 3,760,248 = 0.327%, amd 14,066 / 3,716,634 = 0.378%. Per shard, arm spans 0.197%-0.452% and amd 0.243%-0.539%, so no shard is an outlier against its siblings, and arm is not worse than amd on either axis. Weekly for 8 weeks both sit in 0.29%-0.53% with no trend. Mean stat_threshold is actually lower on arm (0.0238 on m8g.4xlarge) than amd (0.0357 on m7i.4xlarge), i.e. arm resolves differences slightly better.

Two things do explain why it looks arm-specific from a PR:

  1. Only arm runs on a normal PR. filter_job.py:402 skips the amd perf shards unless the PR is labeled pr-performance, so arm is the only arch you ever see fail. Over 30d arm perf ran on 1,903 PRs against amd's 209. Same noise, six times the exposure.

  2. Those shards were not red. All six were success in CIDB and OK in the report; shard 1/6's own message is 3 too long, 1 faster, 11 unstable. What you saw is a real reporting defect, not a failure: performance_tests.py:1901 turns every slower/unstable per-query row into a sub-Result with status=FAIL, purely to attach a query-history link. The parent Check Results keeps its own computed status (:1919), so the job stays green while its children render red. The 14/28 discrepancy is the same layer: compare.sh:1908 emits one row per side (::old, ::new), so 14 rows on 56d94aae are 7 distinct queries (11+2+1 = 14 queries -> 28 rows across shards 1, 4, 5).

So the query-level instability is real but arch-neutral, and it is concentrated, not systemic: 261 distinct tests produce arm PR unstable rows over 14d, and the top 10 account for 67.4%, the top 20 for 82.6%. The worst are insert_sequential_and_background_merges (37.2% of its rows), polymorphic_parts_s (25.7%), polymorphic_parts_m (22.0%), number_formatting_formats and file_table_function (~10%). Comparing the same tests across arches on master shows the skew cuts both ways: polymorphic_parts_m is 12.8% arm vs 3.7% amd, removing_group_by_keys 6.4% vs 0.1%, but index_bulk_filtering is 12.5% amd vs 3.5% arm, polymorphic_parts_l 15.5% vs 1.8%, timeseries_to_grid_aggregation_functions 12.0% vs 2.7%. That is per-query variance, not per-arch.

I also tested the one arch-specific mechanism I could find and it does not survive: GET_HISTORICAL_TRESHOLDS_QUERY (performance_tests.py:47) learns the per-query thresholds with no arch filter, pooling arm and amd even though query_metrics_v2 carries the column. On the concentrated offenders pooling does under-size arm (file_table_function #2: pooled 3.95 vs arm-only 7.76). But applying the CI rule with per-arch thresholds over the last week of arm PR rows flags more, not fewer: 10,750 vs 10,254, because the pooled q99 is on average wider than arm's own (0.21 vs 0.175). Splitting by arch would make the reporting noisier, so I am not proposing it.

Conclusion: no PR to widen thresholds, since the data does not support one and widening would reduce coverage. The two defects worth fixing are the reporting one above (green job rendering red children, and double-counted rows) and right-sizing the handful of concentrated offenders so the harness can resolve a difference, per the usual approach of increasing work per iteration rather than weakening the assertion. Say the word and I will send a PR for the reporting defect first, since that is what actually cost you the triage time here.

alexey-milovidov and others added 3 commits August 4, 2026 12:53
Capture a `start_time` before creating the table and filter both the
cleanup-row and cleanup-iteration queries over `system.text_log` by
`event_time_microseconds >= toDateTime64('$start_time', 6)`, so stale
rows from a previous run (e.g. under a fixed --database, where the
logger names are the same) cannot satisfy or break the assertions.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on 2eb9f50a511, Stress test (arm_msan) — Logical error: Stream y.Map(UInt64, UInt64).size0 for column y with type Dynamic(max_types=76) is not found in MergeTreeReaderWide::getStream during a merge — is unrelated to this PR (which only reorders renameParts in MutateFromLogEntryTask::finalize). The fix is already in progress: #113514 (shared SerializationDynamic cache entry between tables with different map_serialization_version, so a part's written Map layout can mismatch its declared one). Merged master and pushed 59f9c9771ea to re-run CI.

@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2b09dc7d4 with master b05b99a64 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 692.21 MiB 689.20 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

8 translation units recompiled, 20 s compile time in total, 8 of them have a recent master baseline.

Job report

Merged via the queue into master with commit 38f4dc4 Aug 13, 2026
357 of 359 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-mutation-temp-dir-cleanup-race branch August 13, 2026 18:43
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 13, 2026
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Aug 17, 2026
A Performance Comparison shard that passed rendered a list of red rows, and
every affected query was listed twice. On PR ClickHouse#111992 shard
"arm_release, master_head, 1/6" was OK and its own message said "11 unstable",
yet the report showed 22 red rows that had to be hand-verified before the PR
could be attributed.

Two causes, both in the block building the "Check Results" rows:

The rows exist only to carry a per-query "query history" link, and each was
constructed with a hardcoded FAIL, demoting the slower/unstable verdict to
info. The job status was unaffected because "Check Results" is passed an
explicit status and Result.create_from aggregates children only when no status
is given, so a green job rendered red children. json.html already classifies
both statuses natively in shouldShowRow and getStatusPriority, so passing the
real verdict through is sufficient; getStatusClass was the only one of the
three maps with no case for "slower", which is why a slower query rendered
gray. One line added there.

compare.sh emits one row per side, array join map('old', left, 'new', right),
naming them "<query> #<idx>::old" and "::new", so 11 queries became 22 rows.
Only the candidate side is listed now, and only its displayed name is stripped:
the history query filters test_name on an exact match and the CI database
stores the suffixed name, so the row keeps its original name for the link.
compare.sh is left alone deliberately, because its per-side rows are what the
CI database stores; changing the emission would fork that history and break
every existing per-query history link. Verified that the rows inserted into the
CI database are byte-identical before and after, and that the links still
resolve.

The loop is extracted into build_check_results_children so it can be tested;
behaviour is otherwise unchanged.

Tests are driven by two trimmed real shard artifacts: the one from ClickHouse#111992, and
a failing release_base shard as a negative control that must stay red. The
parent's own message states the query count, which is an independent oracle for
the row count.

Related: ClickHouse#111992
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Aug 17, 2026
The Check Results rows were selected by skipping every "::old" row, which
assumes compare.sh's "::new" mate always arrives. It does not.

compare.sh writes ci-checks.tsv last, so a failure there (most often a full
disk) leaves a byte prefix, and read_ci_checks_results deliberately imports the
intact rows of a torn file rather than killing the job before praktika uploads
the artifacts. Rows are emitted "::old" before "::new" per query, so a cut tail
always keeps the reference side and loses the candidate one. Such a query was
then dropped from the report entirely: it lost the query history link that is
the only reason these rows exist, and the row count stopped matching the query
count the parent message states.

Group the rows by query instead and represent each group by the side that
survived, preferring "::new". The history link is built from the represented
row's own name, so a reference-only row links to the history CIDB actually
stores for it.

Measured through the importer: a file cut inside its last row parses to
[q_a::old, q_a::new, q_b::old] and listed q_a alone; it now lists both.

Reported in ClickHouse#111992
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 17, 2026
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Every conflict is master-only context the cherry-pick drags along, not a
divergence in the change itself. Kept only what it contributes and dropped:

- `new_part->getDataPartStorage().commitTransaction();` after
  `renameTempPartAndReplace`. No release branch has it; they only
  `precommitTransaction` above.
- The `rmt_mutate_task_pause_after_zero_copy_lock` and
  `merge_tree_background_task_marked_for_deletion` failpoints, and the
  matching `extern`. Neither is registered on the older branches, and nothing
  in this file uses them, so taking the `extern` would not link. Note that a
  blank line among the `PAUSEABLE(...) \` entries would silently end the macro
  list, so the two new entries are appended without one.
- The `MutateFromLogEntryTask::~MutateFromLogEntryTask` destructor and
  `Stopwatch commit_watch;`, both master-only and unused here.

What lands is the fix itself: the two new failpoints, and
`transaction_ptr->renameParts()` moved out of the `try` block to before
`mutate_task.reset()`, so the rename happens while the `TemporaryParts` guard
still keeps `clearOldTemporaryDirectories` off the `tmp_mut_<part>` directory.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Every conflict is master-only context the cherry-pick drags along, not a
divergence in the change itself. Kept only what it contributes and dropped:

- `new_part->getDataPartStorage().commitTransaction();` after
  `renameTempPartAndReplace`. No release branch has it; they only
  `precommitTransaction` above.
- The `rmt_mutate_task_pause_after_zero_copy_lock` and
  `merge_tree_background_task_marked_for_deletion` failpoints, and the
  matching `extern`. Neither is registered on the older branches, and nothing
  in this file uses them, so taking the `extern` would not link. Note that a
  blank line among the `PAUSEABLE(...) \` entries would silently end the macro
  list, so the two new entries are appended without one.
- The `MutateFromLogEntryTask::~MutateFromLogEntryTask` destructor and
  `Stopwatch commit_watch;`, both master-only and unused here.

What lands is the fix itself: the two new failpoints, and
`transaction_ptr->renameParts()` moved out of the `try` block to before
`mutate_task.reset()`, so the rename happens while the `TemporaryParts` guard
still keeps `clearOldTemporaryDirectories` off the `tmp_mut_<part>` directory.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Every conflict is master-only context the cherry-pick drags along, not a
divergence in the change itself. Kept only what it contributes and dropped:

- `new_part->getDataPartStorage().commitTransaction();` after
  `renameTempPartAndReplace`. No release branch has it; they only
  `precommitTransaction` above.
- The `rmt_mutate_task_pause_after_zero_copy_lock` and
  `merge_tree_background_task_marked_for_deletion` failpoints, and the
  matching `extern`. Neither is registered on the older branches, and nothing
  in this file uses them, so taking the `extern` would not link. Note that a
  blank line among the `PAUSEABLE(...) \` entries would silently end the macro
  list, so the two new entries are appended without one.
- The `MutateFromLogEntryTask::~MutateFromLogEntryTask` destructor and
  `Stopwatch commit_watch;`, both master-only and unused here.

What lands is the fix itself: the two new failpoints, and
`transaction_ptr->renameParts()` moved out of the `try` block to before
`mutate_task.reset()`, so the rename happens while the `TemporaryParts` guard
still keeps `clearOldTemporaryDirectories` off the `tmp_mut_<part>` directory.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Cherry pick #111992 to 26.3: Fix a mutated part losing files to the temporary directory cleanup
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Cherry pick #111992 to 26.6: Fix a mutated part losing files to the temporary directory cleanup
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Cherry pick #111992 to 26.7: Fix a mutated part losing files to the temporary directory cleanup
robot-clickhouse added a commit that referenced this pull request Sep 17, 2026
robot-clickhouse added a commit that referenced this pull request Sep 17, 2026
robot-clickhouse added a commit that referenced this pull request Sep 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 17, 2026
PedroTadim added a commit that referenced this pull request Sep 17, 2026
Backport #111992 to 26.3: Fix a mutated part losing files to the temporary directory cleanup
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #111992 to 26.6: Fix a mutated part losing files to the temporary directory cleanup
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #111992 to 26.7: Fix a mutated part losing files to the temporary directory cleanup
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Sep 28, 2026
The cleanup thread writes `... is in use (by merge/mutation/INSERT)` at most
once per 10 seconds per table (`LogFrequencyLimiter` in
`MergeTreeData::clearOldTemporaryDirectories`), so the row about the paused
mutation's temporary directory can be held back by an earlier row about
another directory of the same table. In both failures the INSERT's own
`tmp_insert_all_1_1_0` was flagged first, because its rename on object storage
took about 1.4 s. Phase 1 waited only two cleanup iterations and then read
`system.text_log`, which had no row for the mutation's directory yet (or had
it written but not flushed), so it printed `0 0` instead of `1 0`.

Phase 1 now flushes and polls, bounded by 60 seconds of wall clock, until the
row about the mutation's directory is in `system.text_log`. Phase 2, the
regression check for ClickHouse#111992, is
unchanged.

CI reports:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121216&sha=ef01f2e8d8d7c0d86a1893f72eb4a2a7ba7bc455&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29
(ClickHouse#121216, which does not touch this test)
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=ecf87398fcafe260f22e26909bda0b6a84c67b36&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%201%2F2%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants