Repository navigation
Fix flaky test_replication_credentials: two waits in front of SYSTEM SYNC REPLICA - #119897
PedroTadim merged 2 commits into
Conversation
…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]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold pass, over
Noted, not blocking: the four Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260914-071700 |
Pre-PR validation gate (click to expand)
Validation: whole module green 84/84 (one plain run plus two Session id: cron:clickhouse-impl-slot-5:20260914-063700 |
|
Workflow [PR], commit [e21da3a] Summary: ✅ AI ReviewSummaryThis PR hardens Final VerdictStatus: ✅ Approve |
| node5.query("SYSTEM RELOAD CONFIG") | ||
| node5.query("INSERT INTO test_table values('2017-06-21', 333, 1)") | ||
| node6.query("SYSTEM SYNC REPLICA test_table", timeout=10) | ||
| node6.query("SYSTEM SYNC REPLICA test_table", timeout=60) |
There was a problem hiding this comment.
@groeneai do you have to increase the timeout this much?
There was a problem hiding this comment.
Yes, though not for the reason my description gave, which I have now corrected.
The failing run never reached the backoff. node8's GET_PART for 201706_0_0_0 starts at 03:30:57.830, is rejected 401 in 2ms, and the attempt releases the entry only at 03:31:12.867, so it held it for 15.04s on that coverage build. The sync starts at 03:31:02.480 (Waiting for 1 entries to be processed: queue-0000000000) and the 10s client timer fires about 0.4s before the attempt ends. num_tries was 0 for the whole sync: node8's first put aside this log entry line is at 03:31:17.160, after the client was already killed. The settings in this PR cannot shorten an attempt that is already running, so the client budget itself has to outlast it, and 10s does not.
I cannot account for those 15s on that build. It is not HTTP retries (401 is in non_retriable_errors, so doWithRetries rethrows at try 1), and it does not reproduce on a local debug build, where the same rejected attempt ends in milliseconds. Whatever it is, the sync has to sit through it.
The two bounds at 0 are for the other wait, the one that starts once that attempt fails: min(2^num_tries ms, max_postpone_time_for_failed_replicated_fetches_ms) reaches the 60s default, and driving it locally I measured 58705ms still outstanding at sync start, which a 60s cap loses to by 0.03s.
On the magnitude itself: 60 is what the four other sync calls in this file already use, so it is not a new constant, and it costs nothing on a green run (with the bounds at 0 these two syncs return in 0.017s and 0.015s). If you would rather keep the ceiling small, 30s is still twice the longest attempt I have measured on that lane and I will push that instead.
There was a problem hiding this comment.
Done in e21da3a: this call and the node8 one in test_credentials_and_no_credentials are both at 30s now, and the four pre-existing 60s calls in this file are untouched.
30s is twice the 15.04s attempt, and that attempt was the outlier of the run rather than the build: node7 made 12 rejected fetches in the same window on the same binary, each releasing the queue entry within 0.1s (11 of them within 6ms). The module is green 44/44 at 30s (one plain run plus a --count 10), and with the two bounds dropped both sites still time out at 30s, so the setting is still carrying the other wait.
…on_credentials These two syncs have to outlast one interserver fetch attempt that is already in flight when the sync starts: in the failing coverage run node8's GET_PART for 201706_0_0_0 was rejected 401 in 2 ms yet held the queue entry for 15.04 s, and a plain SYSTEM SYNC REPLICA waits for every entry present at call time. So 10 s is structurally below the requirement, while 30 s is twice the longest attempt I have measured on that lane. The other wait, the failed-entry backoff that starts once that attempt fails, is covered by the two bounds set to 0 in _fill_nodes, so the client budget does not have to match the 60 s the four other sync calls in this file use. Reduced from the 60 s of the previous commit as requested in review. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Good to go |
Related: #113473
Related: #108433
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
test_different_credentialsandtest_credentials_and_no_credentialsmismatch the interserver credentials on purpose, so the reader'sGET_PARTis rejected 401. Each then repairs them and callsSYSTEM SYNC REPLICA, which with no mode keyword waits for every entry present at call time, including that stale one. Two waits can sit in front of it.First, an attempt already in flight, which is the one CI hit. In the failing run node8's
GET_PARTfor201706_0_0_0is rejected 401 in 2ms but releases the entry only 15.04s later, after the 10s client timer has already fired;num_trieswas 0 throughout that sync, so the backoff played no part in it. No table setting shortens an attempt already running, so only the client budget covers it: both syncs get 30s, twice that attempt.Second, the backoff once that attempt fails:
min(2^num_tries ms, max_postpone_time_for_failed_replicated_{fetches,merges}_ms)from the last exception, shortened only by a queue reload. Driving that window locally I measured 58705ms still outstanding at sync start and even a 60s cap losing by 0.03s, so no client budget covers this half; the bounds have to go to 0, as in #108433 fortest_parallel_quorum_actually_quorum.Setting them on all four shards is neutral: with no failed entry
last_exception_time_msstays 0 and the bound is never consulted.The two syncs keeping a 10s budget follow a
TRUNCATEbetween peers whose credentials match, so they drain aDROP_RANGEand no fetch can be rejected.Validation: the two syncs drop from 32.9s and 16.0s to 0.017s and 0.015s; at the 30s budget the module is green 44/44 across a plain run and a
--count 10, and removing only the setting reddens both sites with the original traceback. Recorded failures: 2 in 120 days, both onIntegration tests (amd_llvm_coverage, 7/8), none on master. Example report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119821&sha=96446fd4c17e3113a698f14b1414971327f4cf5e&name_0=PRnode8 log from the failing run (the 15.04s attempt the sync waited on)
That 15.04s is an outlier of that run, not general build slowness: node7 on the same
build made 12 rejected fetch attempts in the same window, each releasing the entry
within 0.1s (11 of them within 6ms).
Workflow [PR]
Sync PR [sync-upstream/pr/119897]