Skip to content

Fix flaky test_parallel_quorum_actually_quorum - #108433

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-flaky-quorum
Jun 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fix-flaky-quorum

Conversation

@groeneai

@groeneai groeneai commented Jun 25, 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 the flaky integration test test_quorum_inserts_parallel/test.py::test_parallel_quorum_actually_quorum.

Failure: the final line node2.query("SYSTEM SYNC REPLICA q", timeout=10) raises QueryTimeoutExceedException: Client timed out!. 100% of the 30-day CIDB failures are on slow sanitizer integration shards (asan / tsan / msan); ~13 distinct PRs + 2 master hits, none related to the failing test.

Root cause: the test partitions node2 from node1/node3 on the interserver port (9009) for the whole body. While partitioned, node2 still reaches ZooKeeper, pulls the log and creates GET_PART queue entries, but every fetch fails ("Connection refused"). Each failure increments the entry's num_tries, and ReplicatedMergeTreeQueue::getPostponeTimeMsForEntry schedules the next attempt 1 << num_tries ms out (capped at max_postpone_time_for_failed_replicated_fetches_ms, default 60000). After enough failed tries the next retry is scheduled more than 10s out, so once the partition heals the SYSTEM SYNC REPLICA must wait out that accumulated backoff and the client times out. On the slow sanitizer shards the partition phase lasts long enough for num_tries to cross the threshold, which is why it is sanitizer-only.

Fix: disable the fetch-failure backoff for this table (max_postpone_time_for_failed_replicated_fetches_ms = 0) so node2 retries the fetch on the next queue tick after the partition heals. This is the same idiom used by test_postpone_failed_tasks's no_backoff_policy.xml. Quorum semantics and every assertion are unchanged.

Validation: reproduced deterministically with a partition held long enough to drive num_tries past the threshold. With the default backoff the 10s SYSTEM SYNC REPLICA times out; with max_postpone_time_for_failed_replicated_fetches_ms = 0 it completes within 10s.

Version info

  • Merged into: 26.7.1.146 (included in 26.7 and later)
  • Backported to: 26.6.2.101

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Standalone repro: partition node2 off node1/node3 on port 9009 with REJECT, insert quorum=2 parts, hold the partition ~75s so node2's GET_PART num_tries climbs (observed num_tries=10, num_postponed=37 even at 35s), heal, then time SYSTEM SYNC REPLICA(timeout=10). Backoff default -> SYNC times out; backoff=0 -> completes <10s.
b Root cause explained? Yes. While node2 is partitioned it still reaches ZooKeeper, creates GET_PART queue entries, and every fetch fails ("Connection refused"). Each failure increments num_tries; ReplicatedMergeTreeQueue::getPostponeTimeMsForEntry schedules the next attempt 1<<num_tries ms out (capped at max_postpone_time_for_failed_replicated_fetches_ms, default 60000). After ~14 tries the next retry is >10s out, so after the heal the final SYSTEM SYNC REPLICA waits out the backoff and the client times out. Sanitizer-only because the partition phase is slow enough there for num_tries to cross the threshold (100% of 30d failures on asan/tsan/msan).
c Fix matches root cause? Yes. Setting max_postpone_time_for_failed_replicated_fetches_ms = 0 makes getPostponeTimeMsForEntry return 0, so node2 retries the fetch on the next queue tick after the heal instead of waiting out an accumulated exponential backoff. Directly targets the mechanism in (b), not a symptom.
d Test intent preserved / new tests added? Yes. No assertion weakened, no data reduced, no no-* tag added. The setting only affects post-failure retry timing; quorum behavior and every COUNT/parts assertion are unchanged. Test continues to verify the same quorum semantics.
e Both directions demonstrated? Yes. Deterministic repro: with default backoff the 10s SYNC times out (bug reproduced); with max_postpone_time_for_failed_replicated_fetches_ms = 0 it completes <10s (fixed). The fixed test also passed end-to-end via the praktika integration runner.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test setting fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (flaky test setting fix, not a code bug). The pinned setting is a per-table MergeTree setting that already exists; no default or format change.
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug). Disabling fetch-failure backoff only removes a retry delay; replication correctness invariants are unaffected.

Session id: cron:clickhouse-worker-slot-1:20260625-005300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix — could you review? Test-only fix for the flaky test_parallel_quorum_actually_quorum: node2 is partitioned off the other replicas for the whole test, so its failing GET_PART entries accumulate exponential fetch backoff (1<<num_tries ms); after the partition heals the final SYSTEM SYNC REPLICA q (timeout=10) waits out that backoff and times out on the slow sanitizer shards. Pins max_postpone_time_for_failed_replicated_fetches_ms = 0 on the table (same idiom as test_postpone_failed_tasks), no assertion changed. You reviewed the sibling fix for this file in #103710.

@murphy-4o murphy-4o added the can be tested Allows running workflows for external contributors label Jun 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [13b91d5]

Summary: ✅


AI Review

Summary

This PR changes only tests/integration/test_quorum_inserts_parallel/test.py: the quorum integration test now disables replicated fetch backoff for table q and gives the final SYSTEM SYNC REPLICA q barrier a 60s client timeout. That matches the described sanitizer-only failure mode where node2 accumulates fetch retry backoff while partitioned, and the post-heal correctness assertion is still present. I did not find issues that warrant inline review comments.

Final Verdict

Status: ✅ Approve

No required actions.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 25, 2026
@murphy-4o murphy-4o self-assigned this Jun 25, 2026
test_parallel_quorum_actually_quorum partitions node2 off node1/node3 on
port 9009 for the whole test. While partitioned, node2's GET_PART queue
entries fail repeatedly and accumulate the ReplicatedMergeTree exponential
fetch backoff (1<<num_tries ms, capped at
max_postpone_time_for_failed_replicated_fetches_ms, default 60000). After
the partition heals, the final "SYSTEM SYNC REPLICA q" must wait out that
accumulated postpone before node2 re-fetches the 3 parts. Under the parallel
sanitizer flaky-check (--dist=each, many concurrent clusters under ASAN) the
backoff plus contention pushes the catch-up well past the barrier's tight
10s client-side timeout, so the test fails with "Client timed out!".

Two changes, neither weakens an assertion:
- Set max_postpone_time_for_failed_replicated_fetches_ms = 0 on the table so
  node2 retries fetches without the exponential postpone once it can reach
  its peers again (same idiom as test_lost_part / test_postpone_failed_tasks,
  which disable the analogous backoff settings for fault-window flakiness).
- Raise the final SYSTEM SYNC REPLICA barrier timeout from 10s to 60s (the
  common value used by other integration tests) to absorb residual parallel
  sanitizer slowness. Correctness is still gated by the retrying
  assert_eq_with_retry(node2, count, "3") that follows, so a genuine
  "node2 never syncs" regression still fails there.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the ci-fix-flaky-quorum branch from fde7e87 to 13b91d5 Compare June 25, 2026 08:03
@groeneai

Copy link
Copy Markdown
Collaborator Author

Updated the fix after the Integration tests (amd_asan_ubsan, flaky) check failed on the previous commit, which surfaced that disabling the fetch backoff alone was necessary but not sufficient.

Refined root cause: the failure is a client-side 10s timeout on the final SYSTEM SYNC REPLICA q (helpers/client.py -> Client timed out!). node2 is partitioned off node1/node3 (port 9009) for the whole test; once the partition heals it must fetch 3 parts. Disabling max_postpone_time_for_failed_replicated_fetches_ms removes the deterministic exponential-backoff stall, but under the flaky-check (--dist=each, many concurrent 3-node+ZK clusters under ASAN) the post-heal catch-up can still exceed a tight 10s barrier.

Change (neither weakens an assertion):

  • Keep max_postpone_time_for_failed_replicated_fetches_ms = 0 on the table (same idiom as test_lost_part / test_postpone_failed_tasks).
  • Raise the barrier SYSTEM SYNC REPLICA q timeout 10s -> 60s (the value 13 other integration tests already use) to absorb residual parallel-sanitizer slowness. Correctness is still gated by the retrying assert_eq_with_retry(node2, count, "3") that follows, so a genuine "node2 never syncs" regression fails there rather than being hidden.

Verified locally: test_parallel_quorum_actually_quorum passes via the integration runner (1 passed in 31.48s, including the SYNC barrier line).

@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 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: 457 line(s), 14 function(s) across 128 file(s) · Details

Top files
  • src/Storages/MergeTree/MergeTreeData.cpp: 77 line(s), 2 function(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 35 line(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 18 line(s)
  • src/Storages/Statistics/ConditionSelectivityEstimator.cpp: 11 line(s), 2 function(s)
  • src/Interpreters/DeltaMetadataLog.cpp: 11 line(s)

Full report

@alexey-milovidov
alexey-milovidov merged commit 64f23c1 into ClickHouse:master Jun 27, 2026
166 of 167 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 Jun 27, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 16, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 16, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 23, 2026
Backport #108433 to 26.6: Fix flaky test_parallel_quorum_actually_quorum
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Fix flaky test_parallel_quorum_actually_quorum
Blargian pushed a commit to Blargian/ClickHouse that referenced this pull request Sep 18, 2026
…ff the sync must wait out

test_different_credentials and test_credentials_and_no_credentials each run a
phase with mismatched interserver credentials on purpose, so the reader
replica's GET_PART for the writer's part is rejected 401 and enters the
failed-entry backoff. ReplicatedMergeTreeQueue::getPostponeTimeMsForEntry gates
re-execution for min(2^num_tries ms, <bound>) measured from
last_exception_time_ms, where <bound> is
max_postpone_time_for_failed_replicated_fetches_ms for GET_PART and
..._merges_ms for MERGE_PARTS, both defaulting to 60000 ms; the 2^num_tries term
saturates against the bound from num_tries = 16, and nothing but a queue reload
shortens it. Both tests then repair the credentials and call SYSTEM SYNC REPLICA
with no mode keyword, i.e. SyncReplicaMode::DEFAULT, which snapshots every queue
entry present at call time and waits for all of them, so the sync sits out
whatever remains of that window while the client-side kill timer runs.

Raising the client timeout cannot fix this, because the reachable window is the
bound itself. Driving the entry to num_tries = 16 on the unfixed test, I
measured a window of 59299 ms armed on it, 58705 ms still outstanding when the
sync started, and a 60000 ms client cap still losing: the fetch succeeded 0.03 s
after the client had been killed. So this sets both bounds to 0 on the table and
keeps the two client budgets aligned with the four other sync sites in this file
as a secondary guard. It is the same pairing that fixed
test_parallel_quorum_actually_quorum (ClickHouse#108433); test_lost_part sets both bounds
the same way, and tests/config/config.d/backoff_policy_25_4.xml zeroes them for
the whole stateless suite.

_fill_nodes builds the table for all four shards. That is neutral for the two
matched-credential shards: with no failed entry last_exception_time_ms stays 0,
so next_min_allowed_time_ms is already in the past and
getPostponeTimeMsForEntry returns 0 whatever the bound is.

With the bounds at 0 both sites pass at the old 10 s budget with the sync taking
0.115 s, and redden again with the original traceback when only the setting is
removed. On the shipped tree the two syncs drop from 32.859 s and 16.043 s to
0.017 s and 0.015 s, so both tests stop waiting out a recovery window they
previously sat through on every green run. No assertion changes, so genuinely
broken replication still fails.

The two syncs that keep a 10 s budget directly follow a TRUNCATE on the peer, so
they drain a DROP_RANGE and need no interserver fetch at all.

Recorded failures: 2 in 120 days, both on Integration tests
(amd_llvm_coverage, 7/8), none on master.

Co-Authored-By: Claude Opus 5 <[email protected]>
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-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.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants