Skip to content

Write part_log entry before reporting a plain MergeTree mutation as done - #107741

Merged
azat merged 2 commits into
ClickHouse:masterfrom
azat:mt-mutations-part_log-race
Jun 19, 2026
Merged

azat merged 2 commits into
ClickHouse:masterfrom
azat:mt-mutations-part_log-race

Conversation

@azat

@azat azat commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Otherwise after "ALTER SETTINGS mutations_sync=2" and "SYSTEM FLUSH LOGS part_log" you may not see this mutation as in 1:

2026-06-17T13:01:58.1385357Z [2026-06-17 13:01:58] [ 6835 / 11515] 03568_mutation_affected_rows_counter:                                   [ FAIL ] 0.18 sec.
2026-06-17T13:01:58.1386195Z [2026-06-17 13:01:58] Reason: result differs with reference:
2026-06-17T13:01:58.1387248Z [2026-06-17 13:01:58] --- /home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/tests/queries/0_stateless/03568_mutation_affected_rows_counter.reference
2026-06-17T13:01:58.1388336Z                       2026-06-17 14:54:43.238557950 +0200
2026-06-17T13:01:58.1389136Z [2026-06-17 13:01:58] +++ /home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/tests/queries/0_stateless/03568_mutation_affected_rows_counter.216313.stdout
2026-06-17T13:01:58.1389938Z                       2026-06-17 15:01:58.111713786 +0200
2026-06-17T13:01:58.1390288Z [2026-06-17 13:01:58] @@ -1,2 +1 @@
2026-06-17T13:01:58.1390611Z [2026-06-17 13:01:58]  151	2
2026-06-17T13:01:58.1390888Z [2026-06-17 13:01:58] -1000	1

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Version info

  • Merged into: 26.6.1.1052

Otherwise after "ALTER SETTINGS mutations_sync=2" and "SYSTEM FLUSH LOGS
part_log" you may not see this mutation as in [1]:

    2026-06-17T13:01:58.1385357Z [2026-06-17 13:01:58] [ 6835 / 11515] 03568_mutation_affected_rows_counter:                                   [ FAIL ] 0.18 sec.
    2026-06-17T13:01:58.1386195Z [2026-06-17 13:01:58] Reason: result differs with reference:
    2026-06-17T13:01:58.1387248Z [2026-06-17 13:01:58] --- /home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/tests/queries/0_stateless/03568_mutation_affected_rows_counter.reference
    2026-06-17T13:01:58.1388336Z                       2026-06-17 14:54:43.238557950 +0200
    2026-06-17T13:01:58.1389136Z [2026-06-17 13:01:58] +++ /home/ubuntu/actions-runner/_work/ClickHouse/ClickHouse/tests/queries/0_stateless/03568_mutation_affected_rows_counter.216313.stdout
    2026-06-17T13:01:58.1389938Z                       2026-06-17 15:01:58.111713786 +0200
    2026-06-17T13:01:58.1390288Z [2026-06-17 13:01:58] @@ -1,2 +1 @@
    2026-06-17T13:01:58.1390611Z [2026-06-17 13:01:58]  151	2
    2026-06-17T13:01:58.1390888Z [2026-06-17 13:01:58] -1000	1

  [1]: https://github.com/ClickHouse/ClickHouse/actions/runs/27690285295
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [189f802]

Summary: ❌

job_name test_name status info comment
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue

AI Review

Summary

This PR tries to make plain MergeTree synchronous mutations queue the MutatePart row before mutations_sync returns, and adds coverage for failed mutations. The failure path is now ordered correctly, but the success path still has a race because the mutation becomes observable as done at transaction.commit before the part-log row is queued.

Findings

⚠️ Majors

  • [src/Storages/MergeTree/MutatePlainMergeTreeTask.cpp:143] mutations_sync can still return before MutatePart is queued on success. waitForMutation polls every second in addition to being notified by updateMutationEntriesErrors; once transaction.commit makes the new part visible, a timed poll can see the mutation as done while the background task is between the commit and write_part_log. An immediate SYSTEM FLUSH LOGS part_log can still take its flush target before the push.
    Suggested fix: make the completion condition observed by mutations_sync happen after the part-log entry is queued, or otherwise prevent the timed-poll path from treating the mutation as done until that point.
Tests
  • ⚠️ The success-path coverage still does not force the waiter to wake from the one-second poll after transaction.commit but before write_part_log. Add focused coverage with a failpoint or synchronization at that window, or change the implementation so that window no longer exists and test that SYSTEM FLUSH LOGS part_log after mutations_sync = 2 sees the current mutation row.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: close the success-path timed-poll race and add focused coverage or another proof that mutations_sync cannot return before the corresponding MutatePart row is queued.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 17, 2026
@azat
azat enabled auto-merge June 19, 2026 15:25
@azat
azat force-pushed the mt-mutations-part_log-race branch from 7267e1c to 189f802 Compare June 19, 2026 15:37
/// Write the part log entry before reporting the mutation as done, otherwise a
/// synchronous mutation (mutations_sync) may return to the client before the
/// MutatePart row is queued, so a subsequent SYSTEM FLUSH LOGS misses it.
write_part_log({});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does not guarantee that mutations_sync waits for the part-log row. waitForMutation is not only woken by updateMutationEntriesErrors; it also polls every second. After transaction.commit the mutated part is visible, so a waiter whose timed wait expires while this background task is between the commit and this write_part_log will see getIncompleteMutationsStatus as done and can return before the MutatePart row is queued. An immediate SYSTEM FLUSH LOGS part_log can still take its target before this push. Please make the completion condition observed by mutations_sync happen after the part-log entry is queued, or otherwise block the timed-poll path too.

@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.40% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 14/14 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@azat
azat added this pull request to the merge queue Jun 19, 2026
Merged via the queue into ClickHouse:master with commit baadbda Jun 19, 2026
164 of 167 checks passed
@azat
azat deleted the mt-mutations-part_log-race branch June 19, 2026 19:48
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants