Skip to content

Fix flaky test 02417_load_marks_async with parallel replicas - #123825

Merged
devcrafter merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02417-load-marks-async-parallel-replicas
Oct 5, 2026
Merged

devcrafter merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-02417-load-marks-async-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Oct 4, 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):

The test 02417_load_marks_async now sums BackgroundLoadingMarksTasks over the initial query and the parallel replicas queries it starts, instead of reading only the initiator's system.query_log row.

Description

Related: #122853 (added the lane)
Related: #123790 (re-land)

The test fails in about 1% of runs in the new Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential) lane: job 1, job 2. It expects ProfileEvents['BackgroundLoadingMarksTasks'] != 0 in the initiator's query_log row.

The table has 123 marks, one segment, which the coordinator assigns to a remote replica. The local replica reads only by stealing from an owner that has not announced yet. In both failing jobs a remote replica announced first, so the local replica read nothing. All marks were loaded by the two remote replicas, while the initiator row has 0: remote profile events are not merged into it. With parallel_replicas_local_plan = 0 the initiator row is always 0.

The check now sums the counter over initial_query_id, which also matches the initiator row, so nothing changes without parallel replicas. The replica rows have current_database = 'default', so the filter becomes has(databases, currentDatabase()).

Validation on a master debug binary with the lane's 3-replica config:

  • parallel_replicas_local_plan = 0: old check 10/10 FAIL (-Ok/+F), new check 10/10 OK;
  • failpoint slowdown_parallel_replicas_local_plan_read: the old check failed in exactly the 5/10 runs where the local replica got 0 marks; the new check passed 10/10, 6 of them with 0 local marks;
  • load_marks_asynchronously = 0: the new check returns 0;
  • randomized: 50/50 with parallel replicas (7 runs had an initiator row of 0), 50/50 with parallel_replicas_local_plan = 0, 50/50 without parallel replicas.

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

Version info

  • Merged into: 26.10.1.1545-master (included in 26.10 and later)

The test checked `ProfileEvents['BackgroundLoadingMarksTasks'] != 0` in the
initiator's `system.query_log` row only. Under parallel replicas the table
(one part, 123 marks) is a single 128-mark segment that the coordinator
assigns to a remote replica; the local replica reads only by stealing from an
owner that has not announced yet. When the remote owner's announcement arrives
first, the local replica reads nothing, the marks are loaded by the remote
replicas' secondary queries, and the initiator row stays 0 because remote
profile events are not merged into it. With `parallel_replicas_local_plan = 0`
the initiator row is always 0.

Sum the counter over `initial_query_id`, which also matches the initiator row,
so the result is unchanged without parallel replicas. The secondary queries log
`current_database = 'default'`, so filter with `has(databases, currentDatabase())`.

Seen in `Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential)`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 4, 2026
@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 finding).

# Sev Finding Verdict Evidence / action
1 💡 03254_prewarm_mark_cache_rmt and 03273_primary_index_cache also read reader-side counters from the initiator query_log row only AGREE, not changed here one failure each in this lane, both on #122853 with parallel_replicas_local_plan = 0; separate tests, out of scope of this PR

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261004-043300

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With parallel_replicas_local_plan = 0 the old check fails 10/10 with -Ok/+F. The CI race itself is forced with the in-tree failpoint slowdown_parallel_replicas_local_plan_read: the old check failed in exactly the runs where the local replica got 0 marks (5/10).
b Root cause explained? The table is one 128-mark segment owned by a remote replica. The local replica reads only by stealing before the owner announces; when it loses, all marks are loaded by the remote replicas, whose query_log rows (current_database = 'default') hold the counter, while the initiator row has 0.
c Fix matches root cause? Yes. The check now measures the whole query (initial plus secondary queries via initial_query_id). No tag, no pinned setting, no bound changed.
d Test intent preserved / new tests added? Yes. Still != 0 on a counter only the async load task increments; with load_marks_asynchronously = 0 the new check returns 0 on both parallel_replicas_local_plan values. Test-only change.
e Both directions demonstrated? Yes. local_plan = 0: 10/10 FAIL before, 10/10 OK after. Failpoint arm: 5/10 FAIL before (all race runs), 10/10 OK after with 6 race runs.
f Fix is general across code paths? N/A (test oracle, no product defect). The sibling tests 03640_load_marks_synchronously and 03759_marks_cache_events assert exact counts and already carry no-parallel-replicas.
g Fix generalizes across inputs (params/datatypes/wrappers)? Randomized 50/50 with parallel replicas (max_threads 1/2/3/32, 7 runs with an initiator row of 0), 50/50 with parallel_replicas_local_plan = 0, 50/50 without parallel replicas (15 runs with automatic_parallel_replicas_mode = 2). No datatype dimension.
h Backward compatible? (maintainer-approved exception only) N/A, test-only.
i Invariants and contracts preserved? Isolation holds: the fresh query id plus has(databases, currentDatabase()) count only this test's rows. Replicas write their QueryFinish row before sending EndOfStream, so the initiator's completion precedes the test's SYSTEM FLUSH LOGS query_log.

Session id: cron:clickhouse-impl-slot-6:20261004-040600

@clickhouse-gh

clickhouse-gh Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [634c768]

Summary: ✅


AI Review

Summary

This PR fixes the flaky oracle in 02417_load_marks_async by reading BackgroundLoadingMarksTasks across the whole query chain with initial_query_id instead of only the initiator row. I did not find a remaining correctness issue in the updated check: the query_log predicate matches existing parallel-replica test patterns, lines up with the failure mode described in the PR, and the validation in the PR body covers the important load_marks_asynchronously = 1 and load_marks_asynchronously = 0 cases.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 4, 2026
@groeneai
groeneai requested a review from devcrafter October 4, 2026 04:57
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 4, 2026
${CLICKHOUSE_CLIENT} -q "SYSTEM FLUSH LOGS query_log"

result=$(${CLICKHOUSE_CLIENT} -q "SELECT ProfileEvents['BackgroundLoadingMarksTasks'] FROM system.query_log WHERE event_date >= yesterday() AND event_time >= now() - 600 AND query_id = '${QUERY_ID}' AND type = 'QueryFinish' AND current_database = currentDatabase()")
# With parallel replicas the marks may be loaded only by the replicas, whose rows have current_database = 'default'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai The comment is not accurate. It'd be simpler to fix test by pinning parallel_replicas_local_plan=1 for the test query i.e. SELECT * FROM test SETTINGS load_marks_asynchronously=$1 FORMAT Null

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I rewrote the comment: 634c768.

Pinning parallel_replicas_local_plan = 1 doesn't close it, though: both CI failures already ran with it (it is not in their client args, and the lane does not randomize it). The local replica does use the local plan, it just gets nothing to read. The table is a single 128-mark segment hashed to replica 1, and the local replica only steals from an owner that has not announced yet (ParallelReplicasReadingCoordinator.cpp#L697). In the #123084 job replica 1 announced 48 microseconds before replica 0's first read request, the coordinator answered replica 0 with 0 marks. Finish: true, and only the two remote rows had BackgroundLoadingMarksTasks (10 and 10, initiator 0).

On a local 3-replica rig your variant (the pin plus the initiator-row check) failed 2/50 randomized runs, both with that same coordinator response. The summed check passed 50/50, with 17 of those runs at 0 on the initiator row.

If you'd rather keep the initiator-row check, the deterministic option is enable_parallel_replicas = 0 on that query, at the cost of this test's parallel-replicas coverage.

@devcrafter devcrafter self-assigned this Oct 4, 2026
The marks can be loaded only by remote replicas when the local replica gets
nothing to read: the table is a single segment owned by a remote replica, and
the local replica only steals before the owner announces itself. Pinning
`parallel_replicas_local_plan = 1` does not avoid that: the CI failures already
ran with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devcrafter
devcrafter added this pull request to the merge queue Oct 4, 2026
Merged via the queue into ClickHouse:master with commit 5b5bdf3 Oct 5, 2026
149 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 Oct 5, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 11, 2026
In the ParallelReplicas configuration the single segment of these tests'
tables is read by whichever of the three replicas gets it. When a remote
replica reads it, the mark and primary index load counters land on that
replica's own query_log row (is_initial_query = 0, current_database =
'default'), which the current_database = currentDatabase() filter drops, so
the initiator row shows 0. parallel_replicas_local_plan = 1 does not help:
the local plan is used but gets nothing to read.

Sum the counters over all rows whose initial_query_id is one of the test's
queries, as in 02417_load_marks_async (ClickHouse#123825). All replicas share one
server's caches and each load is counted once, so the exact references are
unchanged, and nothing changes without parallel replicas.

Failing job: 03254_system_prewarm_mark_cache in Stateless tests (arm_binary,
ParallelReplicas, s3 storage, sequential) on PR ClickHouse#124862.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... 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-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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