Skip to content

Fix flaky test test_ttl_move/test.py::test_moves_after_merges - #128704

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-moves-after-merges-ttl-window
Nov 3, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-moves-after-merges-ttl-window

Conversation

@groeneai

@groeneai groeneai commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #128619

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):

Not required.

Description

Failure: Integration tests (amd_asan_ubsan, db disk, 3/8) on #128619 55595802aa93: step 1 found the merged part on external instead of jbod1.

The test inserts two parts with d1 = now + 3 s under SYSTEM STOP MOVES, runs OPTIMIZE and expects the merged part to stay on jbod1. SYSTEM STOP MOVES only stops the background mover: a merge reserves its own space and goes to the TTL destination if the TTL has already expired (MergeTreeData::tryReserveSpacePreferringTTLRules). The 3 s window had to cover both INSERTs and the OPTIMIZE. In the failing job the OPTIMIZE reached the server 1.66 s after the client sent it, 0.22 s after the TTL expired, and the server logged Trying to reserve 1.00 MiB to apply a TTL rule for that merge.

Both parts now share one TTL timestamp, int(time.time()) + 10 (about 3.5x the 2.84 s the failing job needed from the first INSERT to the OPTIMIZE reaching the server), and step 2 sleeps until exactly that time instead of a fixed 3 s. The assertions are unchanged.

Validation (master ASan build, both [mt] and [rmt]):

  • With a 3 s sleep injected before OPTIMIZE, the old test fails with the CI assertion and server log line, and the fixed test passes.
  • The fixed test with an 11 s sleep fails in step 1, and without SYSTEM START MOVES it fails in step 2, so both checks still catch their case.
  • 20/20 passes; one run takes ~13.6 s instead of ~9.2-10.3 s.

The other checks in this file that run on 3 s TTL data before it expires (test_inserts_and_moves, test_merges_to_disk, test_move_after_policy_change, test_replicated_download_ttl_info) are unchanged: none of their ~1.1M runs in 90 days of CIDB failed this way.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/128704]

Version info

  • Merged into: 26.11.1.1189-master (included in 26.11 and later)

The test inserted two parts with `d1 = now + 3 s` under `SYSTEM STOP MOVES`,
ran `OPTIMIZE`, and expected the merged part to stay on `jbod1` (step 1).
`SYSTEM STOP MOVES` only blocks the background mover: a merge picks its
destination itself and honours a move TTL that has already expired
(`MergeTreeData::tryReserveSpacePreferringTTLRules`, with `time(nullptr)` for
MergeTree and the log entry create time for ReplicatedMergeTree). The window
was 3 s minus the fraction `toDateTime(float)` truncates, and had to cover both
INSERTs and the OPTIMIZE reaching the server. In the failing ASan+UBSan job
the OPTIMIZE reached the server 1.66 s after the client issued it, 0.22 s after
the TTL expired, so the merge itself placed the part on `external` and step 1
saw `{'external': 20}`.

Both parts now share one TTL timestamp, `int(time.time()) + 10`, taken before
the inserts, and step 2 sleeps until exactly that timestamp instead of a fixed
3 s, so the existing 30 s wait is left for the move.

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

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: 0 blockers, 0 open majors
Finding Verdict
⚠️ Gate B: the fixed 10 s window needs proof in both directions for [mt] and [rmt] DISAGREE: done locally for both engines. With a 3 s delay injected before OPTIMIZE, the old test fails with the CI assertion and the fixed test passes. An 11 s delay fails step 1; without SYSTEM START MOVES, step 2 fails; 20/20 plain runs pass. Merge placement reads wall-clock time, so a margin is the only control a test has.
💡 Gate B: backtick SQL names in the new comment AGREE, nit (comment-only, not applied in this head)
💡 Own review: other 3 s TTL checks in the file Not changed: each races only one INSERT's own latency, 0 failures of this kind in ~1.1M CIDB runs (90 days)

@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The old test with time.sleep(3) injected before OPTIMIZE fails for [mt] and [rmt] with the CI assertion ({'external': {'rows': 20}} vs {'jbod1': {'rows': 20}}) and the CI server log line Trying to reserve 1.00 MiB to apply a TTL rule.
b Root cause explained? SYSTEM STOP MOVES blocks only the background mover. The OPTIMIZE merge picks its own destination and applies a move TTL that has already expired. The 3 s TTL window had to cover two INSERTs plus the OPTIMIZE, and in the failing ASan+UBSan job the OPTIMIZE reached the server 0.22 s after the TTL expired.
c Fix matches root cause? Yes. Both parts share one TTL timestamp, now + 10 s, taken before the inserts, so step 1 can always meet its window. Step 2 sleeps until that exact timestamp. No widened assertion, tag, retry or data reduction.
d Test intent preserved / new tests added? Yes. With an 11 s injected sleep, step 1 fails again (it still catches a TTL placement made at merge time). Without SYSTEM START MOVES, step 2 fails (the background mover does the move). The test itself is the deliverable.
e Both directions demonstrated? Yes, under the same injected 3 s latency: the old test fails 2/2 and the fixed test passes 2/2. The unmodified fixed test passes 20/20.
f Fix is general across code paths? MergeTree and ReplicatedMergeTree merge placement, insert placement and any background merge all happen before the TTL timestamp. Both params ran in every arm. The sibling 3 s TTL checks in this file are unchanged: 0 failures of this kind in ~1.1M runs over 90 days of CIDB.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test timing fix; both engine parametrizations exercised).
h Backward compatible? (maintainer-approved exception only) N/A (test-only change).
i Invariants and contracts preserved? Every placement decision before step 1 is taken with the TTL not yet expired. The move-TTL choice uses the part's max TTL, which is the shared timestamp. Step 2 starts only after the TTL has expired.

Session id: cron:clickhouse-impl-slot-7:20261102-153800

@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ, could you review this and add the can be tested label so CI runs? SYSTEM STOP MOVES does not stop an OPTIMIZE merge from placing its part by an already expired move TTL, so the test now gives both parts one TTL 10 s ahead (the old 3 s window was missed by a slow OPTIMIZE under ASan+UBSan) and step 2 waits until exactly that time.

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f711e8a]

Summary: ✅


AI Review

Summary

The PR gives both inserted parts in test_moves_after_merges one TTL deadline ten seconds ahead and waits until that deadline before checking the background move. This addresses the observed premature merge placement while preserving the existing assertions. No actionable findings.

Missing context / blind spots
  • ⚠️ Integration CI has not yet reported results for f711e8a2a3b13478f1a430411797ad97da3b583a, and integration tests were not rerun during this review. Validation evidence is the author's documented delay-injection checks for both MergeTree and ReplicatedMergeTree and 20 successful runs; completed targeted CI would provide independent confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 2, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Nov 2, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 3, 2026
Merged via the queue into ClickHouse:master with commit a79b6ce Nov 3, 2026
179 of 180 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 3, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 3, 2026
@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 Nov 3, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #128704 to 26.9: Fix flaky test `test_ttl_move/test.py::test_moves_after_merges`
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #128704 to 26.8: Fix flaky test `test_ttl_move/test.py::test_moves_after_merges`
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #128704 to 26.10: Fix flaky test `test_ttl_move/test.py::test_moves_after_merges`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-ttl TTL rules and TTL merges (moving/recompressing/rolling-up/deleting parts). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-ttl TTL rules and TTL merges (moving/recompressing/rolling-up/deleting parts). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci 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.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants