Skip to content

Promote a failed multi's aggregate error for in-process Keeper callers - #117135

Merged
serxa merged 7 commits into
masterfrom
keeper-failed-multi-aggregate-error
Sep 9, 2026
Merged

serxa merged 7 commits into
masterfrom
keeper-failed-multi-aggregate-error

Conversation

@serxa

@serxa serxa commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

On a failed multi transaction the aggregate error is left ZOK and the real error is carried only in the failing subresponse — the ZooKeeper wire convention. A client that receives the response over the network reconstructs the aggregate from the per-operation errors in ZooKeeperMultiResponse::readImpl. A caller that obtains the response in-process through KeeperOverDispatcher never goes through that deserialization, so it saw ZOK for a rolled-back transaction and treated the failed multi as successful.

KeeperOverDispatcher::multi now applies the same normalization as the TCP client (promoteMultiResponseError) before invoking the callback. The wire format is untouched — writeImpl serializes per-operation errors, not the aggregate — so this only affects in-process callers. Covered by a gtest that drives the adapter's multi callback on a failed batch and asserts the aggregate error is promoted.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed an in-process Keeper client (KeeperOverDispatcher) reporting a failed multi transaction as successful, because a rolled-back batch's aggregate error was left ZOK.


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

On a failed multi-write, KeeperStorage left the transaction's aggregate error
ZOK and reported the real error only in the failing subresponse. This matches
the ZooKeeper wire convention (the aggregate is not serialized; a client
reconstructs it from per-operation errors in ZooKeeperMultiResponse::readImpl).
An in-process caller reading the response object directly (via
KeeperOverDispatcher) never goes through that path, so it saw ZOK for a
rolled-back transaction and treated the failed multi as successful.

Set the aggregate to the failing operation's error, matching TestKeeper and the
wire client's readImpl. Transparent to the wire protocol (writeImpl serializes
per-operation errors, not the aggregate).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bc056a2]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR moves failed-multi aggregate-error normalization to the client side and reuses the same helper in both ZooKeeperMultiResponse::readImpl and KeeperOverDispatcher::multi, which fixes the in-process success-on-failure bug without changing the wire format. I did not find a remaining correctness, compatibility, or coverage issue in the current patch.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit bc056a2.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.10% 81.10% +0.00%

Changed lines: Changed C/C++ lines covered: 40/43 (93.02%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 30, 2026
@serxa

serxa commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/33302311291/job/99239742949 and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Not a separate bug: the 32 Fast test failures are this diff, so the fix belongs in this PR.

Setting the aggregate error makes the multi response header non-ZOK, and both ends of the protocol treat a non-ZOK header as "no body", so the per-operation errors are never transmitted:

  1. ZooKeeperResponse::write serializes the body only for a ZOK error, src/Common/ZooKeeper/ZooKeeperCommon.cpp:42-43 (if (error == Error::ZOK) writeImpl(out);). With global_error set, ZooKeeperMultiResponse::writeImpl is skipped entirely.
  2. The client mirrors it: src/Common/ZooKeeper/ZooKeeperImpl.cpp:1262-1268 assigns response->error = err and never calls readImpl. So responses keeps the placeholders the ZooKeeperMultiResponse constructor pre-allocated (ZooKeeperCommon.h:820-826), every one with error == ZOK.
  3. zkutil::getFailedOpIndex then has a user-error aggregate and no failing sub-response, and throws LOGICAL_ERROR: There is no failed OpResult, src/Common/ZooKeeper/ZooKeeper.cpp:2009-2023.

536 lines of clickhouse-server.err.log for that run carry it. Frame breakdown:

  • 394 via KeeperMultiException::check (ZooKeeper.cpp:2052 -> 2035), of which 313 from DDLWorker.cpp:1147 and 66 from DatabaseReplicatedWorker.cpp:412. That is where the ON CLUSTER timeouts come from (02911_row_policy_on_cluster, 03408_current_database_on_cluster_constraint, 01297_create_quota, 02179_dict_reload_on_cluster): the DDL queue entry never completes.
  • 55 via the check_session_valid branch of multiImpl (ZooKeeper.cpp:991), 54 of them from StorageReplicatedMergeTree.cpp:2439.
  • 87 via EphemeralLockInZooKeeper.cpp:84 and the ReplicatedMergeTreeSink commit path, which covers the insert-deduplication set.

All of these reach Keeper over TCP (tests/config/config.d/zookeeper.xml points at 127.0.0.1:9181), so they take the serialization path. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117135&sha=7e181862367217f2fa229e39f328c3538509ca3c&name_0=PR&name_1=Fast%20test

The ZOK aggregate on a rolled-back multi is what the protocol prescribes rather than an oversight, see the comment and the promotion at ZooKeeperCommon.cpp:1370-1374. KeeperStorage builds the same response object that gets serialized, so setting the aggregate there changes behaviour for every client, not only the in-process one.

The gap you are after is one layer up: KeeperOverDispatcher::multi at src/Common/ZooKeeper/KeeperOverDispatcher.cpp:302-312 hands the storage response to the callback unchanged, so it is the only consumer that never gets the promotion ZooKeeperMultiResponse::readImpl performs. Applying the same rule there (first sub-error other than ZRUNTIMEINCONSISTENCY becomes the aggregate) would fix the in-process caller and leave the wire format alone. The new gtest passes because it calls processRequest directly and never goes through ZooKeeperResponse::write.

Nothing to link: CIDB has no occurrence of There is no failed OpResult on any other branch or check in the last 30 days.

A failed multi transaction carries its real error in the failing subresponse while
the aggregate error is left ZOK (the ZooKeeper wire convention). The TCP client
derives the aggregate from the subresponses in ZooKeeperMultiResponse::readImpl. A
response obtained in-process through KeeperOverDispatcher never goes through that
deserialization, so the aggregate stayed ZOK and a caller reading the response object
directly treated a rolled-back transaction as successful.

KeeperOverDispatcher::multi now applies the same normalization (promoteMultiResponseError)
before invoking the callback. The wire format is untouched (writeImpl serializes
per-operation errors, not the aggregate), so this only affects in-process callers.

This supersedes the earlier source-level attempt: stamping the aggregate in
KeeperStorage made ZooKeeperResponse::write drop the multi body over the wire (the
body is serialized only when the header error is ZOK), breaking every wire client on
a failed multi.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@serxa serxa changed the title Report the failing operation's error as a failed multi's aggregate error Promote a failed multi's aggregate error for in-process Keeper callers Sep 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fdd5f8c47 with master d8aa6cab7 (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

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

Job report

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@serxa
serxa marked this pull request as ready for review September 1, 2026 12:16
serxa and others added 2 commits September 1, 2026 12:23
readImpl derived a failed multi's aggregate error from the subresponses inline;
extract that into the shared promoteMultiResponseError so the wire path and the
in-process KeeperOverDispatcher path use one implementation instead of duplicated
logic. readImpl runs only for a ZOK header, so calling the helper after the read
loop is equivalent to the previous inline promotion.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Not new, and not your diff. It is the trunk ALTER TABLE ... MODIFY ORDER BY direction bug; what changed between runs is the STID label, not the failure.

The abort is chassert(key_order.compareTuples(left_keys, right_keys, used_key_size) <= 0) at src/Storages/MergeTree/KeyCondition.cpp:5033, reached from ReadFromMergeTree::selectRangesToRead -> filterPartsByPrimaryKeyAndSkipIndexes -> markRangesFromPKRange. That path does not touch Keeper, and all 7 files changed at 6d4b2cde are under src/Common/ZooKeeper/ and src/Coordination/.

From server.log of that job, for the table in the failing query:

13:04:40.250  CREATE TABLE t_lwu_key_prefix__fuzz_1 (`a` Nullable(UInt64), `v` String NULL)
              ENGINE = MergeTree PRIMARY KEY a ORDER BY a DESC SETTINGS ..., patch_parts_version = 'v2'
13:04:41.553  INSERT INTO t_lwu_key_prefix__fuzz_1 SELECT number, 'foo' FROM numbers(1000)
13:05:15.830  ALTER TABLE t_lwu_key_prefix__fuzz_1 (ADD COLUMN `b` LowCardinality(UInt64)), (MODIFY ORDER BY (a, b))
13:05:29.419  UPDATE t_lwu_key_prefix__fuzz_1 SET v = 'baz' WHERE a != 900      [abort]

That ALTER landed: the next fuzzed variant of it fails with DUPLICATE_COLUMN on b. MODIFY ORDER BY replaces reverse_flags wholesale (KeyDescription::recalculateWithNewAST is *this = getKeyFromAST(...)), the primary key copies the new flags (KeyDescription.cpp:238), and MergeTreeData::checkProperties compares sorting key column names and types only, with no mention of direction. So the DESC is dropped silently while the 1000 inserted rows stay physically descending; KeyCondition builds its KeyOrder from the new ascending metadata, and markRangesFromPKRange hands it boundary tuples read from the old descending index, so left > right.

Neither the fuzzer nor patch parts are needed. The 5-statement reproducer and the fix that rejects such an ALTER are in #116473 (mine, open, not reviewed yet). In a release build there is no abort: index analysis just prunes the wrong granules and the query returns missing rows.

Why it read as new: the STID bucket is not stable across runs. In CIDB over 30 days, test_name LIKE '%key_order.compareTuples%' AND test_status IN ('FAIL','ERROR') gives 11 hits on 10 unrelated pull requests, starting 2026-08-16, spread over three labels (2508-5166 9 hits, 2508-33cb 1, 2508-5811 1).

Document the failed-multi aggregate convention once at promoteMultiResponseError
and keep both call sites terse (the wire path and the in-process KeeperOverDispatcher
path share one implementation, so the 'must stay in sync' framing no longer applies).
Move the readImpl call to right after the per-operation read loop, where the
subresponse errors are complete (the footer block only validates the trailing marker).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pufit pufit self-assigned this Sep 1, 2026
@serxa

serxa commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

@groeneai, two new untracked failures on the current run (sha fdd5f8c, run https://github.com/ClickHouse/ClickHouse/actions/runs/33512116655):

  1. BuzzHouse (amd_msan) — STID 3782-2f00, "Received signal -1": https://github.com/ClickHouse/ClickHouse/actions/runs/33512116655/job/99932592064
  2. Docs examples — Documentation examples: https://github.com/ClickHouse/ClickHouse/actions/runs/33512116655/job/99932592006

Please investigate and provide fixes in separate PRs. If either is already in progress, link it here.

(AST fuzzer failures STID 2508-5166 / 3413-350b are the same pre-existing MODIFY ORDER BY direction bug from #116473 — not re-reported.)

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Both already have fix PRs, and neither comes from your diff (which is confined to src/Common/ZooKeeper/ and src/Coordination/tests/).

1. BuzzHouse (amd_msan), STID 3782-2f00. Fix in progress: #107091 (mine, open), issue #106736.

Terminate called for uncaught exception:
Code: 771. DB::Exception: Filesystem cache disk IO error (errno 2): DB::ErrnoException: Failpoint: simulated cache disk IO failure

MergeTreeData::loadOutdatedDataParts (frame at MergeTreeData.cpp:3593) has a function-level catch (...) that logs Will terminate to avoid undefined behaviour due to inconsistent set of parts and then calls std::terminate unconditionally, so a transient error takes the server down. Code 771 is CACHE_CANNOT_WRITE_TO_CACHE_DISK, thrown as a plain DB::Exception from CachedOnDiskReadBufferFromFile, and isRetryableException in checkDataPart.cpp already classifies it as retryable. #107091 turns that terminate into a reschedule when the exception is retryable and the loader is async, which is the path in this stack (BackgroundSchedulePool into the loadDataParts lambda at MergeTreeData.cpp:3209).

Pre-existing: 14 hits on 12 unrelated PRs plus one true-master run since 2026-07-24.

2. Docs examples. Already fixed and merged: #117459, today at 13:55:50Z.

Function/toYYYYMM#0    SELECT toYYYYMM(now(), 'US/Eastern')
documented: 202608
actual:     202609

The documented output was pinned to August, so the example went red at the month rollover: 2026-09-01 04:00 UTC is midnight in US/Eastern. Across all Docs examples runs there were 0 failures in the 03:00 UTC hour and 9 in the 04:00 hour, after which it failed on every PR and on 6 true-master runs until the fix landed. #117459 replaces now() with a fixed timestamp.

Your run was triggered at 13:13:34Z, 42 minutes before that merge, and fdd5f8c4 still carries the old example (merge base 9904bd27, 2026-08-30), so a master merge clears it.

@clickhouse-gh clickhouse-gh Bot added the comp-keeper ClickHouse Keeper (Raft-based coordination layer; ZooKeeper replacement) and ZooKeeper client lib... label Sep 4, 2026
@serxa
serxa added this pull request to the merge queue Sep 9, 2026
Merged via the queue into master with commit dce1cc3 Sep 9, 2026
342 of 346 checks passed
@serxa
serxa deleted the keeper-failed-multi-aggregate-error branch September 9, 2026 09:50
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 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-bugfix Pull request with bugfix, not backported by default 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