Repository navigation
Conversation
Split request processing (batching, session management, request/response threads) into a separate `KeeperRequestDispatcher` class, leaving `KeeperDispatcher` as a thin shell for snapshots, session ID assignment, session cleanup, and cluster configuration management. Key interface changes: - `KeeperStateMachine` now takes a `KeeperResponseCallback` instead of a `ResponsesQueue &`, decoupling the state machine from the queue type. - `KeeperServer` constructor takes `KeeperResponseCallback` instead of `ResponsesQueue &`. - `KeeperServer::KeeperRaftServer` moved from .cpp anonymous definition to the header for visibility. - `ZooKeeperResponseCallback` moved to `KeeperCommon.h`, returns `bool` for future flow control. - `shutdown` now takes a `closed_all_connections` parameter. - Consolidated `finishSession` calls into a single `SCOPE_EXIT` in `KeeperTCPHandler`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…aming New pipelined request dispatcher (`KeeperRequestDispatcher2`) with: - Lock-free `NonblockingBoundedQueue` for request/response flow - `KeeperAppendStream` for ordered Raft entry appends with flow control - Parallel read request batching and execution - Response queue backpressure via `onResponseDeallocated` callback NuRaft submodule bumped for virtual `append_entries_in_bg`, streaming mode support, and `STREAM_FORWARDING_REQUEST` message type. New settings: `use_new_dispatcher`, `max_in_flight_request_batches`, `max_request_queue_bytes_size`, `max_response_queue_bytes_size`, `optimize_read_order`, `dispatch_busy_wait_sleep_us`, `stream_suspect_retry_delay_ms`, `stream_in_flight_drain_timeout_ms`, `max_read_batch_size`, `max_read_batch_bytes_size`, `asio_streaming_mode`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [94e8b68] Summary: ❌
AI ReviewSummaryThis PR replaces Keeper request dispatching with a new pipelined implementation (plus fallback old dispatcher), introduces new flow-control settings, and enables the new path by default. The current head still has unresolved correctness issues around response-stream contract and recovery gating, plus missing focused regression coverage for the new dispatcher invariants. Merge should wait for those fixes. Findings❌ Blockers
Tests
Missing context / blind spots
Final VerdictStatus: Minimum required actions:
|
Remove unused `ErrorCodes::BAD_ARGUMENTS`, `ErrorCodes::ABORTED` from `KeeperRequestDispatcher.cpp`, unused `ProfileEvents` from `KeeperDispatcher.cpp` and `KeeperStateMachine.cpp`. Fix typos in `KeeperRequestDispatcher2.cpp`, `KeeperRequestDispatcher2.h`, and `NonblockingBoundedQueue.h`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101757&sha=2bfce0838853d8ec99a83361334a7e0b4f40cd27&name_0=PR&name_1=Style+check Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…nd why does it take 2 hours to get this error
| DECLARE(UInt64, snapshot_transfer_chunk_size, 0, "Chunk size in bytes for snapshot transfer between Keeper nodes. Larger values reduce round-trips but increase per-message memory usage. 0 means disabled: the whole snapshot is sent as a single NuRaft object (compatibility behaviour).", 0) \ | ||
| DECLARE(UInt64, write_snapshot_version, 6, "Snapshot format version to write (supported: 6 and above). Increase only after all nodes in the cluster are upgraded to a version that supports the new format", 0) \ | ||
| DECLARE(Bool, nuraft_test_mode, false, "Nuraft test mode. not enabled for production use", 0) \ | ||
| DECLARE(Bool, use_new_dispatcher, false, "Use new request dispatcher implementation (KeeperRequestDispatcher2)", 0) \ |
There was a problem hiding this comment.
use_new_dispatcher introduces a second request-dispatching pipeline with substantially different concurrency/flow-control behavior, but this PR only adjusts existing tests for the constructor signature and does not add targeted coverage for the new path.
Could you add at least one Keeper test that enables use_new_dispatcher and exercises core invariants (session ordering with interleaved reads/writes and bounded queue behavior under backpressure)? Without this, regressions in the new pipeline are hard to catch before rollout.
There was a problem hiding this comment.
Re-checking current HEAD: I still don't see targeted coverage that exercises the use_new_dispatcher path.
The changes in src/Coordination/tests/* only adapt constructor wiring (response_callback), but there is still no focused test that enables the new dispatcher and validates the key contract surfaces (session ordering under mixed read/write and queue/backpressure behavior).
There was a problem hiding this comment.
Re-checking current HEAD: I still don't see focused coverage for the use_new_dispatcher path.
The changes in src/Coordination/tests/* mostly adapt constructor/callback wiring, and the integration test edits focus on shutdown/reconfig flakiness. I still don’t see a test that explicitly validates the new dispatcher’s key ordering contract under interleaved read/write requests and queue/backpressure pressure.
Please add at least one targeted Keeper test that exercises those invariants with use_new_dispatcher enabled.
There was a problem hiding this comment.
It's on by default now.
There was a problem hiding this comment.
Re-checking current HEAD: this thread is still live.
The tests added/changed in this PR (src/Coordination/tests/gtest_coordination*.cpp, tests/integration/test_keeper_session/test.py, tests/integration/test_keeper_reconfig_replace_leader/test.py) mostly adjust constructor wiring and shutdown/reconfig behavior. I still do not see a focused test that exercises the new dispatcher invariants directly (mixed read/write ordering per session and behavior under queue/backpressure pressure).
Since use_new_dispatcher is enabled by default in this PR, that missing focused coverage is still a release risk.
Cherry pick #101757 to 26.5: KeeperDispatcher overhaul
Backport #101757 to 26.5: KeeperDispatcher overhaul
Sync the non-private stabilization from ClickHouse/clickhouse-private#54962 for `test_keeper_reconfig_replace_leader_in_one_command`. Reset the `Keeper` state before each repeated run, close stale ZooKeeper connections, and treat retried `create` as success only when the existing znode contains the expected data. Refs: ClickHouse/clickhouse-private#54962 Refs: ClickHouse#101757
Adds a regex filter for the NuRaft shutdown-time message `RaftInstance: session N failed to read rpc header from socket ::1:PORT due to error E, ..., ref count R` to the upgrade-runner allow-list. The message comes from `rpc_session::start` in `contrib/NuRaft/src/asio_service.cxx` when the peer of an accepted RPC connection closes its socket before the acceptor cancels the pending read. In single-node Keeper the peer is a loopback `::1` client, so this fires routinely during shutdown. The already-allow-listed sibling `RaftInstance: failed to accept a rpc connection due to error 125` covers the inverse race (acceptor wins); this one covers the variant where the peer wins and the read returns EOF (or any other transient socket error). Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101757&sha=f6f0e80f9529c3ed3fa183d2a0cdf259824e8a58&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 PR: ClickHouse#101757 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
KeeperDispatcher overhaul
The test issues `CREATE NAMED COLLECTION zk_test` against the ClickHouse server (ZooKeeper session A) and then immediately calls `kazoo.get_children` on a separate kazoo client (ZooKeeper session B). The two sessions may be connected to different nodes of the ZK ensemble. Even though `ZooKeeper::createOrUpdate` on the server side is synchronous, the kazoo session can still see a stale view for a short window — normally sub-millisecond, but amplified under TSan and MSan slowdowns. The same race applies in the symmetric `DROP` case. Observed twice on master CI: - PR #101757 Integration tests (amd_tsan, 4/6) on 2026-05-16 - PR #102031 Integration tests (amd_msan, 6/6) on 2026-04-10 Both with `AssertionError: assert 'zk_test.sql' in []` at test.py:529. Fix: add `wait_zk_child_exists` and `wait_zk_child_absent` polling helpers (matching the existing `wait_exists` / `wait_not_exists` pattern, 10s timeout, 0.3s sleep) and use them in `test_zk_node_lifecycle` in place of the single-shot `get_children` membership checks. The assertions still verify the same invariant — ZK node appears after `CREATE`, disappears after `DROP` — just with bounded retry to tolerate cross-session replication lag. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102031&sha=169ea923b985fa66060e440b34cf2a908049afa4&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%206%2F6%29 Related PR: #102031
The test issues `CREATE NAMED COLLECTION zk_test` against the ClickHouse server (ZooKeeper session A) and then immediately calls `kazoo.get_children` on a separate kazoo client (ZooKeeper session B). The two sessions may be connected to different nodes of the ZK ensemble. Even though `ZooKeeper::createOrUpdate` on the server side is synchronous, the kazoo session can still see a stale view for a short window — normally sub-millisecond, but amplified under TSan and MSan slowdowns. The same race applies in the symmetric `DROP` case. Observed twice on master CI: - PR ClickHouse#101757 Integration tests (amd_tsan, 4/6) on 2026-05-16 - PR ClickHouse#102031 Integration tests (amd_msan, 6/6) on 2026-04-10 Both with `AssertionError: assert 'zk_test.sql' in []` at test.py:529. Fix: add `wait_zk_child_exists` and `wait_zk_child_absent` polling helpers (matching the existing `wait_exists` / `wait_not_exists` pattern, 10s timeout, 0.3s sleep) and use them in `test_zk_node_lifecycle` in place of the single-shot `get_children` membership checks. The assertions still verify the same invariant — ZK node appears after `CREATE`, disappears after `DROP` — just with bounded retry to tolerate cross-session replication lag. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102031&sha=169ea923b985fa66060e440b34cf2a908049afa4&name_0=PR&name_1=Integration%20tests%20%28amd_msan%2C%206%2F6%29 Related PR: ClickHouse#102031
`test_replication_without_zookeeper/test.py::test_startup_without_zookeeper` intermittently fails with `kazoo.exceptions.NotEmptyError` inside `drop_zk`, which calls `zk.delete(path="/clickhouse", recursive=True)`. The drop happens while `node1` (ClickHouse) is still running, so its `ReplicatedMergeTree` background threads keep re-creating ZooKeeper nodes under `/clickhouse`. kazoo's recursive delete races with that: between `get_children` and `delete` a new child node can appear, and kazoo raises `NotEmptyError` without retrying. The test already used `cluster.run_kazoo_commands_with_retries`, but with the default `repeats=1`. In that helper the retry loop is `for i in range(repeats - 1)`, so `repeats=1` performs zero retries — the callback runs exactly once with no exception handling. Pass `repeats=5` (matching the existing usages in `helpers/cluster.py`) so the drop is retried on the transient `NotEmptyError`. This is a pre-existing flaky test (same failure seen on unrelated PRs, e.g. ClickHouse#103540 and ClickHouse#101757), not a regression. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d40ea5d0da4103b54971ac01a9960ef9153242bb&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F6%29 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`test_replication_without_zookeeper/test.py::test_startup_without_zookeeper` intermittently fails with `kazoo.exceptions.NotEmptyError` inside `drop_zk`, which calls `zk.delete(path="/clickhouse", recursive=True)`. The drop happens while `node1` (ClickHouse) is still running, so its `ReplicatedMergeTree` background threads keep re-creating ZooKeeper nodes under `/clickhouse`. kazoo's recursive delete races with that: between `get_children` and `delete` a new child node can appear, and kazoo raises `NotEmptyError` without retrying. The test already used `cluster.run_kazoo_commands_with_retries`, but with the default `repeats=1`. In that helper the retry loop is `for i in range(repeats - 1)`, so `repeats=1` performs zero retries — the callback runs exactly once with no exception handling. Pass `repeats=5` (matching the existing usages in `helpers/cluster.py`) so the drop is retried on the transient `NotEmptyError`. This is a pre-existing flaky test (same failure seen on unrelated PRs, e.g. ClickHouse#103540 and ClickHouse#101757), not a regression. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d40ea5d0da4103b54971ac01a9960ef9153242bb&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F6%29 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The first two commits can be reviewed separately. First one refactors things to move the hot paths from KeeperDispatcher into a new class KeeperRequestDispatcher. Second one adds KeeperRequestDispatcher2.
I didn't benchmark it much yet. Preliminarily, it's ~30% faster (on the one workload I tried).
Explanation from the code:
(This is artisanally coded, then I asked Claude to review and split into two commits.)
Version info
26.6.1.10226.5.2.8