Skip to content

test(cluster): add a docker chaos harness for multi-node edge cases - #4474

Closed
almostintuitive wants to merge 2 commits into
apache:masterfrom
aperiodic-io:test/cluster-chaos-harness
Closed

almostintuitive wants to merge 2 commits into
apache:masterfrom
aperiodic-io:test/cluster-chaos-harness

Conversation

@almostintuitive

Copy link
Copy Markdown
Contributor

Which issue does this PR address?

Relates to #4438
Relates to #4436

Also reproduces the data loss reported in this #4433 comment. The failing tests for #4438 and #4436 are in #4439 and #4437.

Rationale

#4438, #4436 and the #4433 regression only showed up with real server processes crashing, restarting from disk or losing the network while producers write, and checking afterwards that every acknowledged message can be read back. Each one was found with a throwaway script. This puts that tooling in the repository, so a maintainer can rerun a failure case on one machine with one command, and check a fix against it.

What changed?

scripts/cluster-chaos starts a 3-node cluster in Docker from a published apache/iggy image (default edge). Each node has a fixed IP and its data in a named volume, so kill then start is a real crash and a recovery from disk. run-scenario.sh <scenario> creates a topic, produces while it injects the faults of that scenario, heals every node, reads the whole topic back and writes a verdict and a result JSON. Nothing builds the server.

The checker is a new binary in core/tools (cluster-chaos-checker, next to data-seeder-tool) on the in-repo SDK, so it speaks the same protocol as a server built from the same commit. produce logs every event before its first send and again once a send carrying it is acknowledged, and retries a failed send with the same events. verify reads every partition from offset 0 in rounds, because right after a recovery an empty poll or the end that GetTopic lists does not prove the end of the log. A scenario fails on acknowledged events lost, offset gaps, per-key reordering, a key in two partitions, events nobody sent, a listed tail that no read returns, reads that never settle, producers giving up, or a panic or fatal shard error in a node log. Upstream has no server-side deduplication, so duplicates from retries are reported, not failed. Also reported but not failed: polls that came back empty at an offset that held data, and GetTopic as each node answers it next to what was read.

Scenario Faults Reproduces
baseline, control none (control resends 20% of events and must see every copy) checks the checker
crash-restart SIGKILL each node in turn, restart from disk data loss with #4433 applied
rolling-restart, isolate, pause, kill-storm graceful restarts, network cut, freeze, rapid kills
cascading-crash a second node dies during the view change of the first replicated loss below
full-outage, full-outage-replicated all three nodes killed at once replicated loss is by design
rolling-crash 1 partition, 30k msg/s, persisted, one kill every 80 s, 40 s down #4438
split-primaries crash-restart, then a clean produce phase with a p99 limit #4436

k8s/kind-cluster.sh implements the same backend commands on a local kind cluster, with one release of helm/charts/iggy per node in cluster mode (the chart's examples/cluster-3-node.yaml). A kill there is kubectl delete pod --force with the Deployment scaled to zero. The README covers every scenario, the expected and the buggy outcome, and how to read the results.

Local Execution

  • Passed. All against apache/iggy:edge (revision 2c1f70b53, two commits behind this branch's base, neither touching the server, SDK or protocol), with the checker built from this branch. Nodes at 1 CPU and 2 GiB, 2000 msg/s from 6 producers on 6 partitions for 120 s unless noted:
  • Kubernetes: not run against a cluster. The kind backend was checked with helm template for all three releases (with examples/cluster-3-node.yaml) and kubeconform -strict against Kubernetes 1.35 (12 resources valid), plus shellcheck.
  • The checker: cargo fmt and cargo clippy -p tools --all-targets --all-features -- -D warnings clean. docker build -f scripts/cluster-chaos/Dockerfile . built the image; the final image was built with the same cargo build --release --locked -p tools --bin cluster-chaos-checker in a container capped at 2 CPUs.
  • Pre-commit hooks ran (pre-commit run --files <changed>): markdownlint, shellcheck, license headers, version consistency, trailing whitespace and newline, binary artifacts, typos, skills and taplo passed. cargo fmt and clippy ran separately as above. cargo sort was not installed, so I checked the core/tools/Cargo.toml order by hand.

AI Usage

  1. Claude (Claude Code).
  2. Most of the code and text, adapted from scripts I used to find Partition replica stuck after rolling crash-restarts: state transfer never completes while it keeps serving its stale prefix #4438, Rust SDK: sends to a multi-partition topic bounce between nodes once partition primaries diverge (multi-second stalls) #4436 and the fix(partitions): don't commit a stale prepare after adopting a newer view #4433 regression.
  3. By running the scenarios above against the published image and checking that the checker fails when it must (control must see every resent copy; the replicated outage scenarios lost acknowledged events and were reported). Before opening, I ran a review in the spirit of team-review-slim with two reviewers (checker correctness and data-loss logic; shell, kind and docs) and fixed what applied: failed polls no longer count as a quiet read round, a non-advancing poll cannot loop forever, the partition check also covers duplicate copies, the content check compares every field, logs of an earlier run are never overwritten, fault steps no longer abort a run and node logs are saved before teardown, the kind script is executable and maps memory units, and split-primaries fails when its measure phase did not run. Not taken: checking each acknowledged event at its acknowledged offset, and reading every replica separately.
  4. Yes.

🤖 Generated with Claude Code

Several cluster bugs only show up with real processes crashing, restarting
from disk or losing the network under produce load: a replica stuck behind
its group after rolling crash-restarts (apache#4438), sends thrashing once
partition primaries diverge (apache#4436), and acknowledged data lost on
crash-restart with apache#4433 applied. Reproducing them meant hand-built
scripts each time.

scripts/cluster-chaos runs a 3-node cluster from a published apache/iggy
image in Docker, injects one named fault scenario while producing, heals
every node and reads the whole topic back. The checker
(core/tools, bin cluster-chaos-checker) is built on the in-repo SDK, so it
speaks the same protocol as a server from the same commit. It fails a
scenario on lost acknowledged events, offset gaps, per-key reordering,
keys split across partitions, unknown events, an unreadable listed tail,
reads that never settle, producers giving up, or fatal node errors.
Duplicates, empty polls over data and per-node GetTopic stats that
disagree with the read are reported, not failed. A kind backend runs the
same scenarios on the Helm chart's cluster mode.

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

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.47%. Comparing base (43fb443) to head (b5e18de).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #4474      +/-   ##
============================================
+ Coverage     87.54%   88.47%   +0.92%     
+ Complexity     1608     1607       -1     
============================================
  Files          1300     1302       +2     
  Lines        241253   252088   +10835     
  Branches     201557   212384   +10827     
============================================
+ Hits         211207   223037   +11830     
+ Misses        25014    23684    -1330     
- Partials       5032     5367     +335     
Components Coverage Δ
Rust Core 89.60% <ø> (+0.32%) ⬆️
Java SDK 68.81% <ø> (-0.02%) ⬇️
C# SDK 77.83% <ø> (+16.39%) ⬆️
Python SDK 91.25% <ø> (ø)
PHP SDK 85.67% <ø> (ø)
Node SDK 96.62% <ø> (-0.03%) ⬇️
Go SDK 70.27% <ø> (-0.01%) ⬇️
C++ SDK 86.60% <ø> (ø)
see 144 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hubcio

hubcio commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

overall i like what was done here but i think we cannot use docker. i will rewrite this to incorporate all you did into our chaos-monkey test.

@numinnex

Copy link
Copy Markdown
Contributor

Hi @almostintuitive I will close down this PR as #4557 reproduces it using our internal chaos monkey testing suite. I added you as Co-author of the new PR.

@numinnex numinnex closed this Oct 15, 2026
@github-actions github-actions Bot removed the S-waiting-on-review PR is waiting on a reviewer label Oct 15, 2026
numinnex added a commit that referenced this pull request Oct 19, 2026
…#4557)

Relates to #4474, which it supersedes. Relates to #4438, #4436 and
#4476, whose reproductions become scenarios of the existing chaos
monkey.

Co-authored-by: Mark Aron Szulyovszky [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants