Skip to content

Fix Keeper termination on get /keeper/availability_zone with quorum_reads=true - #104663

Merged
antonio2368 merged 4 commits into
ClickHouse:masterfrom
myeongjjun:keeper-fix-az-get-skip-leftover
May 12, 2026
Merged

antonio2368 merged 4 commits into
ClickHouse:masterfrom
myeongjjun:keeper-fix-az-get-skip-leftover

Conversation

@myeongjjun

@myeongjjun myeongjjun commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem. When ClickHouse Keeper runs with <quorum_reads>true</quorum_reads> and <placement> absent, get /keeper/availability_zone reaches processImpl<false> via the raft commit path, fails the container.find lookup, and triggers onStorageInconsistency → std::terminate. The request is already in the raft log, so every restart replays it and the Keeper terminates again — raft-log poisoning that leaves the Keeper cluster stuck in a restart crash loop.

Fix. Drop keeper_availability_zone_path from the preprocess early-return list in both Get and ListRecursive. The regular uncommitted_state.getNode check now runs and emits a ZNONODE ErrorDelta when the AZ node is not in the container.

Why. The early-return skip was correct only while AZ was served by a dedicated processImpl branch and never lived in storage.container. Commit 06ff714 moved AZ into system_nodes_with_data behind if (!keeper_az.empty()) and removed that branch, but the preprocess skip was left behind. With <placement> absent the node is never registered. The skip prevents preprocess from producing the ZNONODE ErrorDelta that would have short-circuited commit, so the request flows on to container.find and trips the fail-fast branch. ListRecursive was introduced with the same skip line in PR #100998. Removing the skip makes the quorum_reads=true response match the quorum_reads=false response (processLocalRequests → processImpl<true>'s graceful ZNONODE).

tests/integration/test_keeper_availability_zone_quorum_reads/ covers unconfigured + configured AZ under quorum_reads=true, plus the local-read path.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix Keeper termination and restart loop when get /keeper/availability_zone is sent with quorum_reads=true to a Keeper without <placement> configured.

Version info

  • Merged into: 26.5.1.561
  • Backported to: 26.4.3.29, 26.3.11.27, 26.2.19.37, 25.8.24.20

…_reads=true

The skip for `keeper_availability_zone_path` in `Get` and `ListRecursive`
`preprocess` returned early without producing a `ZNONODE` delta for an
unconfigured AZ, so `processImpl<false>` then called
`onStorageInconsistency` and the request poisoned the raft log on
restart. Drop the skip; the regular `uncommitted_state.getNode` path
returns `ZNONODE` when AZ is unconfigured and keeps returning the node
with stat when it is configured.
@antonio2368 antonio2368 self-assigned this May 12, 2026
@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label May 12, 2026
@antonio2368

Copy link
Copy Markdown
Member

Changes make sense. Can you tell me why are you running Keeper with quorum reads?

@clickhouse-gh

clickhouse-gh Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8fa0424]

Summary: ✅
Keeper Stress Tests (PR): Grafana: Run details (this run), Grafana: 1vs1 Comparison, Grafana: Historical progression


AI Review

Summary

This PR removes the /keeper/availability_zone early-return skip from Get/ListRecursive preprocess and adds integration coverage for configured/unconfigured AZ reads. One quorum-read inconsistency still remains in ListRecursive for /keeper/config, and the new tests do not yet prove the restart replay path described in the PR contract.

Findings

❌ Blockers

  • [src/Coordination/KeeperStorage.cpp:2454-2457, 2481-2487] ListRecursive still bypasses uncommitted_state.getNode for keeper_config_path, but ListRecursive::processImpl has no dedicated /keeper/config branch. With quorum_reads=true, ListRecursive /keeper/config can still reach onStorageInconsistency on a missing container node, causing Keeper termination via the same failure pattern this PR fixes for /keeper/availability_zone.
    Suggested fix: for ListRecursive, remove keeper_config_path from this early-return skip list (or add explicit /keeper/config handling in processImpl) so the request returns a normal response/error instead of terminating Keeper.
Tests
  • ⚠️ [tests/integration/test_keeper_availability_zone_quorum_reads/test.py:70] The new regression checks immediate liveness after get, but does not restart Keeper and replay the committed entry. Since the PR contract explicitly includes fixing the restart-loop behavior, add a focused restart step (restart instance, reconnect, repeat get /keeper/availability_zone) to prove replay no longer re-triggers termination.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Prevent ListRecursive /keeper/config from reaching onStorageInconsistency under quorum_reads=true (either by removing the preprocess skip for keeper_config_path or by adding explicit processImpl handling).
  2. Add restart/replay regression coverage for the poisoned-log scenario described in the PR.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels May 12, 2026
if (zk_request.path == Coordination::keeper_api_feature_flags_path
|| zk_request.path == Coordination::keeper_config_path
|| zk_request.path == Coordination::keeper_availability_zone_path)
|| zk_request.path == Coordination::keeper_config_path)

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.

ListRecursive still skips preprocess for keeper_config_path, but unlike Get there is no dedicated /keeper/config branch in processImpl.

With quorum_reads=true, ListRecursive /keeper/config goes through the RAFT commit path, misses container.find in processImpl<false>, and then reaches onStorageInconsistency (the same termination pattern this PR fixes for /keeper/availability_zone).

Can we either remove keeper_config_path from this skip list for ListRecursive, or add explicit /keeper/config handling in ListRecursive::processImpl so it returns a normal response/error instead of terminating Keeper?

assert "node doesn't exist" in error
assert "/keeper/availability_zone" in error

# The keeper should still be alive — no SIGABRT, no raft-log poisoning.

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.

This validates the immediate post-request behavior, but the PR description also claims replay after restart is fixed (no RAFT-log poisoning loop).

Could we add one restart step after _assert_znonode (or in a dedicated test): restart the same keeper instance, wait for reconnection, and run get("/keeper/availability_zone") again? That would directly prove the replay path no longer triggers termination.

@myeongjjun

Copy link
Copy Markdown
Contributor Author

Changes make sense. Can you tell me why are you running Keeper with quorum reads?

@antonio2368
Honestly, quorum_reads=true wasn't enabled for a specific hard requirement — we kept it enabled as a conservative operational choice.

For context, after a Keeper HA event, ClickHouse → Keeper connections don't automatically rebalance; they stay pinned to whichever Keeper node they failed over to. We were testing an AZ-aware Keeper configuration so that each ClickHouse would prefer a same-AZ Keeper. During that rollout, we hit this bug.

@clickhouse-gh

clickhouse-gh Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.60% +0.10%

Changed lines: 80.00% (8/10) | lost baseline coverage: 8 line(s) · Uncovered code

Full report · Diff report

@antonio2368
antonio2368 added this pull request to the merge queue May 12, 2026
Merged via the queue into ClickHouse:master with commit ad8631f May 12, 2026
165 of 166 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels May 12, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 12, 2026
Cherry pick #104663 to 26.4: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
robot-clickhouse added a commit that referenced this pull request May 12, 2026
@myeongjjun
myeongjjun deleted the keeper-fix-az-get-skip-leftover branch May 13, 2026 04:23
@myeongjjun
myeongjjun restored the keeper-fix-az-get-skip-leftover branch May 13, 2026 04:28
antonio2368 added a commit that referenced this pull request May 18, 2026
Backport #104663 to 26.4: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
robot-clickhouse-ci-1 added a commit that referenced this pull request May 18, 2026
Cherry pick #104663 to 25.8: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
robot-clickhouse added a commit that referenced this pull request May 18, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 18, 2026
Cherry pick #104663 to 26.2: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
robot-clickhouse added a commit that referenced this pull request May 18, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 18, 2026
Cherry pick #104663 to 26.3: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
robot-clickhouse added a commit that referenced this pull request May 18, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 18, 2026
antonio2368 added a commit that referenced this pull request May 19, 2026
Backport #104663 to 26.2: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
antonio2368 added a commit that referenced this pull request May 19, 2026
Backport #104663 to 25.8: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
antonio2368 added a commit that referenced this pull request May 19, 2026
Backport #104663 to 26.3: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…eeper/availability_zone` with `quorum_reads=true`
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…4663

Backport ClickHouse#104663 to 26.4: Fix Keeper termination on get `/keeper/availability_zone` with `quorum_reads=true`
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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