Skip to content

Check the setup of 05229 and 05230 before writing a replication log entry into ZooKeeper - #127123

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-05229-05230-check-setup-before-keeper-write
Oct 22, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-05229-05230-check-setup-before-keeper-write

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119189

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not required: test-only change.

Description

05230_merge_entry_for_local_part_missing_in_zookeeper aborted the server in Stress test (amd_msan) (report, STID 4362-110a) and in Stress test (arm_asan_ubsan) (report, STID 4362-43f8). Neither carrier PR is related.

Stress fault injection failed the test's first INSERT (Code: 241 ... fault injected), so no part was created and part_name came back empty. The test then wrote a merge entry with an empty into part into the table's log/ by hand. LogEntry::parse accepts it, both replicas copy it into their queues, and only after that ZooKeeper multi commits does ReplicatedMergeTreeQueue::insertUnlocked reject the name (BAD_DATA_PART_NAME). The exception lands in the catch-all where pullLogsToQueue calls std::terminate() on purpose, because its in-memory state no longer matches ZooKeeper, so the server aborts with signal 6. 05229 writes a get entry the same way.

Both tests now read the part with a query that returns a row only when r2 holds exactly one active part with all 100 rows, and stop with one line on stdout before any hand-written ZooKeeper write otherwise. That state is what the references already assert, so a normal run is unchanged.

Validation on a master debug build: one injected failing query (the INSERT in 05230, the part-name SELECT in 05229) makes the original tests abort the server with the CI stack every time, and makes the fixed tests exit with the new line while the server stays up. Each test passes 50/50 with randomized settings. 200 runs with memory_tracker_fault_probability=0.05 stopped at the check 13 times, with no abort.


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

Version info

  • Merged into: 26.11.1.583-master (included in 26.11 and later)

…oKeeper by hand

Under stress fault injection the first INSERT of 05230 failed (Code 241), so
no part was created and part_name came back empty. The test then wrote a merge
entry with an empty `into` part into the table's log/ by hand. LogEntry::parse
accepts it, both replicas copy it into their queues, and insertUnlocked rejects
it only after the ZooKeeper multi committed, inside the catch-all of
pullLogsToQueue that calls std::terminate(). 05229 writes a get entry the same
way; its fatal shape is a failed part-name SELECT (an empty part_type fails in
LogEntry::parse, before the multi, and only wedges the queues).

Read the part with a query that returns a row only when r2 holds exactly one
active part with all 100 rows, and exit before any hand-written ZooKeeper write
otherwise. The state is checked rather than the client's exit code because the
stress AST fuzzer and fault injection can change it while every query succeeds,
and the capture query itself can fail.

Stress test (amd_msan), STID 4362-110a:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110105&sha=b690c448969420c8c4fe3548cf0dfa4262c8c5cf&name_0=PR&name_1=Stress%20test%20%28amd_msan%29
Stress test (arm_asan_ubsan), STID 4362-43f8:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=112950&sha=9bc143e56853b7b122d17053abc6fa996ff22a93&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review of the diff (0 findings).

Checked: the guard precedes both hand-written ZooKeeper writes (rm and create); the captured part is the only active part on r2, so ActiveDataPartSet::add in insertUnlocked can neither get an empty name nor an intersecting one; the stress AST fuzzer runs server-side and does not change the captured output; no other stateless test writes a table's log/ by hand.

Session id: cron:clickhouse-review-slot-9:20261021-065700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One injected failing query in the original test (WHERE throwIf(number = 0) = 0 on the first INSERT of 05230; throwIf(1) in the part-name SELECT of 05229) aborts the server every time.
b Root cause explained? A failed setup leaves part_name empty, the hand-written log entry names no part, insertUnlocked rejects it after the ZooKeeper multi committed, and the catch-all in pullLogsToQueue calls std::terminate().
c Fix matches root cause? Yes. The tests check the state they built (one active part with all 100 rows on r2) right before the first hand-written ZooKeeper write. The check reads state rather than an exit code, because stress can change the state while every query succeeds.
d Test intent preserved / new tests added? Yes. The checked state is the one the references already assert; .reference files are unchanged and normal runs are identical.
e Both directions demonstrated? Yes. Original + injection: BAD_DATA_PART_NAME on both replicas, Terminate called, signal 6. Fixed + injection: exit 1 with the new line, server alive, no entry in log/.
f Fix is general across code paths? Yes. 05229 and 05230 are the only tests that write a table's log/ through keeper-client.
g Fix generalizes across inputs (params/datatypes/wrappers)? Covers no part, a failed capture query, two active parts and an empty part_type. Data types: N/A (test-only).
h Backward compatible? (maintainer-approved exception only) Yes, tests only.
i Invariants and contracts preserved? Yes. Replication metadata is written only from checked values, and the check precedes both the rm and the create. 50/50 randomized runs pass for each test; 200 runs with memory_tracker_fault_probability=0.05 stopped at the check 13 times without an abort.

Session id: cron:clickhouse-impl-slot-6:20261021-063600

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5809835]

Summary: ✅


AI Review

Summary

The PR checks that replica r2 has exactly one active part containing all 100 rows before tests 05229 and 05230 manually modify ZooKeeper. It also captures the part name and type together in 05229, preventing a failed second query from supplying an empty type. No actionable findings against commit 58098358e512b4f7cadba11fc2f36018d2d0ecd3.

Missing context / blind spots
  • ⚠️ Server tests were not rerun locally because this checkout has no runnable ClickHouse build. Runtime evidence comes from the PR's documented deterministic fault-injection reproductions and repeated randomized runs; completed targeted and stress CI runs would provide independent confirmation.
Final Verdict

Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix, could you review this and add the can be tested label so CI runs? When stress fault injection fails the setup INSERT, 05229 and 05230 hand-write a replication log entry that names no part, and both replicas then reach the std::terminate() in pullLogsToQueue; the tests now check the part they built before writing anything to ZooKeeper.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 21, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
@groeneai groeneai mentioned this pull request Oct 22, 2026
1 task done
@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 22, 2026
Merged via the queue into ClickHouse:master with commit 956abbe Oct 22, 2026
526 of 528 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@clickhouse-gh clickhouse-gh Bot added comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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 comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. pr-ci 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.

3 participants