You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(inkless:switch): hold each switch step before injecting faults [KC-838] - #885
The switch system tests left eight scenarios uncovered. This PR adds a test for seven of them and explains why the eighth doesn't need one. All of the changes are in inkless_topic_switch_test.py.
Coverage of the gaps
Gap
Test that covers it
The Category B faults raced the protocol step that they meant to hit
New test_fault_before_control_plane_init, which replaces the five Category B fault tests
No lowered seal (kafka-topic-switch.sh lower-seal) taken into phase 2
No system test. ClassicToDisklessSwitchLastKnownLeaderClusterTest with loseTail=true lowers the seal and restarts the leader. It then waits for phase 2 on every broker and reads every record.
The removed tests are test_switch_leader_restart, test_switch_leader_crash (sigkill and sigstop), test_switch_follower_crash_with_lagged_hw, and test_switch_rolling_restart.
Held-step fault test
The Category B fault tests injected the fault right after the config change, so the protocol step that the fault hit was a race. To stretch the steps, they ran under a degraded network with 30 partitions.
Each run of test_fault_before_control_plane_init keeps the switch in one step and injects the fault there. Unless the fault itself moves the switch on, the test asserts that the switch is still in that step. Only then does it release the switch. The holds work like this:
replication holds step 3 in WaitingForReplication. A network partition cuts a follower of partition 0 off from the other brokers while a producer writes. A raised replica.lag.time.max.ms keeps the follower in the ISR. The test switches the topic only after every Trogdor agent reports the partition in place and partition 0 stops getting acks.
control_plane holds step 5 in AwaitingMetadata. The test blocks Postgres during the replication hold and then heals the network partition. The controller commits the seal, and control-plane init retries until Postgres is back.
The runs:
Hold
Fault
What happens
replication
follower_sigkill
The test kills the cut-off follower while the leaders' high watermarks lag their log end offsets. After the switch, a preferred leader election makes that follower lead the partitions it prefers.
replication
leader_sigkill
The test kills the leader of partition 0. The new leader seals again and re-drives InitDisklessLog.
replication
controller_failover
With 3 controllers, the test stops the active controller and one more, then heals the network partition. Once an InitDisklessLog request has been pending for 10 s, it starts the second controller.
control_plane
leader_sigstop
The test freezes the leader of partition 0 for 30 s. The new leader initializes the control plane from metadata.
control_plane
rolling_restart
The test restarts every broker while Postgres is down.
Before a leader fault, the test waits for a fresh JMX sample of that leader in the hold state. After the fault, it requires a fresh sample from every live broker. The producer allows each record 1,000 attempts and 8 hours, so no record expires during a hold.
Category D additions
These runs of test_fault_between_seal_commit_and_phase_2 already existed. This PR adds checks to them:
object_storage_outage: a consumer group commits in the classic prefix before the switch. It resumes up to the seal in phase 1, and through the tail in phase 2. Each time, the test reads the committed offsets back with kafka-consumer-groups.sh. The phase 1 resume commits with the leader epoch of the last classic record, and the test reads __consumer_offsets to assert that epoch before the phase 2 resume. The test checks ListOffsets for earliest and latest in phase 1. In phase 2 it checks latest, earliest, and a timestamp at the start of the tail through each broker, and max-timestamp once.
reassignment: after phase 2, the test moves a follower of partition 1 while a producer writes. It then reads the topic with only the new replica of that partition running.
controller_failover_at_phase_2: the test kills the leader of partition 0 once its own flag request has been pending for 10 s. The leader starts again after the failover.
Testing
python3 -m py_compile passes on the test file.
An AST check finds every self. attribute that the test class uses defined in the class.
make vale doesn't report alerts on the added lines.
Run 44721529007 passed the five test_fault_before_control_plane_init runs and the other eleven Category D runs at c61c07b. b0f2b9f changes only the consumer group check of object_storage_outage. Together the held-step runs took 32.0 minutes, against 43.3 minutes for the Category B runs that they replace in the 2026-11-19 nightly.
…KC-838]
The Category B fault tests injected the fault right after the config
change, so the protocol step that the fault hit was a race. They also
used a degraded network and 30 partitions to stretch the steps, which
made them the slowest switch tests.
`test_fault_before_control_plane_init` replaces them. A network partition
holds step 3 in `WaitingForReplication`, and a Postgres outage after the
seal commit holds step 5 in `AwaitingMetadata`. Each run injects its
fault inside a hold, asserts that the hold is still in place unless the
fault ends it, and then releases it. The runs cover a follower and a
leader crash, a controller failover before the seal commit, a frozen
leader, and a rolling restart while Postgres is down.
Category D runs also cover the remaining client and operator paths:
- `controller_failover_at_phase_2` kills the leader of partition 0 while
its flag request is pending.
- `reassignment` moves a follower in phase 2 under load, then reads the
partition through the new replica alone.
- `object_storage_outage` resumes a consumer group before the switch, in
phase 1, and in phase 2, and reads its committed offsets back. It
checks `ListOffsets` for the latest, earliest, timestamp, and
max-timestamp specs in phase 1 and through each broker in phase 2.
A lowered seal that enters phase 2 needs no system test:
`ClassicToDisklessSwitchLastKnownLeaderClusterTest` lowers the seal,
restarts the leader, waits for phase 2, and reads every record.
Assisted-by: Claude Opus 5.5
Three runs of `test_fault_before_control_plane_init` failed on
records that the producer couldn't send: the replication hold with a
leader SIGKILL and with a controller failover, and the control-plane
hold with a rolling restart. `VerifiableProducer` sets `retries` on the
client as well as the delivery timeout, so `retries=20` capped each
record at 20 attempts. A broker that is down or sealed rejects a send
within a second, and the backoff stays at 1 s, so a record used up its
attempts long before the hold ended.
The held runs now use `retries=1000`, which keeps a record alive for
1,000 attempts and 8 hours. A failed send now also reports the
exception and message of the first errors from the producer output.
Assisted-by: Claude Opus 5.5
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The tests can falsely fail on healthy clusters or miss intended validation and recovery paths because consumption counts include unprocessed records, commits omit leader epochs, and broker termination can rely on stale metrics from another broker.
This PR replaces timing-dependent fault injection with controlled switch-state holds, making Inkless’s classic-to-diskless system tests more predictable and reducing reliance on slow, degraded-network runs.
Changes:
Consolidates mid-switch faults into parameterized replication and control-plane holds, with higher producer retry limits and better failure diagnostics.
Extends phase-2 controller-failover and reassignment scenarios.
Adds consumer-group resume, committed-offset, and ListOffsets checks across switch phases.
… state [KC-838]
Review found three gaps in the new checks:
- `VerifiableConsumer` reports the size of the whole last poll, even when
`--max-messages` stops it partway. `_consume_with_group` no longer
compares that count. The callers already check the committed offsets.
- A manual commit of `VerifiableConsumer` doesn't include a leader epoch,
so the phase 2 resume skipped the epoch check of its position. The
phase 1 resume now auto-commits on close, with the epoch of the last
classic record, and the test reads the commits from
`__consumer_offsets` to assert the epoch before phase 2.
- The cluster-wide state waits can pass on another broker's history.
Before a leader fault, the tests now wait for a fresh sample of the
leader's own gauges: `SendingFlagToController` before the kill in
`controller_failover_at_phase_2`, and the hold state before a leader
SIGKILL or SIGSTOP in `test_fault_before_control_plane_init`.
Assisted-by: Claude Opus 5.5
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The tests can fail on healthy clusters because concatenated commit records are discarded during JSON parsing and the topic switch can race ahead of fault activation and replication lag.
create_task returns before the agents necessarily install the network rules, so the switch can seal the logs while the follower is still caught up. If the high watermark already equals the log end offset, the switch leaves WaitingForReplication immediately and the following hold wait times out on a healthy cluster. Before switching, wait for the agents to activate the fault and verify replication lag on partition 0 while the isolated follower remains in the ISR.
…rtition rules [KC-838]
`OffsetsMessageFormatter` writes the records without a separator, and
`ConsoleConsumer` doesn't add one. Parsing each output line as one JSON
object dropped every commit, so the `object_storage_outage` run would
fail its leader epoch check. `_committed_offsets_with_epochs` now
decodes the output as a run of JSON objects.
`create_task` returns before the Trogdor agents install the iptables
rules. The held-step test now waits until every agent reports the
network partition in place, and until partition 0 stops getting acks,
before it switches the topic. Without that, the switch could seal a log
that the follower had already caught up on.
Assisted-by: Claude Opus 5.5
After a broker restart or pause, this assertion can accept a positive JMX sample from before the fault because _live_cluster_jmx_sum doesn't check timestamps. That lets the test pass without proving the hold survived. Record the assertion's start time and require a newer sample from every live broker before checking the sum.
…[KC-838]
`_assert_switch_state_held` summed the newest sample of each live
broker through `_live_cluster_jmx_sum`, which doesn't check sample
times. `_restart_broker_jmx_tool` keeps the samples from before a
restart, so after a restart or a pause the newest sample could predate
the fault, and the assertion could pass without the hold surviving it.
The assertion now requires a sample from each live broker taken after
the call starts.
Assisted-by: Claude Opus 5.5
…1 resume [KC-838]
The `object_storage_outage` run failed its leader epoch check on
partition 2. The group's first run read 3,000 records and drained that
partition, which held 1,653. Its manual commit at the seal doesn't
include an epoch, and the phase 1 resume fetched nothing from it, so the
commit at close had no epoch either. The first run now reads half the
records of the smallest partition.
Assisted-by: Claude Opus 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The switch system tests left eight scenarios uncovered. This PR adds a test for seven of them and explains why the eighth doesn't need one. All of the changes are in
inkless_topic_switch_test.py.Coverage of the gaps
test_fault_before_control_plane_init, which replaces the five Category B fault teststest_fault_before_control_plane_init,hold=replication,fault=controller_failovertest_fault_before_control_plane_init,hold=control_plane, withfault=leader_sigstopandfault=rolling_restarttest_fault_between_seal_commit_and_phase_2,fault=object_storage_outageListOffsetsacross the sealtest_fault_between_seal_commit_and_phase_2,fault=object_storage_outagetest_fault_between_seal_commit_and_phase_2,fault=reassignmenttest_fault_between_seal_commit_and_phase_2,fault=controller_failover_at_phase_2kafka-topic-switch.sh lower-seal) taken into phase 2ClassicToDisklessSwitchLastKnownLeaderClusterTestwithloseTail=truelowers the seal and restarts the leader. It then waits for phase 2 on every broker and reads every record.The removed tests are
test_switch_leader_restart,test_switch_leader_crash(sigkillandsigstop),test_switch_follower_crash_with_lagged_hw, andtest_switch_rolling_restart.Held-step fault test
The Category B fault tests injected the fault right after the config change, so the protocol step that the fault hit was a race. To stretch the steps, they ran under a degraded network with 30 partitions.
Each run of
test_fault_before_control_plane_initkeeps the switch in one step and injects the fault there. Unless the fault itself moves the switch on, the test asserts that the switch is still in that step. Only then does it release the switch. The holds work like this:replicationholds step 3 inWaitingForReplication. A network partition cuts a follower of partition 0 off from the other brokers while a producer writes. A raisedreplica.lag.time.max.mskeeps the follower in the ISR. The test switches the topic only after every Trogdor agent reports the partition in place and partition 0 stops getting acks.control_planeholds step 5 inAwaitingMetadata. The test blocks Postgres during the replication hold and then heals the network partition. The controller commits the seal, and control-plane init retries until Postgres is back.The runs:
replicationfollower_sigkillreplicationleader_sigkillInitDisklessLog.replicationcontroller_failoverInitDisklessLogrequest has been pending for 10 s, it starts the second controller.control_planeleader_sigstopcontrol_planerolling_restartBefore a leader fault, the test waits for a fresh JMX sample of that leader in the hold state. After the fault, it requires a fresh sample from every live broker. The producer allows each record 1,000 attempts and 8 hours, so no record expires during a hold.
Category D additions
These runs of
test_fault_between_seal_commit_and_phase_2already existed. This PR adds checks to them:object_storage_outage: a consumer group commits in the classic prefix before the switch. It resumes up to the seal in phase 1, and through the tail in phase 2. Each time, the test reads the committed offsets back withkafka-consumer-groups.sh. The phase 1 resume commits with the leader epoch of the last classic record, and the test reads__consumer_offsetsto assert that epoch before the phase 2 resume. The test checksListOffsetsfor earliest and latest in phase 1. In phase 2 it checks latest, earliest, and a timestamp at the start of the tail through each broker, and max-timestamp once.reassignment: after phase 2, the test moves a follower of partition 1 while a producer writes. It then reads the topic with only the new replica of that partition running.controller_failover_at_phase_2: the test kills the leader of partition 0 once its own flag request has been pending for 10 s. The leader starts again after the failover.Testing
python3 -m py_compilepasses on the test file.self.attribute that the test class uses defined in the class.make valedoesn't report alerts on the added lines.object_storage_outageat b0f2b9f, the head.test_fault_before_control_plane_initruns and the other eleven Category D runs at c61c07b. b0f2b9f changes only the consumer group check ofobject_storage_outage. Together the held-step runs took 32.0 minutes, against 43.3 minutes for the Category B runs that they replace in the 2026-11-19 nightly.Assisted-by: Claude Opus 5.5
🤖 Generated with Claude Code