Repository navigation
Fix flaky test_keeper_session_loss_during_coordinated_refresh - #107413
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-4:20260613-165700 |
|
cc @al13n321 — could you review this? It de-flakes the coordinated-refresh keeper-loss test you added in #104051: instead of restarting the whole keeper cluster (whose slow/flapping quorum reformation on loaded runners makes node1's 6.25s crash-detection grace expire before node2 can re-register, so node1 starts a by-design duplicate), it isolates only node2 from keeper so node2 reconnects promptly within grace. node1 still takes the grace-period wait path, so the test still catches a regression of the #104051 coordination fix. |
|
Workflow [PR], commit [7c1b99d] Summary: ✅ AI ReviewSummaryThis PR stabilizes Missing context / blind spots
Final VerdictStatus: ✅ Approve No review blockers. The revised ordering removes the prior race, and the PR discussion provides focused local validation for this test-only CI flake fix; CI should provide the final runtime signal. |
The test puts replica B (node2) on a fake clock so it starts a coordinated refresh, makes node2 lose its keeper session so its 'running' ephemeral expires, then checks replica A (node1) does not start a duplicate refresh for the same timeslot (the guarantee added in ClickHouse#104051). It was flaky (8 PR failures / 30d, 0 on master across 4036 master runs). Two issues, both in the test's timing: 1. node1's crash-detection grace deadline is computed from currentTime(), which returns the frozen fake clock once SET FAKE TIME is applied. node1 enters the missing-'running'-ephemeral grace path purely from watching node2's znodes (the check runs before the stop_requested check, so STOP VIEW does not gate it). The old test dropped node2's keeper connection and only THEN set node1's fake clock. On a loaded runner node2's ephemeral could expire and node1 could record running_znode_missing_since on the REAL clock before that SET FAKE TIME; the subsequent jump to a fake time far in the future then put the grace deadline in the past, so node1 immediately declared node2 crashed, cleared the lock and ran a duplicate refresh. 2. node2's reconnect was timed with fixed sleeps relative to the partition, not to when node1 actually started its grace period, leaving a load- dependent margin before node1's ~6.25s deadline. Fix the test (the behavior under a genuinely long outage is by design): - Set node1's fake clock and START its view BEFORE partitioning node2, so node1 always records grace-start on the frozen fake clock and its deadline never arrives while node2 is briefly disconnected. - Cut only node2 off from keeper (PartitionManager) instead of restarting the whole keeper cluster, so keeper stays healthy for node1 and node2 reconnects promptly. - Chain node2's restore to node1's "no corresponding ephemeral znode" log line instead of a fixed sleep, so node2 reconnects ~1s after node1 starts the grace period regardless of runner load. - Use query_with_retry for SYSTEM SYNC REPLICA to tolerate a replica being briefly read-only right after re-establishing its keeper session. node1 still enters the grace-period wait while node2's ephemeral is missing, so the test still fails if the ClickHouse#104051 coordination fix is reverted. Verified locally: 14/14 runs pass with the change; a forcing variant that deliberately uses the old ordering deterministically reproduces node1 clearing the lock and refreshing, confirming the root cause. Co-Authored-By: Claude Opus 4.8 <[email protected]>
e33d7f8 to
7c1b99d
Compare
Pre-PR validation gate (updated for revised timing fix)
Session id: cron:clickhouse-worker-slot-2:20260613-195900 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 494 line(s), 23 function(s) across 138 file(s) · Details Top files
|
|
CI fully finished on HEAD
Genuinely waiting on @al13n321 review (the bot change request on the test timing was addressed in Session id: cron:our-pr-ci-monitor:20260613-233000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Stabilizes the flaky integration test
test_refreshable_mv_keeper_loss/test.py::test_keeper_session_loss_during_coordinated_refresh(added in #104051). Test-only change; no product behavior changes.
Related: #104051
Flakiness: 8 failures across 8 unrelated PRs in 30 days, 0 on master (4036 master runs). The two observed modes:
assert 2 == 1/ "Expected 1 row APPENDed for the timeslot, got 2" (3 of 4 recent).Code: 242 ... Table is in readonly modeduringSYSTEM SYNC REPLICA(1 of 4).Root cause (from CI server logs): the test restarted all three keeper nodes to expire the running replica's (node2) session so its
runningephemeral disappears, then made node1 want to refresh the same timeslot. On a loaded runner keeper quorum reforms slowly; node2's session expired three times over ~30s while quorum reformed. node1's crash-detection grace period is a hard-coded1.25x session_timeout(6.25s withsession_timeout_ms=5000), so node1 declared node2 crashed, cleared the coordination lock, and started a duplicate refresh before node2 could reconnect and re-register. That duplicate-after-extended-outage is by design, so the assertion is stronger than what the product guarantees under a long/flapping outage. The readonly mode is node1's target table being briefly read-only right after a keeper session re-establish.Fix (test-only):
PartitionManager.drop_instance_zk_connectionsinstead of restarting the whole cluster. Keeper stays healthy for node1, so its grace period ticks from a stable clock, and node2 reconnects promptly (~1s) after restore, well within grace. This is exactly the "brief keeper connection loss on the running replica" condition Refreshable MV: avoid duplicate refresh on brief keeper connection loss #104051 guards against. node1 still enters the grace-period wait while node2's ephemeral is missing, so the test still fails if the coordination fix is reverted (teeth preserved).query_with_retryforSYSTEM SYNC REPLICAto tolerate a replica being briefly read-only after re-establishing its session.Verification: 18/18 local runs pass with the change. Server logs confirm node1 takes the grace-period wait path ("refresh is running on replica '2', ... Waiting for 6250 ms ...") and node2 re-creates its ephemeral within grace, so exactly one refresh runs (no duplicate). The failing CI report this was found from: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=566bdf29bbc637b8e193a4a89be1417799fc6dc6&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29
Version info
26.6.1.790