Skip to content

Fix flaky test 04027_system_start_replicated_view - #107254

Merged
nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-04027-system-start-replicated-view
Jun 12, 2026
Merged

nikitamikhaylov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-04027-system-start-replicated-view

Conversation

@groeneai

@groeneai groeneai commented Jun 11, 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

Fixes flaky 04027_system_start_replicated_view, seen on Stateless tests (arm_asan_ubsan, azure, parallel) (0 master hits; self-heals on rerun).

The <4: new rows> assertion waits for the resumed refreshable view to complete at least one more refresh after SYSTEM START REPLICATED VIEW. That wait was 30 iterations of 0.5s (15s), while both the initial-refresh wait and the stop wait earlier in the same test use 60 iterations (30s).

After resume, with REFRESH AFTER 1 SECOND the next refresh is scheduled in the past and fires immediately, but the BackgroundSchedulePool wake plus the Keeper round-trips to run the refresh and APPEND a row take at least as long as the initial refresh, plus an extra coordination watch round-trip. Under load this can exceed 15s, so the loop gives up before the row is appended and the test reports <4: new rows> 0. The engine behavior is correct: the view leaves Disabled (<3: restarted> 1 always passes) and a rerun succeeds.

This extends the restart wait to 120 iterations (60s) so the budget covers resume detection plus a full refresh run and is no shorter than the initial-refresh wait. Assertions and reference output are unchanged.

Reproduced deterministically by making the refresh body sleep ~18s: the old 15s loop reports <4: new rows> 0, a 60s loop reports 1. With the fix, 50/50 runs pass with randomization enabled.

Version info

  • Merged into: 26.6.1.697

The "<4: new rows>" assertion waits for the resumed refreshable view to
complete at least one more refresh after SYSTEM START REPLICATED VIEW. That
wait was only 30 iterations of 0.5s (15s), while both the initial-refresh
wait and the stop wait earlier in the test use 60 iterations (30s).

After resume, with REFRESH AFTER 1 SECOND the next refresh is scheduled in
the past and fires immediately, but the BackgroundSchedulePool wake plus the
Keeper round-trips to actually run the refresh and APPEND a row take at least
as long as the initial refresh did, plus an extra coordination watch
round-trip. Under load (seen on arm_asan_ubsan, azure, parallel) that can
exceed 15s, so the loop gives up before the row is appended and the test
reports "<4: new rows> 0". The engine behavior is correct (the view leaves
Disabled, "<3: restarted> 1" always passes) and a rerun succeeds.

Extend the restart wait to 120 iterations (60s) so the budget covers resume
detection plus a full refresh run and is no shorter than the initial-refresh
wait. The assertions and reference output are unchanged.

Reproduced deterministically by making the refresh body sleep ~18s: the old
15s loop reports "<4: new rows> 0" while a 60s loop reports 1.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. Make the refresh body sleep ~18s (as select 1 as x from numbers(6) where NOT sleepEachRow(3) settings function_sleep_max_microseconds_per_block=30000000), then the original 30-iteration (15s) restart-wait loop reports <4: new rows> 0 on every run; a 120-iteration (60s) loop reports 1.
b Root cause explained? After SYSTEM START REPLICATED VIEW, the resumed refresh fires immediately (next time is in the past for REFRESH AFTER 1 SECOND), but actually running it and appending a row needs a BackgroundSchedulePool wake plus Keeper round-trips (including a coordination-watch re-arm) — at least as long as the initial refresh. The restart wait was only 15s while the initial-refresh and stop waits are 30s, so under load (arm_asan_ubsan, azure, parallel) the loop exits before the append finishes and <4: new rows> is 0. <3: restarted> is always 1, and the run self-heals (Failed 0 out of 3 reruns).
c Fix matches root cause? Yes. The root cause is a too-short wait budget for an operation that the test elsewhere allows 30s for; the fix raises the restart wait to 60s so it covers resume detection plus a full refresh run. No assertion bound is widened and no randomization is disabled.
d Test intent preserved / new tests added? Preserved. The test still strictly requires the view to leave Disabled and to append at least one new row after resume; only the wait budget changed. Reference output is unchanged. This is a test-only flaky fix, so no new test is added.
e Both directions demonstrated? Yes. With the ~18s slow-refresh injection: old 15s loop -> <4: new rows> 0 (fails), 60s loop -> 1 (passes). With the fix and normal timing: 50/50 runs passed with randomization enabled.
f Fix is general, not a narrow patch? N/A (flaky test wait-budget fix, not a code bug). The engine behavior is already correct; no source code is changed and there are no sibling code paths to widen.

Session id: cron:clickhouse-worker-slot-10:20260611-163600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 — could you review this? It only extends the post-resume wait in 04027_system_start_replicated_view from 15s to 60s (matching the test's own initial-refresh wait), because under arm_asan_ubsan/azure load the resumed refresh can take longer than 15s to append a row and the loop gave up too early (<4: new rows> 0). Engine behavior is unchanged; assertions and reference output are unchanged.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [065e2f4]

Summary: ✅


AI Review

Summary
  • This PR is a test-only fix for flaky 04027_system_start_replicated_view: it extends the post-SYSTEM START REPLICATED VIEW polling budget from 15s to 60s while preserving the same assertions and reference output. I found no correctness issues or unresolved prior review findings in the current diff.
Final Verdict
  • Status: ✅ Approve

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

clickhouse-gh Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.30% 77.20% -0.10%

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

Newly covered by added/modified tests: 349 line(s), 56 function(s) across 99 file(s) · Details

Top files
  • src/Functions/FunctionShowCertificate.cpp: 37 line(s), 3 function(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesChanges.h: 14 line(s), 32 function(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesGroupArray.h: 14 line(s), 8 function(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeRestartingThread.cpp: 12 line(s)
  • src/Storages/MaterializedView/RefreshTask.cpp: 10 line(s)

Full report

@nikitamikhaylov nikitamikhaylov self-assigned this Jun 12, 2026
@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jun 12, 2026
Merged via the queue into ClickHouse:master with commit 8e7eda8 Jun 12, 2026
166 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 12, 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.

3 participants