Skip to content

Route old-leader reads through Raft in the Keeper compat snapshot test - #113992

Merged
antonio2368 merged 3 commits into
ClickHouse:masterfrom
groeneai:keeper-compat-quorum-reads
Aug 19, 2026
Merged

antonio2368 merged 3 commits into
ClickHouse:masterfrom
groeneai:keeper-compat-quorum-reads

Conversation

@groeneai

@groeneai groeneai commented Aug 8, 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

test_keeper_snapshot_chunked_transfer/test.py::test_recover_from_snapshot_sent_by_old_leader can
hang for the full 900 s pytest-timeout and take its whole integration shard with it.

The stall is not in the code under test. It is on compat1 / compat_s3_1, pinned to the released
25.3 and 25.12 images. Those versions park a read that arrives while a write batch is assembling
in read_request_queue[<last write's session_id>][<that write's xid>], which can belong to a
different session, and finishSession erases that whole session entry without responding. So when a
writer session expires, a co-batched read from another session is dropped silently and the client
waits on it forever.

Master fixed that in 5eb8dd3 ("Keeper: fix race between read requests and session close"),
which also added tests/integration/test_keeper_read_during_close. Neither image has it, so nothing
needs fixing in src/.

In both pinned versions the only read_request_queue insertion is guarded by !quorum_reads, and the
branch above it routes the read through the write path when that setting is on. This PR sets it on
those two instances only, making the dropping path unreachable for every read they serve. The
followers under test and the quorum fillers keep the default local reads.

Bumping the images instead does not work: the earliest release carrying that commit is 26.4, which
is also the earliest release shipping snapshot_transfer_chunk_size, so it stops being a leader
without chunking and the test's n_chunks == 1 premise disappears.

The test also asserts the effective setting read back from both servers via the 4LW conf command, so
a later edit that drops the fragment fails there instead of silently restoring the hang. No existing
assertion is weakened.

Not addressed: helpers/kazoo_client.py calls AsyncResult.get() with no timeout, so a future lost
response would still burn 900 s. That unbounded wait is what lets test_keeper_read_during_close
detect a stuck reader, and 61 files reach it through get_fake_zk.

Validation

Config: quorum_reads present on exactly compat1 + compat_s3_1, absent on the other four, and
the merged effective config (4LW conf) still carries operation_timeout_ms, session_timeout_ms,
snapshot_distance, stale_log_gap, reserved_log_items on both, so the fragment adds a setting
rather than replacing the generated block.

Mechanism, oracle = 4LW lgif last_log_idx (a quorum read is appended to the Raft log, a local
read is not). 40 reads per node:

arm compat1 (25.3) compat_s3_1 (25.12) compat3 (current build)
with fragment +40 +40 +0
fragment set to false +0 +0 +0

A one-write control advances the index by 1 on every node in both arms, so the oracle is not
vacuous. (Processing requests batch is not usable here: LOG_TRACE in 25.3 but LOG_TEST in
25.12.)

Runs: both parametrizations 20/20 over 10 repeats; test_keeper_read_during_close,
test_keeper_snapshot_chunked_transfer/test_concurrent.py and
test_keeper_snapshot_rotation_race/test.py all pass unchanged.

Cost: [local_disk] 38.4 s -> 39.8 s, [remote_disk] 32.2 s -> 36.7 s, module 119.9 s -> 126.5 s.

Version info

  • Backported to: 26.7.14.13

test_recover_from_snapshot_sent_by_old_leader could hang for the full 900 s
pytest-timeout and take its whole integration shard with it. The stall is not in
the code under test: it is on compat1 / compat_s3_1, the instances pinned to the
released 25.3 and 25.12 images.

Those versions park a read that arrives while a write batch is assembling in
read_request_queue[<last write's session_id>][<that write's xid>], which can
belong to a different session, and finishSession erases the whole session entry
without sending any response (addErrorResponses never consults the queue). So
when a writer session expires, a co-batched read from another session is dropped
silently, and the test's client waits on it forever because
KazooClientWithImplicitRetries calls AsyncResult.get() with no timeout.

That Keeper bug was fixed on master by 5eb8dd3 ("Keeper: fix race
between read requests and session close"), which also added
tests/integration/test_keeper_read_during_close. Neither pinned image has it:
25.3 is 890 commits behind that commit, and 25.12's KeeperDispatcher.cpp still
erases without responding. There is nothing to fix in src/.

In both pinned versions the only read_request_queue insertion is guarded by
!quorum_reads, and the branch above it sends the read through the write path
instead when that setting is on. Setting quorum_reads on those two instances
therefore makes the dropping path unreachable for every read they serve, from
every call site, without having to enumerate the call sites. The followers under
test (compat3, compat_s3_3) and the two quorum-filler instances keep the default
local reads so CI still exercises the default path.

No assertion is changed, skipped or weakened.

Validated with the 4LW lgif last_log_idx as the oracle, since a quorum read is
appended to the Raft log and a local read is not: 40 reads per node advance the
index by 40 on both pinned nodes with the fragment and by 0 without it, while a
one-write control advances it by 1 on every node in both arms. The
"Processing requests batch" log line is not usable for this, being LOG_TRACE in
25.3 but LOG_TEST in 25.12. The merged effective config keeps every generated
coordination setting, and the setting is present on exactly those two instances.

Not addressed here: helpers/kazoo_client.py still waits without a timeout, so a
future lost response would again burn 900 s. That unbounded wait is what lets
test_keeper_read_during_close detect a stuck reader, and the helper is shared by
61 test files.
The previous commit made the compat test depend on quorum_reads being enabled
on the pinned old leaders, but nothing in the repository asserted that. Three of
the four ways the setting can stop being applied are loud (a missing fragment
file raises in cluster.py, a non-merging fragment reverts snapshot_distance and
fails the snapshot assertion, an unknown setting name stops the server), but the
fourth is silent: dropping "configs/quorum_reads.xml" from main_configs leaves
both parametrizations passing while the 900 s hang returns.

Read the value back from the running servers with the 'conf' four-letter-word
command and assert it: true on the pinned old leader, false on the follower
under test, which must keep the default local-read path. A future edit that
drops the fragment now fails on this assertion instead of silently restoring the
flake.

Verified in both directions: removing the fragment from compat1 fails with
"assert 'false' == 'true'", and adding it to compat3 fails with
"assert 'true' == 'false'". Both parametrizations pass with the tree as
committed.
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, 0 open blockers)

An independent model reviewed this change cold against the diff and the pinned-version sources,
separately from the session that wrote it. One major was raised and fixed in a second commit;
one half of its suggested remedy was rejected with measurements. Verdicts below.

Finding Verdict
⚠️ The setting's presence was not asserted anywhere in-tree, so a future edit dropping configs/quorum_reads.xml from main_configs would pass CI silently and restore the 900 s hang AGREE, fixed in a231046
💡 Also assert that N reads advance 4LW lgif's last_log_idx by exactly N DISAGREE (would itself flake)

AGREE, fixed. Three of the four ways the setting can stop applying are already loud: a missing
fragment file raises in cluster.py, a fragment that replaced rather than merged the generated
block reverts snapshot_distance and fails the existing snapshot assertion, and an unknown setting
name stops the server. The fourth is silent. The test now reads the effective value back from each
server with the 4LW conf command and asserts true on the pinned old leader and false on the
follower under test. Both directions were mutated and both redden: dropping the fragment from
compat1 fails with assert 'false' == 'true', adding it to compat3 fails with
assert 'true' == 'false', and each mutation reddens exactly one of the two asserts, so they are
two independent oracles. Restoring the tree passes both parametrizations.

DISAGREE, with evidence. An exact-equality log-index delta is not deterministic in this
ensemble. sessionCleanerTask pushes an OpNum::Close entry per expiring session
(25.3 KeeperDispatcher.cpp:685-700), and this test opens at least three client sessions against
the old leader (two get_fake_zk calls plus one inside cleanup_test_tree), so unrelated appends
land in the measured window and the assertion has a real interleaving that fails with the fix
perfectly in place. The out-of-band lgif A/B quoted in the description could use exact equality
only because it ran on a quiesced cluster with one scripted session. An >= N variant was also
rejected: it adds a second timing-sensitive assertion and buys nothing over conf, which is
deterministic and is in the default four_letter_word_allow_list on both pinned versions.

Also checked and found sound, independently of the authoring session: the read_request_queue
carrier set is closed rather than sampled (8 references per pinned tree, single insertion, guarded
by !quorum_reads); 5eb8dd3be12cff3 is an ancestor of master and 26.4+ only; the new 4LW
calls cannot perturb the test, since a four-letter command is dispatched before any session is
established; quorum_reads appears exactly once in each pinned conf dump at roughly byte 860 of
about 1320, three orders of magnitude inside the single recv, and the same command is parsed on
master by test_keeper_four_word_command::test_cmd_conf at a much later position with no failures
recorded in 30 days; and exactly one integration module both pins a released image and configures
keeper_server, so there is no sibling to fix.

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? No, and not claimed. The 900 s hang is a race inside a pinned released binary; there is no on-demand repro. What is deterministic is the path the fix removes: 40 reads on each pinned node advance the Raft log by 40 with the fragment and by 0 without it (4LW lgif last_log_idx), on command, every time.
b Root cause explained? Yes. In 25.3 and 25.12, KeeperDispatcher parks a read arriving during batch assembly in read_request_queue[<last write's session_id>][<that write's xid>], which can be another session's, and finishSession erases the session entry without sending a response (addErrorResponses never consults the queue). A writer session expiring therefore drops a co-batched read silently. Matches the observed timeline: read sent, Found dead session 3 ms later, then 900 s of silence.
c Fix matches root cause? Yes. The sole read_request_queue insertion is guarded by !quorum_reads in both pinned versions, so setting quorum_reads on exactly those instances makes the dropping path unreachable. Not a timeout bump, retry, widened bound or skip.
d Test intent preserved / new tests added? Yes. No existing assertion touched: verify_test_tree still compares all 300 nodes on both servers, and n_chunks == 1, assert_obj_ids, assert_receiving_snapshot_logged are unchanged. Nothing in the diff can make a failing snapshot transfer pass. Assertions were added: the test now reads the effective quorum_reads back from both servers via the conf four-letter-word command and requires true on the pinned old leader and false on the node under test, so a future edit that drops the config fragment fails loudly instead of silently restoring the hang. No source behavior changed, so no source regression test applies.
e Both directions demonstrated? Yes, twice over. Mechanism: with the fragment the pinned nodes append 40 reads to the Raft log, with it set to false they append 0, while a one-write control advances the index by 1 on every node in both arms, so the oracle is not vacuous. New assertions: removing the fragment from the pinned leader fails with assert 'false' == 'true', adding it to the node under test fails with assert 'true' == 'false', and the tree as committed passes both parametrizations. Each mutation reddens exactly one of the two asserts.
f Fix is general across code paths? Yes, and that is the reason for this approach: the lever is a server setting, so it covers every read from every call site (verify_test_tree's 600, ensure_path's opening exists_async, cleanup_test_tree's ~272 get_children) without enumerating them. Both pinned families are covered, not just the one that failed: 25.12 was verified to still carry the bug, and 2 of 4 recorded failures are [remote_disk].
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A in the type-wrapper sense: no data path changed. The relevant matrix is instance x version and it is fully enumerated: 2 pinned-and-read get the setting, 2 pinned quorum-filler are left alone (verified they receive no client reads), 2 current-build nodes under test stay on the default. Both parametrizations assert presence on the leader and absence on the node under test, so the matrix is checked at run time on every run rather than only by inspection.
h Backward compatible? N/A. Tests only: no setting default changed, so no SettingsChangesHistory.cpp; no serialization or format change; no experimental gate.
i Invariants and contracts preserved? Yes. quorum_reads changes how a read is served, not what it returns, and the 20/20 repeat runs assert full 300-node tree equality on every iteration, which is exactly the contract that would break otherwise. The merged effective config still carries every generated coordination setting, and wait_until_connected / get_leader / conf / mntr / lgif parsing in keeper_utils all work unchanged on the modified nodes.

Session id: cron:clickhouse-impl-slot-4:20260808-223300

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368, could you review this? A Keeper compat integration test can hang for the full 900 s pytest-timeout because its old leader is pinned to a released 25.3 / 25.12 image that predates 5eb8dd3, so an expiring writer session silently drops another session's batched read; this sets quorum_reads on those two pinned instances only, which makes that queue insertion unreachable, and asserts the effective value via the conf four-letter-word command so the fragment cannot be dropped silently.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [62aa7f3]

Summary: ✅


AI Review

Summary

This PR makes the compat Keeper snapshot-transfer test avoid a known hang in the pinned 25.3 and 25.12 images by enabling quorum_reads on the two old-leader nodes and asserting the effective setting before the first old-leader read. I checked the current diff, the full prior discussion, the existing review thread, the surrounding Keeper test/helpers, and the current CI report; I did not find a remaining correctness, contract, or coverage issue in the updated change.

Final Verdict

✅ No blocking findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 9, 2026
The effective-setting assertion was placed after the snapshot transfer, but
cleanup_test_tree and fill_test_tree already read from the old leader before
that point (zk.exists and ensure_path's exists_async). If a later edit dropped
configs/quorum_reads.xml from main_configs, one of those earlier reads could hit
the lost-response race in the pinned image and burn the full 900 s pytest
timeout before the assertion ran, so the guard did not reject the regression
deterministically.

Move both assertions ahead of cleanup_test_tree, gated on a 4LW-only readiness
wait (wait_complete_readiness=False, as in test_keeper_disks) because the
complete-readiness probe issues a kazoo read itself.

Measured with the fragment dropped from compat1: the test now fails on the
assertion in 57 s having issued zero Keeper requests, where previously it failed
in 87 s after 6 Exists and 2 GetData requests against the old leader.
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 62aa7f3

CI is fully finished and green: 0 failing checks (PR, Mergeable Check and
Finish Workflow all SUCCESS). No failure needs an owner.

Session id: cron:our-pr-ci-monitor:20260809-220000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI here is green (0 failures on 62aa7f35), and this came up again today on the 26.6
backport #114972, where it was suggested as the fix for a cancelled integration shard. It is
not that fix (that cancel is a whole-runner stall), but the compat read-drop this does remove
is real, and the backport automation only scans merged PRs, so this needs to land before any
release branch can pick it up.

@antonio2368 could you take a look when you have a moment? Test-only change, two files.

@antonio2368
antonio2368 added this pull request to the merge queue Aug 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 19, 2026
@antonio2368
antonio2368 added this pull request to the merge queue Aug 19, 2026
Merged via the queue into ClickHouse:master with commit c71e0ab Aug 19, 2026
181 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 Aug 19, 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 Sep 22, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 22, 2026
Backport #113992 to 26.7: Route old-leader reads through Raft in the Keeper compat snapshot test
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.7-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants