Skip to content

keeper: change request queue push timeout - #121559

Merged
kssenii merged 1 commit into
masterfrom
zk-push-request-3x-session-timeout
Sep 23, 2026
Merged

kssenii merged 1 commit into
masterfrom
zk-push-request-3x-session-timeout

Conversation

@kssenii

@kssenii kssenii commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Do not drop the ClickHouse Keeper session when the client's outgoing request queue stays full for longer than operation_timeout_ms. The enqueue wait is now three times session_timeout_ms, so a short burst of backpressure no longer terminates the session and invalidates all its ephemeral nodes and watches.


Workflow [PR]
Sync PR [sync-upstream/pr/121559]

Version info

  • Merged into: 26.10.1.512-master (included in 26.10 and later)
  • Backported to: 26.9.2.22, 26.8.11.25, 26.7.14.41

`ZooKeeper::pushRequest` used `operation_timeout_ms` as the timeout for
pushing into `requests_queue`. But a failed push is not a failed
operation: the surrounding `catch` calls `finalize`, which tears down the
whole session. Losing the session because the queue stayed full for one
operation timeout is far too aggressive.

Wait `3 * session_timeout_ms` instead. By the time that elapses the
session is dead anyway, so nothing is lost by being patient.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [81aed47]

Summary: ✅


AI Review

Summary

This PR changes ZooKeeper::pushRequest to wait up to 3 * session_timeout_ms instead of operation_timeout_ms when the outgoing request queue is full, with the goal of avoiding unnecessary Keeper session expiration during short queue backpressure. I do not think the change is correct as written: queue saturation still flows into finalize, so a healthy but overloaded session can still lose all ephemeral nodes and watches once the longer timeout elapses.

Findings

⚠️ Majors

  • [src/Common/ZooKeeper/ZooKeeperImpl.cpp:1791] requests_queue saturation is still handled as a session-level failure. A steady producer backlog can keep the 1024-slot queue full for longer than 3 * session_timeout_ms while sendThread and receiveThread continue making progress, and in that case this path still throws and the catch still calls finalize. The original failure mode therefore remains: local backpressure can invalidate a healthy Keeper session and drop all ephemeral nodes and watches. The fix should decouple enqueue timeout from session teardown instead of only increasing the timeout.
Tests
  • ⚠️ Add a focused regression test that keeps the client request queue full past operation_timeout_ms while the session continues receiving responses, and verify that only the enqueuing request fails instead of expiring the whole session.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: stop treating local queue-enqueue timeout as proof that the Keeper session is dead, then add a regression test that covers queue saturation without session loss.

LLVM Coverage Report

Measured on commit 81aed47.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 6/9 (66.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 22, 2026
@antonio2368 antonio2368 self-assigned this Sep 22, 2026
/// A failed push kills the session (the `catch` below calls `finalize`), so be patient here.
const UInt64 push_timeout_ms = 3 * static_cast<UInt64>(args.session_timeout_ms);

if (!requests_queue.tryPush(std::move(info), push_timeout_ms))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requests_queue saturation is still treated as a session failure here. A healthy session can keep making send/receive progress while producers outpace the single sender for longer than 3 * session_timeout_ms; when that happens tryPush times out, the catch below still calls finalize, and we tear down ephemeral nodes and watches even though the Keeper session is alive. If the goal is to stop queue backpressure from invalidating the session, this timeout needs to fail just the enqueuing request (for example by bypassing the finalize path for this ZOPERATIONTIMEOUT), not just wait longer before expiring the whole session.

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 81aed47db with master d5e7a4509 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... label Sep 22, 2026
@kssenii
kssenii added this pull request to the merge queue Sep 23, 2026
@kssenii kssenii added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 23, 2026
Merged via the queue into master with commit 015b310 Sep 23, 2026
176 checks passed
@kssenii
kssenii deleted the zk-push-request-3x-session-timeout branch September 23, 2026 12:05
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 23, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 23, 2026
Backport #121559 to 26.9: keeper: change request queue push timeout
clickhouse-gh Bot added a commit that referenced this pull request Sep 23, 2026
Backport #121559 to 26.8: keeper: change request queue push timeout
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
antonio2368 added a commit that referenced this pull request Sep 25, 2026
Backport #121559 to 26.7: keeper: change request queue push timeout
@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 28, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants