Repository navigation
Fix flaky test_replication_credentials replication race - #113473
PedroTadim merged 1 commit into
Conversation
test_same_credentials and test_no_credentials insert into one replica
and then assert the table contents on the other, with a fixed
time.sleep(1) as the only barrier.
ReplicatedMergeTreeSink commits the part's /log/log-N znode in the same
multi-op transaction that commits the part, so when the INSERT returns
the log entry is durably in ZooKeeper. The other replica, however,
learns of it only asynchronously: its queue_updating_task pulls the
log, a background pool task executes the resulting GET_PART, and the
part is fetched over the interserver HTTP endpoint and committed. None
of that chain is bounded by anything the test controls, so on a loaded
sanitizer runner it routinely exceeds one second and the assertion
reads a stale replica:
AssertionError: assert '111\n' == '111\n222\n'
That reached master at cfc1fd2. Over
the last 90 days CIDB has 7 occurrences of the lag signature - an
AssertionError at one of the four reads that query the replica which
did not receive the insert - across 4 distinct refs, spanning both
tests. Over the same 90 days CIDB records 220751 OK and 13 FAIL
results for these two tests, so the lag accounts for 7 of the 13
failures: a genuine low-rate race rather than a broken check.
Replace the barrier instead of the timing constant: before each
cross-replica assertion, the replica about to be read runs SYSTEM SYNC
REPLICA test_table with an explicit timeout. waitForProcessingQueue
first calls pullLogsToQueue(..., SYNC), so a pending GET_PART is
guaranteed visible before the wait set is computed, then triggers the
background assignee, then addSubscriber snapshots the queue's entry
ids under state_mutex while registering the callback, so the wait
cannot miss the entry it must wait for and returns as soon as the
fetch lands. That turns an unbounded asynchronous wait into a
deterministic barrier at no fixed cost. The file already uses this
idiom at four other places. Raising the sleep was rejected: it treats
the symptom and re-races on a slower runner.
Scope is deliberately two tests and four lines. In
test_different_credentials and test_credentials_and_no_credentials the
sleep guards a negative assertion across intentionally mismatched
interserver credentials, where replication must not happen; a sync
there can never complete and fails with QueryTimeoutExceedException,
which was measured rather than assumed. All eight assertions are left
byte-identical, so the change only strengthens the barrier.
Validated with the fetch stalled deliberately on the reading replica:
the assertion fails before this change with the exact CI signature and
passes after it on the same binary, and reverting only the new barrier
reddens it again. 200/200 green over 50 repeats of the whole file.
Internal second-model review - 2 cold rounds, 1 gate finding, 6 self-found; 6 corrections applied, 1 refuted with evidenceThis change was reviewed cold twice by independent models with no access to the
On #7: three arms were run on one binary, differing only in the test file, with the The gate's other half - that the sync might be a silent no-op - is settled at source Also checked and found correct, so recorded rather than re-litigated: all eight Session id: cron:clickhouse-review-slot-48:20260805-113700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-48:20260805-113700 |
|
cc @tavplubix, could you review this? Two tests in |
|
Workflow [PR], commit [0e2550f] Summary: ✅ AI ReviewSummaryThis PR replaces four fixed Final Verdict✅ Approve. No blocking findings. |
CI finish ledger — 0e2550fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260805-170000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Made
test_replication_credentials::test_same_credentialsand::test_no_credentialsdeterministic by waiting onSYSTEM SYNC REPLICAinstead of a fixedtime.sleep(1)before each cross-replica read.Description
test_same_credentialsandtest_no_credentialsinsert into one replica and thenassert the table contents on the other, with a fixed
time.sleep(1)as the onlybarrier. When the INSERT returns its
/log/log-Nznode is durably in ZooKeeper,but the other replica only learns of it asynchronously: it pulls the log, schedules
a background task, then fetches and commits the part over interserver HTTP. Nothing
in that chain is bounded by the test, so on a loaded runner it exceeds 1 s and the
assertion reads a stale replica:
AssertionError: assert '111\n' == '111\n222\n'. That has reached master(sha
cfc1fd2512eb276fe020907434207a08fbaa5e0b,report),
plus 6 more across 3 unrelated PRs in 90 days, counting only an
AssertionErroratone of the four reads querying the replica that did not receive the insert.
This replaces the barrier rather than the timing constant: the replica about to be
read runs
SYSTEM SYNC REPLICA test_tablewith an explicittimeout=60. That isthe engine's own catch-up signal: it pulls the log synchronously, forces scheduling,
and snapshots the pending entry ids atomically with registering its callback, so it
cannot miss the entry it waits for and returns as soon as the fetch lands. The file
already uses this idiom four times.
All 8 assertions are byte-identical; only the barrier changed. Scope is
deliberately 2 tests, 4 lines: in
test_different_credentialsandtest_credentials_and_no_credentialsthe sleep guards a negative assertion acrossintentionally mismatched credentials, where a sync can never complete: measured, it
fails with
QueryTimeoutExceedException.Validation: with the fetch stalled deliberately, the assertion fails before the
change with the exact CI signature and passes after it on the same binary;
reverting the barrier reddens it. 200/200 over 50 repeats.
Other failures in this file are pre-existing and separate: a ZooKeeper-container
start failure, a MemorySanitizer report, a SIGSEGV, and a
Sanitizer assertfromcluster.shutdown().Version info
26.8.1.855(included in26.8and later)