Skip to content

Handle a ZooKeeper Multi request without subrequests in Keeper - #119847

Merged
antonio2368 merged 12 commits into
masterfrom
sec-keeper-empty-multi
Sep 17, 2026
Merged

antonio2368 merged 12 commits into
masterfrom
sec-keeper-empty-multi

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

A ZooKeeper Multi request whose subrequest list contains nothing but the terminator record parsed successfully and was preprocessed successfully: the loop over zero subrequests appended neither SubDeltaEnd nor FailedMultiDelta and returned ZOK, which is enough for the entry to be written to the changelog and replicated to followers. At commit time process read deltas.front() on that empty delta range - guarded only by a chassert, which is compiled out in the release build - and the process terminated on the raft commit thread. The entry was already durable by then, so every restart replayed it and terminated again.

process no longer relies on the chassert: an empty delta range now returns the empty (successful) multi response instead of being dereferenced, which is also the answer ZooKeeper gives such a request. The request is deliberately not refused while it is parsed - a client that builds a transaction from a list that turns out to be empty sends exactly this request (kazoo does not special-case it), and refusing it there would answer that client by closing its session. processWatches, right next to process, already handled the empty range the same way.

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):

Fixed ClickHouse Keeper terminating when a client sent a multi request with no subrequests. Such a request was written to the changelog before it failed, so the termination repeated on every restart.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.49 (included in 26.10 and later)
  • Backported to: 26.9.1.1602, 26.7.11.13, 26.3.33.105

`ZooKeeperMultiRequest::readImpl` accepted a `Multi` request whose subrequest
list contained nothing but the terminator record. `preprocess` then iterated over
zero subrequests, so it appended neither `SubDeltaEnd` nor `FailedMultiDelta` and
returned `ZOK`, which is enough for the entry to be written to the changelog and
replicated. At commit time `process` read `deltas.front()` on that empty range,
guarded only by a `chassert` that is compiled out in the release build, and the
process terminated on the raft commit thread. Because the entry was already
durable, every restart replayed it and terminated again.

The request is now rejected while it is parsed, before it can reach the
changelog. `process` no longer relies on the `chassert` either: an entry written
by an older version is still replayed on startup, so the empty range returns the
empty (successful) multi response instead of dereferencing it.

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

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5185243]

Summary: ✅


AI Review

Summary

This PR fixes Keeper's handling of a ZooKeeper Multi request with zero subrequests by treating the empty delta range as the legitimate empty-transaction case, and it hardens the multi-delta walk so malformed marker layouts fail closed instead of relying on debug-only assertions or undefined iterator behavior. The integration test exercises the pinned kazoo empty-transaction path and verifies that the request no longer poisons restart replay.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 5185243.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 22/27 (81.48%) · Uncovered code

Full report · Diff report

@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 Sep 13, 2026
ZooKeeper answers such a request with an empty successful response, and a client
that builds a transaction from a list that turns out to be empty sends exactly
that - `kazoo`, for one, does not special-case it. Refusing the request while it
is parsed would answer that client by closing its session, so keep the handling
of the empty delta range in `process` as the fix (`processWatches` next to it
already handles the same range) and let the request through.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Coordination/KeeperStorageImpl.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... label Sep 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 518524383 with master f51fa728a (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, 14 s compile time in total, 7 of them have a recent master baseline.

Job report

alexey-milovidov and others added 3 commits September 14, 2026 02:09
Address review: the success return of the empty-deltas branch in
`process` for `ZooKeeperMultiRequest` is reserved for the true
zero-subrequest case. A request with subrequests but without the
`SubDeltaEnd` / `FailedMultiDelta` markers goes through
`onStorageInconsistency` instead of a debug-only `chassert`, so a release
build does not answer it with an empty success that silently drops every
suboperation.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Address review: TCP does not preserve message boundaries, so a one-shot
`recv` may return a partial connect response, length prefix, or `multi`
body. Add `recv_exactly` and `recv_frame` helpers and use them for both
the handshake and the `multi` reply.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Coordination/KeeperStorageImpl.cpp Resolved
…rker

`extractSubdeltas` searched for the `SubDeltaEnd` marker of the next
subrequest and, when the marker was missing, incremented the end iterator
of the range, which is undefined behavior on the raft commit and replay
threads. The `deltas.empty()` guard in `process` for
`ZooKeeperMultiRequest` covered only a range without any markers at all.

Now `extractSubdeltas` routes a missing marker to `onStorageInconsistency`,
and `process` checks that the range is fully consumed after the last
subrequest, so deltas after the last marker are not silently ignored.

Addresses the AI review finding on
#119847

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The three red stress jobs on d433b1f are unrelated to this Keeper-only change (the diff touches KeeperStorageImpl.cpp and a Keeper integration test); all three are fleet-wide failures that also hit master and other PRs in the last days:

I will merge master into this branch once those fixes land, so the reds clear on the next CI run.

@groeneai

Copy link
Copy Markdown
Collaborator

That amd_asan_ubsan failure is mine, and the fix is already open: #119387.

Same signature as #119899. The null lives in the SelectQueryInfo that replaceReadingFromTable builds when a deserialized query plan reads a Merge table through a table that forwards its read, so the sampling probe at StorageMerge.cpp:1121 dereferences an AST that was never built. The fuzzer is not needed to reach it: with serialize_query_plan = 1, a plain read of a Merge table behind an Alias, a Buffer with a destination or a MATERIALIZED VIEW ... TO reproduces it deterministically, and that is the PR's test.

One caveat for merging master into this branch: this red clears only once #119387 lands, not on a rerun. That PR has been open and unreviewed since I pushed the reshaped predicate (73ada5c) on 2026-09-12 in answer to your comment on the first shape.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai. Recorded: the amd_asan_ubsan stress red (UBSan null query_info.query in ReadFromMerge::createChildrenPlans, tracked in #119899) is fixed by #119387, which awaits review.

None of the three fixes (#119387, #119700, #119715) has landed on master yet, so I am not merging master into this branch now: it would re-run the same unrelated reds. This PR itself is Keeper-only, has 0 unresolved threads and an approving AI review, and is ready for a human review and merge as is.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The three Stress test failures are STID 2467-2c2d, the materialized-CTE assertion family, and not this change: the same signature is on master (Stress test (arm_asan_ubsan), 2026-09-12, no pull request attached) and on unrelated pull requests in the last week - #118853, #118967, #117612, #119715 and #119514. The Keeper-specific jobs, including Keeper Stress Tests, are green.

raise


def test_empty_multi_request(started_cluster):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not use kazoo if it supports it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🕵 It does: kazoo serializes a transaction without operations as exactly the terminator record, and it deserializes the empty response into an empty list. Switched the test to zk.transaction().commit() and dropped the raw-socket frame helpers in de8b439; the test passes locally.

…`test_keeper_empty_multi`

kazoo serializes a transaction without operations as exactly the
terminator record, so `zk.transaction().commit()` is the empty `Multi`
request that the test hand-built over a raw socket. The test now uses it
and asserts the empty list of results, and drops the frame helpers.

#119847 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Coordination/KeeperStorageImpl.cpp Resolved
…in `process` for `Multi`

The failure marker of a failed `Multi` request is the only delta the rollback in
`preprocess` leaves for the transaction. `process` used to trust that and answer
with the failure response even if the range held more deltas, which would have
dropped them silently on the commit and replay path. Now such a range goes through
`onStorageInconsistency`, like the trailing deltas after the last subrequest.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Coordination/KeeperStorageImpl.cpp Resolved
… of a `Multi` request

`extractSubdeltas` looked only for the `SubDeltaEnd` marker, so a misplaced
`FailedMultiDelta` later in the transaction was handed to `commit` as an
ordinary delta of a subrequest. `commit` ignores that variant and returns
`ZOK`, so a malformed delta stream such as `[UpdateNodeDataDelta, SubDeltaEnd,
FailedMultiDelta, SubDeltaEnd]` was replayed as a fully successful `Multi`
instead of failing closed like every other mismatch between a request and
its deltas.

The walk now stops on both markers and routes a failure marker inside a
subrequest slice to `onStorageInconsistency`. The legitimate shape - the
failure marker as the sole delta of the transaction - is still handled by
the callers before they reach the walk.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@antonio2368
antonio2368 added this pull request to the merge queue Sep 17, 2026
Merged via the queue into master with commit c5423c4 Sep 17, 2026
178 checks passed
@antonio2368
antonio2368 deleted the sec-keeper-empty-multi branch September 17, 2026 18:46
@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 17, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #119847 to 26.9: Handle a ZooKeeper `Multi` request without subrequests in Keeper
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #119847 to 26.7: Handle a ZooKeeper `Multi` request without subrequests in Keeper
antonio2368 added a commit that referenced this pull request Sep 18, 2026
Resolve the Keeper storage refactoring conflict by porting the empty `Multi` request handling and delta-integrity checks into `KeeperStorage.cpp`.

PR: https://github.com/ClickHouse/ClickHouse/pull/120666\nOriginal pull-request: #119847
robot-ch-test-poll3 added a commit that referenced this pull request Sep 18, 2026
Cherry pick #119847 to 26.3: Handle a ZooKeeper `Multi` request without subrequests in Keeper
robot-clickhouse added a commit that referenced this pull request Sep 18, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Sep 18, 2026
Cherry pick #119847 to 26.6: Handle a ZooKeeper `Multi` request without subrequests in Keeper
robot-clickhouse added a commit that referenced this pull request Sep 18, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 18, 2026
antonio2368 added a commit that referenced this pull request Sep 18, 2026
Backport #119847 to 26.8: Handle a ZooKeeper `Multi` request without subrequests in Keeper
clickhouse-gh Bot added a commit that referenced this pull request Sep 18, 2026
Backport #119847 to 26.6: Handle a ZooKeeper `Multi` request without subrequests in Keeper
alexey-milovidov added a commit that referenced this pull request Sep 18, 2026
Backport #119847 to 26.3: Handle a ZooKeeper `Multi` request without subrequests in Keeper
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Sep 21, 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-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.

6 participants