8000 test(inkless:switch): hold each switch step before injecting faults [KC-838] by giuseppelillo · Pull Request #885 · aiven/inkless · GitHub
[go: up one dir, main page]

Skip to content

test(inkless:switch): hold each switch step before injecting faults [KC-838] - #885

Merged
gqmelo merged 6 commits into
mainfrom
claude/kc-838-fix-plan-12b40e
Nov 23, 2026
Merged

gqmelo merged 6 commits into
mainfrom
claude/kc-838-fix-plan-12b40e

Conversation

@giuseppelillo
@giuseppelillo giuseppelillo commented Nov 19, 2026 •
Copy link
Copy Markdown
Contributor

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 controller failover before the seal commit test_fault_before_control_plane_init, hold=replication, fault=controller_failover
No Postgres outage during control-plane init test_fault_before_control_plane_init, hold=control_plane, with fault=leader_sigstop and fault=rolling_restart
No consumer group resumes across the seal and reads its committed offsets back test_fault_between_seal_commit_and_phase_2, fault=object_storage_outage
No ListOffsets across the seal test_fault_between_seal_commit_and_phase_2, fault=object_storage_outage
No partition reassignment in phase 2 under load test_fault_between_seal_commit_and_phase_2, fault=reassignment
No leader kill during the phase 2 flag request test_fault_between_seal_commit_and_phase_2, fault=controller_failover_at_phase_2
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 44743127924 passed object_storage_outage at b0f2b9f, the head.
  • 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.
  • Run 44545244135 passed every unchanged switch test at 08245b0.

Assisted-by: Claude Opus 5.5

🤖 Generated with Claude Code

…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
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

3 open issues
What changed in this PR

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.
File Description
tests/​kafkatest/​tests/​inkless/​inkless_topic_switch_test.py Reworks fault timing and expands recovery, replica-read, and offset checks.

Review effort: Balanced

… 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
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Wait for replication lag before switching

tests/​kafkatest/​tests/​inkless/​inkless_topic_switch_test.py:2022

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.

3 resolved since last review

Review effort: Balanced

…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
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The post-fault assertion can accept stale JMX samples, allowing the test to pass without proving the hold survived a broker restart or pause.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Reject stale JMX samples when asserting broker hold after faults

tests/​kafkatest/​tests/​inkless/​inkless_topic_switch_test.py:1998

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.

1 resolved since last review

Review effort: Balanced

…[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
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the switch-system test and recovery-coverage changes.

No open issues 🎉

Review effort: Balanced

…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
@giuseppelillo
giuseppelillo requested a review from gqmelo November 23, 2026 09:31
@gqmelo
gqmelo merged commit 2929e67 8BD0 into main Nov 23, 2026
7 checks passed
@gqmelo
gqmelo deleted the claude/kc-838-fix-plan-12b40e branch November 23, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet
470D

Development

Successfully merging this pull request may close these issues.

3 participants

0