Skip to content

Fix flaky test 03365_column_ttl_should_rebuild_skp_idx_and_proj - #108805

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-03365-column-ttl-deterministic-merge
Jul 29, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-03365-column-ttl-deterministic-merge

Conversation

@groeneai

@groeneai groeneai commented Jun 29, 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):

...

Description

Fix flaky 03365_column_ttl_should_rebuild_skp_idx_and_proj (600s timeout on Stateless tests (amd_msan, WasmEdge, parallel, 2/2)).

The test polled a fresh clickhouse-client every second (up to 300 iterations) waiting for a background column-TTL merge to zero out x. On the amd_msan/WasmEdge shard each client spawn carries large overhead, and the background TTL merge is not guaranteed to run soon (merge_with_ttl_timeout default is 4h), so the loop exhausted the 600s job cap and timed out.

CIDB confirms this is a hang, not an intrinsically-slow test: OK runs on this shard are p50 15s / p90 19s / max 70s, but the failures sit exactly at 600.1s.

Fix: replace the polling loop with OPTIMIZE TABLE tbl FINAL. This forces the merge synchronously through the same code path the background TTL merge uses (drops the expired columns and recalculates the dependent skip index and projection), so it is deterministic and finishes in ~1.5s. The assertions and the .reference are unchanged, so the test still verifies that the skip index and projection are rebuilt when a column is fully dropped by TTL.

Verified locally: 80/80 passes with randomization enabled (~1.5s each). Reproduced the timeout path by suppressing the background TTL merge (the original loop never converges; OPTIMIZE FINAL applies the TTL in ~0.1s).

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108787&sha=505ad9efc6bf49975d1d54b0a6045adff0ff144b&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29

Version info

  • Merged into: 26.8.1.360 (included in 26.8 and later)

The test polled a fresh clickhouse-client every second (up to 300 iterations)
waiting for a background column-TTL merge to zero out x. On the amd_msan/WasmEdge
shard each client spawn carries large overhead and the background TTL merge is
not guaranteed to run soon (merge_with_ttl_timeout default is 4h), so the loop
exhausted the 600s job cap and timed out (CIDB: OK runs p50 15s / max 70s, but
the failures sit exactly at 600.1s).

Replace the polling loop with OPTIMIZE TABLE tbl FINAL, which forces the merge
synchronously through the same code path the background TTL merge uses: it drops
the expired columns and recalculates the dependent skip index and projection.
This is deterministic and finishes in ~1.5s. The assertions are unchanged, so
the test still verifies that the skip index and projection are rebuilt when a
column is fully dropped by TTL.

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. With the background TTL merge suppressed (merge_with_ttl_timeout=86400 or SYSTEM STOP MERGES), the original 300-iteration polling loop never converges, reproducing the timeout path. The fix converges in ~0.1s every run.
b Root cause explained? The test waits for a background column-TTL merge to zero x, polling a fresh clickhouse-client once per second. merge_with_ttl_timeout defaults to 4h, so the merge is not guaranteed soon; on the amd_msan/WasmEdge shard each client spawn is heavily slowed, so the 300-iteration loop exhausts the 600s job cap. CIDB: OK runs p50 15s / max 70s, failures exactly at 600.1s (a hang, not an intrinsically-slow test).
c Fix matches root cause? Yes. OPTIMIZE TABLE tbl FINAL forces the merge synchronously instead of waiting for the non-deterministic background TTL merge, removing the polling loop entirely.
d Test intent preserved / new tests added? Preserved. The three SELECTs and the .reference are unchanged. OPTIMIZE FINAL triggers the same merge code path (MergeTask) the background TTL merge uses, so the test still verifies the skip index and projection are recalculated when a column is fully dropped by TTL. force_optimize_projection_name='p' still has teeth (errors with INCORRECT_DATA if the projection is not used).
e Both directions demonstrated? Yes. Fails without fix (polling loop never converges when the background merge is suppressed); passes with fix 80/80 runs with randomization (~1.5s each).
f Fix is general across code paths? N/A (flaky test fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (flaky test fix, not a code bug).
i Invariants and contracts preserved? N/A (flaky test fix, not a code bug).

Session id: cron:clickhouse-worker-slot-0:20260629-101300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ — could you review this? It de-flakes 03365_column_ttl_should_rebuild_skp_idx_and_proj (600s timeout on amd_msan/WasmEdge) by replacing the background-TTL-merge polling loop with a deterministic OPTIMIZE TABLE tbl FINAL, which forces the same merge that drops the expired columns and recalculates the dependent skip index and projection. Assertions and reference are unchanged.

@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66b35a6]

Summary: ✅


AI Review

Summary

This PR replaces the polling loop in 03365_column_ttl_should_rebuild_skp_idx_and_proj.sh with a deterministic OPTIMIZE TABLE tbl FINAL, while keeping the assertions and .reference unchanged. That matches the stated root cause, follows existing TTL/projection test patterns in the suite, and the current PR CI run is green, so I do not see an unresolved correctness or coverage gap in the change itself.

Final Verdict
  • Status: ✅ Approve

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

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

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

Newly covered by added/modified tests: 407 line(s), 29 function(s) across 138 file(s) · Details

Top files
  • src/Storages/ObjectStorageQueue/ObjectStorageQueuePostProcessor.cpp: 24 line(s), 4 function(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 18 line(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 15 line(s)
  • src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp: 13 line(s), 1 function(s)
  • src/Parsers/parseFieldFromCastedLiteral.cpp: 10 line(s), 11 function(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — ce7712b

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_debug) / Logical error: Not-ready Set is passed as the second argument (STID 0250-41a5) chronic trunk fuzzer LOGICAL_ERROR (14 master hits + 51 PRs / 30d; function IN set-not-ready race; unrelated to this PR's column-TTL test fix) a fix task is investigating at full effort (fixing-PR link to follow here)
CH Inc sync - CH Inc sync (private, not actionable)

This PR's own fix (03365_column_ttl_should_rebuild_skp_idx_and_proj — replace the polling loop with OPTIMIZE FINAL) is green; the sole red check is the pre-existing chronic "Not-ready Set" fuzzer LOGICAL_ERROR, tracked by a full-effort fix task.

Session id: cron:our-pr-ci-monitor:20260629-183000

@Fgrtue Fgrtue self-assigned this Jul 2, 2026

@Fgrtue Fgrtue left a comment

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.

LGTM

@Fgrtue

Fgrtue commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@alexey-milovidov the fix for the test 03365_column_ttl_should_rebuild_skp_idx_and_proj is also done in your PR #96130, However, you PR is big an touches not only test 03365_column_ttl_should_rebuild_skp_idx_and_proj, but many other files. Do you think it is okay if this PR is merged first in case it is ready earlier than yours, or should I close this one in favor of #96130?

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

@Fgrtue thanks. Confirmed: #96130 applies the same fix to this test (drop the 300-iteration polling loop, force the merge with OPTIMIZE TABLE tbl FINAL), and additionally adds a no-random-detach tag that only #96130 needs since it introduces the DETACH/ATTACH randomization; #108805 does not need that tag.

#108805 is a single-file, approved, CI-green change, so merging it now fixes the 600s amd_msan/WasmEdge timeout without touching or destabilizing the other 430 files in #96130. Since the 03365 change is near-identical in both, whichever lands first makes the other's 03365 edit a trivial drop/rebase. I am equally happy to close #108805 in favor of #96130 if you prefer a single landing. I will defer the ordering to you.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 29, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

#96130 is huge, it's unclear when it will be merged. It discovers and accumulates a lot of fixes, but all of them make sense to be submitted separately.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Agreed, I will keep #108805 open then.

It is one test file (03365_column_ttl_should_rebuild_skp_idx_and_proj.sh, +7/-17), approved by @ Fgrtue, and CI is green on the current head: 0 failures across all 174 check-runs. The head is your master merge from 2026-07-28, so I have not pushed anything and will not merge master again unless you ask.

No conflict risk with #96130 either way: master has not touched this file since January, and #96130 applies the same fix here (drop the 300-iteration select x ... sleep 1 loop, force the merge with OPTIMIZE TABLE tbl FINAL), so whichever lands first makes the other's 03365 hunk a trivial drop.

Merged via the queue into ClickHouse:master with commit 3939f2c Jul 29, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 29, 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 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