Skip to content

Fix flaky test 02441_alter_delete_and_drop_column - #108926

Merged
cv4g merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-02441-alter-delete-drop-column-flaky
Jul 2, 2026
Merged

cv4g merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-02441-alter-delete-drop-column-flaky

Conversation

@groeneai

@groeneai groeneai commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Fix flaky test 02441_alter_delete_and_drop_column.

Description

Requested by @alexey-milovidov in #106821, where this was the only red check (in Stateless tests (amd_tsan, parallel, 2/2)) and unrelated to that PR.

Root cause. After SYSTEM STOP MERGES + ALTER TABLE ... DELETE, the test waits for the MUTATE_PART log entry to appear in system.replication_queue via a bounded poll loop (url(... param_tries={1..10} ...) with sleepEachRow(2), i.e. up to 20s). That entry is assigned asynchronously by mergeSelectingTask. StorageReplicatedMergeTree::mutate() wakes the task immediately, but under heavy parallel CI load the BackgroundSchedulePool can run it late, and a CannotSelect attempt backs off (merge_selecting_sleep_ms = 5s, growing x1.2). When assignment lands past the 20s window the loop gives up, the queue select misses the MUTATE_PART line, and the n=10 row is never deleted, giving the observed result-differs:

-MUTATE_PART	all_0_0_0_1	['all_0_0_0']
 1	2
+10	20

STOP MERGES blocks mutation execution, not assignment, so once assigned the entry stays queued until START MERGES; waiting for it to appear is correct, it just needs a reliable budget.

Fix. Extend the three poll loops from {1..10} (20s) to {1..30} (60s, matching the test's own receive_timeout=30). The loops early-terminate as soon as the condition holds, so a normal run is unaffected (~sub-second). The reference output and the test's assertions are unchanged.

Reproduction (local). With the rmt_merge_selecting_task_pause_when_scheduled failpoint forcing a delayed assignment, the old {1..10} loop produces exactly the failure signature above, while the new {1..30} loop (assignment released after ~8s) produces the expected reference output. The flake is rare (the specific signature appears in CIDB only twice in 90 days; there are no true-master occurrences).

Version info

  • Merged into: 26.7.1.431 (included in 26.7 and later)

The test waits for the async MUTATE_PART log entry (assigned by
mergeSelectingTask) to appear in system.replication_queue using a bounded
poll loop of param_tries={1..10} (up to 20s). Under heavy parallel CI load
the BackgroundSchedulePool can delay the assignment past that window, so the
loop gives up before the entry is created: the queue select then misses the
MUTATE_PART line and the ALTER DELETE row is never removed, producing the
observed result-differs failure.

Extend the three poll loops from {1..10} (20s) to {1..30} (60s, matching the
test's own receive_timeout=30) so assignment is tolerated under contention.
The loops early-terminate the moment the condition is met, so a normal run is
unaffected. Test intent and the reference output are unchanged.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Enabling failpoint rmt_merge_selecting_task_pause_when_scheduled to delay MUTATE_PART assignment past the 20s poll window makes the old {1..10} loop produce the exact failure on demand.
b Root cause explained? Yes. The MUTATE_PART log entry is assigned async by mergeSelectingTask. mutate() wakes it immediately, but under parallel-CI BackgroundSchedulePool contention the run is delayed and CannotSelect attempts back off (merge_selecting_sleep_ms=5s x1.2). When assignment lands past the test's 20s wait, the loop gives up, the queue select misses the MUTATE_PART line, and the n=10 row is never deleted -> result differs.
c Fix matches root cause? Yes. The fix extends the bounded wait to tolerate a delayed-but-correct async assignment, addressing the timing mechanism directly. It does not weaken any assertion or disable randomization.
d Test intent preserved / new tests added? Yes. The .reference and all assertions are unchanged; the test still observes the queued MUTATE_PART entry and verifies the deletion applies. Only the poll budget grows ({1..10}->{1..30}).
e Both directions demonstrated? Yes. Old 20s wait + delayed assignment -> 1/10 20 (FAIL, byte-identical to the CIDB diff). New 60s wait + assignment released after ~8s -> MUTATE_PART all_0_0_0_1 ['all_0_0_0']/1 2 (PASS).
f Fix is general across code paths? Yes. All three poll loops in the test (one for MUTATE_PART, two for ALTER_METADATA) get the same extended budget, so the whole test is hardened against the same class of contention delay.
g Fix generalizes across inputs? N/A (flaky test timing fix, not a code bug).
h Backward compatible? N/A (flaky test timing fix, not a code bug).
i Invariants and contracts preserved? N/A (flaky test timing fix, not a code bug).

Session id: cron:clickhouse-worker-slot-5:20260630-101200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — fix for the 02441_alter_delete_and_drop_column flake you flagged in #106821. Test-only: extends the bounded poll loops that wait for the async MUTATE_PART assignment from {1..10} (20s) to {1..30} (60s), reproduced and validated in both directions with the rmt_merge_selecting_task_pause_when_scheduled failpoint. Root cause and repro in the PR description.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [24c098d]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Logical error: Invalid number of rows in Chunk A column B at position C: expected D, got E (STID: 3366-2d1d) FAIL cidb IGNORED
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR hardens flaky stateless test 02441_alter_delete_and_drop_column by extending the existing bounded HTTP polling loops from {1..10} to {1..30} while keeping the same assertions and reference output. I found no correctness, safety, or PR-metadata issues that need changes.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.74% 85.75% +0.01%
Functions 91.47% 91.47% +0.00%
Branches 78.34% 78.38% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 101 line(s), 12 function(s) across 45 file(s) · Details

Top files
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesGroupArray.h: 10 line(s), 8 function(s)
  • src/Storages/MergeTree/MergeTreeDataPartChecksum.cpp: 7 line(s)
  • src/Functions/structureToFormatSchema.cpp: 5 line(s)
  • src/Interpreters/HashJoin/HashJoin.cpp: 5 line(s)
  • src/Functions/getServerPort.cpp: 4 line(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 24c098d

CI fully finished (Finish Workflow: success). This PR is a test-only change: it extends the three poll loops in 02441_alter_delete_and_drop_column from {1..10} (20s) to {1..30} (60s) so the async MUTATE_PART assignment is reliably observed. Every failure has an owner; none is PR-caused (a .sql poll-budget change cannot cause a stress-test crash or a hung check).

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / "Invalid number of rows in Chunk" (STID 3366-2d1d) crash (chronic trunk LOGICAL_ERROR in JoiningTransform; 31 hits / 23 PRs / 6 master in 30d; not in this test-only PR path) #106928 (ours, open)
Stress test (arm_tsan) / "Hung check failed, possible deadlock found" deadlock (chronic hung-check family) #108212 (ours, merged) / #105905 (ours, open)
CH Inc sync - CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260630-173000

@cv4g
cv4g added this pull request to the merge queue Jul 2, 2026
Merged via the queue into ClickHouse:master with commit 7ac2edc Jul 2, 2026
171 of 174 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-alter-delete-drop-column-flaky

Fix flaky test 02441_alter_delete_and_drop_column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

4 participants