Skip to main content

Jepsen Kafka workload

Jepsen tests distributed systems for safety. It runs operations against a cluster from many clients at the same time. A nemesis injects faults on the way. A checker then examines the full history of the operations for anomalies.

Jepsen’s jepsen.tests.kafka workload tests a Kafka-compatible queue. Its clients send records to a set of keys, each key one topic partition. Other clients poll the records back. With --txn, the clients send and poll in Kafka transactions. The checker finds lost writes, duplicates, polls that skip or go back, inconsistent offsets, and transactional anomalies such as G0 and G1c.

aspect jepsen runs that workload against a krabka cluster in Docker containers. The workload, its generator and its checker are Jepsen’s. The harness in tools/jepsen/ adds the client, the database setup, and the nemesis.

Run the tests

aspect jepsen

The task needs Docker, Bazel, Maven, and a JDK 21 or later for the Jepsen JVM. Jepsen 0.3.15 depends on a library compiled for Java 21. The task starts five node containers and a Jepsen JVM with a heap of up to 8 GB. The first run downloads the Jepsen and Kafka client libraries into the local Maven repository.

The task does these steps:

  1. It builds krabka-broker and krabka-format with bazel build -c opt and installs them in target/jepsen/bin/.
  2. It builds the node image krabka-jepsen-node:latest from tools/jepsen/node.Dockerfile.
  3. It resolves the harness classpath with Maven from tools/jepsen/pom.xml, into target/jepsen/classpath.txt.
  4. It starts the node containers n1 to n5 on the Docker network jepsen-krabka.
  5. It writes the selected manifest entries to target/jepsen/selected.json, and runs them with the harness from the sources in tools/jepsen/src/. Jepsen runs one test for each entry.
  6. It compares each result with the manifest and writes target/jepsen/report.md.

To run part of the manifest, give one or more --test prefixes. A prefix selects each entry whose name starts with it:

aspect jepsen --test assign-
aspect jepsen --test assign-none --test subscribe-txn

These options change the other steps:

Option Default Effect
--manifest FILE tools/jepsen/suite.json The manifest, relative to the repository root.
--test PREFIX every entry Run only the entries whose name starts with PREFIX. Repeatable.
--bin-dir DIR build with Bazel Use the krabka-broker and krabka-format in DIR, and do not build. DIR is absolute or relative to the repository root.
--image NAME build the node image Start the nodes from the existing image NAME.
--nodes N 5 Start N node containers, n1 to n<N>.
--heap SIZE 8g The maximum heap of the Jepsen JVM, in the form that -Xmx takes.
--keep-nodes off Leave the node containers up after the run.
--no-skips off Count an entry the machine cannot run as a regression, not as skipped. CI sets it, so that a runner without sch_netem fails rather than quietly leaving out the packet faults.
--bazel-config NAME none Build with --config=NAME as well as -c opt. CI passes release, the configuration of every shipped image.

The node containers have fixed names. A run removes each container named n1 to n<N> before it starts the nodes, also a container that the run did not start. At the end the task removes the node containers, unless --keep-nodes keeps them. Use docker exec -it n1 bash to examine a kept node. The task keeps the jepsen-krabka network for the next run.

How the harness works

The harness is a Clojure program in tools/jepsen/src/jepsen/krabka/. The task does not compile it. java -cp runs it from source with clojure.main. Its suite command runs every entry of a manifest, one Jepsen test each, and writes a JSON summary.

  • Remote. Jepsen usually reaches each node with SSH. With --docker, the harness reaches the container that has the name of the node with docker exec, and it copies files with docker cp. It also skips the operating system setup, because the node image already holds the tools that Jepsen uses.
  • Database. Each test uploads the two binaries from --bin-dir to every node. Every node runs krabka-broker in KRaft combined mode, as a broker and as a voter of the static controller quorum. Each node logs to /opt/krabka/broker.log. At the end of a test, Jepsen copies the log, the krabka.toml file, and an archive of the data directory of each node into the store.
  • Client. The client is Apache Kafka’s Java client, at the release that pom.xml pins.
  • Nemesis. The harness uses Jepsen’s combined nemesis, built from the selected faults only. --nemesis selects the faults: partition with iptables, packet delay, loss, duplication and reordering with tc netem, kill and pause of the broker process, and clock bumps, strobes and resets. Kills and pauses each start and heal on a schedule of their own. Jepsen’s DB package picks one of the two at random at each step, so a kill of every node could wait out a two-minute test for its restart, leaving the checker a history with no successful operation in it. The nemesis finds the controller leader, for faults on primaries, by asking every node at once, so a paused or cut-off node does not hold the next fault back.
  • Clock. Jepsen’s own clock nemesis steps the system clock, and Docker containers share the host’s. With --docker the harness instead starts each broker with libfaketime preloaded, reading its wall-clock offset from /opt/krabka/clock-offset on its node, and the clock nemesis rewrites that file. Only the wall clock moves; the monotonic clock does not, as when a system clock is stepped. libfaketime reads the file at most once a second, so a strobe faster than that shows the broker fewer flips. --clock-mode system uses Jepsen’s own nemesis, for nodes with their own clocks.
  • Checker. Jepsen’s Kafka checker examines the history. The harness also fails a test whose broker log has a Rust panic.

The node image holds only the tools that Jepsen needs on a node. Each container runs with --init, so that a killed broker is reaped and does not stay a zombie, and with the NET_ADMIN capability for iptables and tc. The nodes get no SYS_TIME: clock faults never touch the host’s clock.

The manifest

tools/jepsen/suite.json lists the tests. It crosses the two ways a consumer gets partitions (assign and subscribe), with and without transactions, with each fault alone and with partitions, kills and pauses together. It adds crashed clients, and KIP-848’s consumer group protocol:

{
  "defaults": ["--safe", "--time-limit", "120", "--concurrency", "2n"],
  "tests": [
    {"name": "assign-none", "args": ["--sub-via", "assign"]},
    {"name": "assign-packet", "args": ["--sub-via", "assign", "--nemesis", "packet"], "requires": ["netem"]},
    {"name": "subscribe-txn-partition", "args": ["--sub-via", "subscribe", "--txn", "--nemesis", "partition"],
     "known_failure": "how it fails"}
  ]
}
  • defaults is a list of harness options that every test gets. An entry’s args come after them, so an entry can override a default.
  • name identifies the entry. It holds lowercase letters, digits, and - only. Each name occurs one time.
  • args is the list of harness options for this test. It can be empty.
  • requires lists what the test needs from the machine. The one requirement is netem, for packet faults.
  • known_failure tells how krabka fails the test.

The task checks the manifest before it starts. It stops with status 2 if the manifest has an unknown key, or a field of the wrong type.

The harness skips an entry whose requirement the machine does not meet. netem needs the sch_netem module in the host kernel: sudo modprobe sch_netem loads it where the kernel ships it. With --no-skips, a skipped entry is a regression.

The --safe option sets the client settings under which Kafka promises the most: acks=all, idempotent producers, read_committed consumers, and a replication factor of 3. To list every harness option, run the harness with --help after a first run of the task:

java -Djava.awt.headless=true -cp "tools/jepsen/src:$(cat target/jepsen/classpath.txt)" \
  clojure.main -m jepsen.krabka.core test --help

The JVM needs -Djava.awt.headless=true. Without it, a graph library that Jepsen loads asks for a display and fails.

Results

Jepsen writes each test to its store in target/jepsen/store/, in a directory named for the test and its start time. The store holds the history, the checker results, latency and rate plots, the Jepsen log, and the log and data of each node. The task prints the store path of each regression. To look at the store in a browser, run the harness’s serve command from target/jepsen.

The harness writes target/jepsen/results.json with one result for each entry that it ran. Each result has one of these statuses:

Status Meaning
valid The checker found no anomaly that makes the history invalid.
invalid The checker found an anomaly.
unknown The checker could not decide.
crashed The test stopped with an exception, or its options were bad.
skipped The machine does not meet a requirement of the entry.

The task reports an entry with no result as NOT RUN. It gives each entry one of five verdicts:

Verdict Expectation Result
pass pass valid
regression pass invalid, unknown, crashed or NOT RUN
regression known_failure crashed or NOT RUN
known failure known_failure invalid or unknown
fixed known_failure valid
regression either skipped, with --no-skips
skipped either skipped, without --no-skips

target/jepsen/report.md has the totals, then one row for each entry. For a regression, the row names the anomalies that made the history invalid, or the first line of the error. The exit status of the harness is not the verdict.

The task exits with status 1 if one or more entries is a regression. When an entry is fixed, remove its known_failure. With --no-skips, the row of a skipped entry still gives the reason the harness skipped it.

In CI

The jepsen job of ci.yml runs the whole manifest every night and on every manual run of the workflow, on a hosted runner:

aspect jepsen --bazel-config release --no-skips

It loads sch_netem first, so the packet faults run. The release workflow promotes a tag only when a full run of its commit passed every lane, so this job gates releases. A known failure does not fail the job; a regression does. The job uploads report.md and results.json as the jepsen-report artifact, kept for 90 days, and the Jepsen store as a tarball in jepsen-store, kept for 14 days. The store goes up as one archive because Jepsen names each test’s directory by its start time, and upload-artifact refuses a path with a colon in it. The job adds the report to the run’s summary. A red nightly run names the lane in the nightly-red issue. The run takes about two and a half hours.

Bugs the suite found

No entry in the manifest is marked known_failure, so any invalid entry fails the job. The suite’s first runs found the broker bugs below, each fixed since. One failure is still open: assign-mixed, which was never marked, was invalid once on unseen (committed records that no consumer read) in a dispatch run after those fixes, and is not explained by any of them.

  • Duplicate records (#1947). With acks=all and an idempotent producer, a partitioned or paused follower makes the produce time out, and the client retries the batch. The leader appended the retry again instead of answering it with the original offset, so the log held two or three copies of one batch, with the same producer id, epoch and sequence under one leader epoch.
  • A partition stuck after re-election (#1936). After an unclean restart the controller re-elects a partition’s leader at a new epoch. A re-registration could overwrite an uncommitted election, and an epoch bump that kept the same leader could be lost, so a leader or its followers went on fetching at the old epoch, each logging holding the partition back until the metadata image settles until the test ended. On a __transaction_state partition no transactional client could start.
  • A hanging transaction (#1941, #1953). A transaction open on a partition when brokers were killed never got its marker. Completion gave up on an unexpected marker answer, and the reaper waited on each abort in turn, so the partition’s last stable offset stayed behind the transaction and a read_committed consumer read nothing past it. completion_model found a third path: a coordinator that loaded its __transaction_state partition after a failover acted on records the new leader had not committed, which a second failover could take back. A load now publishes only once the high watermark covers what it replayed.
  • Committed records no consumer read (#1964). A KIP-848 group actor stopped after a failed write, and its group then refused offset commits.

The harness had two bugs of its own (#1961): Jepsen’s DB package picked the kill or the pause schedule at random at each step, so a kill or pause of every node could last a whole test, and the controller-leader lookup asked one node at a time with a 3 s timeout, holding the single nemesis thread.

Run one test by hand

The harness’s test command runs one test with any options, against nodes that are already up. Start them with aspect jepsen --test assign-none --keep-nodes, then run from target/jepsen:

java -Djava.awt.headless=true -cp "../../tools/jepsen/src:$(cat classpath.txt)" \
  clojure.main -m jepsen.krabka.core test \
  --docker --nodes n1,n2,n3,n4,n5 --bin-dir bin \
  --safe --txn --nemesis partition,kill --time-limit 300 --test-count 5

Without --docker, the harness uses Jepsen’s SSH remote and its Debian setup, as Jepsen’s other tests do, and clock faults step each machine’s system clock. --bin-dir is still a directory on the control machine.

Unit tests

The pure parts of the harness have unit tests: option parsing, the suite runner’s bookkeeping, the node configuration and the key mapping. They need no cluster:

java -Djava.awt.headless=true -Dclojure.compile.path=target/jepsen/classes \
  -cp "tools/jepsen/src:tools/jepsen/test:$(cat target/jepsen/classpath.txt)" \
  clojure.main -m jepsen.krabka.core-test

clojure.compile.path keeps the classes that Jepsen’s dom-top library compiles at load time out of the working tree. Its default is ./classes.

aspect tests jepsen tests the task’s own functions.

Known gaps

  • Clock faults move the broker’s wall clock only through the C library. A clock read that bypasses it would not see the skew.
  • A host kernel without sch_netem cannot run packet faults. The harness then reports those entries as skipped, or as regressions with --no-skips.
  • The nemesis does not change the cluster’s membership. It does not add or remove brokers or controller voters.
  • All nodes are on one host. A partition stops traffic between containers, but the nodes share one kernel, one disk, and one CPU scheduler.
  • The cluster uses PLAINTEXT listeners only. The task does not test TLS or SASL.
  • The task tests one client, Apache Kafka’s Java client.