Skip to content

fix(inkless:switch): refuse reads of records that DeleteRecords removed in phase 1 [KC-867] - #902

Closed
giuseppelillo wants to merge 1 commit into
mainfrom
giuseppelillo/delete-records-phase-one-followers
Closed

giuseppelillo wants to merge 1 commit into
mainfrom
giuseppelillo/delete-records-phase-one-followers

Conversation

@giuseppelillo

Copy link
Copy Markdown
Contributor

In phase 1 of the classic-to-diskless switch, DeleteRecords below the seal returns success, but the followers keep serving the deleted records to consumers. With this change every replica refuses those reads when the request succeeds.

Problem

DeleteRecords below the seal advances the log start of the leader and the cross-tier earliest offset in the control plane, and returns at once. A follower learns the log start from fetch responses, and in phase 1 that path is closed:

  • An in-sync follower whose log is at the seal leaves the classic fetcher, so it sends no more fetches.
  • When a follower does fetch at the seal, ReplicaManager.fetchMessages answers with logStartOffset = 0, so the follower keeps its classic records.

In phase 1 the metadata routing sends clients to any alive ISR member. A follower serves a read below the seal from its local log and checks only its own log start.

If the control plane doesn't advance the cross-tier earliest offset, advanceCrossTierEarliestForDeleteRecords logs the failure and the request still returns success. In phase 1 nothing corrects that later.

Example before this change

On a 3-broker cluster, a topic with 3 replicas is sealed at offset 20 and stays in phase 1:

  1. Admin.deleteRecords(beforeOffset(10)) returns low watermark 10.
  2. Fifteen seconds later the leader has logStartOffset=10, and both followers have logStartOffset=0.
  3. A consumer in the zone of a follower seeks to offset 0 and reads offset 0. A consumer in the zone of the leader reads offset 10.

Fix

The change has three parts:

  • Read check. Every replica refuses a consumer read below the seal of a phase 1 partition with OFFSET_OUT_OF_RANGE if the offset is below the cross-tier earliest offset. The new DisklessPhaseOneCrossTierEarliest keeps that offset in memory. A scheduled task reads it from the control plane once per cross.tier.log.start.report.interval.ms (1 second by default), in one call for every phase 1 partition on the broker. The fetch path reads only the value in memory, so a slow control plane doesn't delay a request handler thread. After a failed read the broker keeps the last value, and with no value it serves the read.
  • Hold. The leader holds the DeleteRecords response of a phase 1 partition for two of those intervals, so that the other replicas have the new value when the request succeeds. If the request timeout is shorter, the leader answers REQUEST_TIMED_OUT at the timeout and keeps the records deleted, as DelayedDeleteRecords does.
  • Failed advance. If the control plane doesn't advance the cross-tier earliest offset of a phase 1 partition, the leader answers KAFKA_STORAGE_ERROR, which the client retries.

Phase 2 and born-diskless partitions don't change.

Limits

  • The scheduled task checks every partition that the broker hosts once per interval to find the ones in phase 1. It queries the control plane only if it finds one.
  • Every DeleteRecords on a phase 1 partition takes two intervals, 2 seconds by default.

Test plan

  • ReplicaManagerInklessTest covers the read check on a follower and on the leader, that the fetch path doesn't query the control plane, a failed refresh, the hold, the request timeout, and a cross-tier earliest offset that doesn't advance. The class passes with 321 tests.
  • InklessTopicTypeSwitcherClusterTest has three new tests on 3 brokers:
    • testDeleteRecordsInPhaseOneHidesDeletedRecordsOnEveryReplica: consumers in every zone read from the new log start, also after leadership moves to a follower.
    • testPhaseOnePrefixReadsDontWaitForAnUnreachableControlPlane: with the control-plane database paused, 12 consumers read the whole prefix, and a produce to a classic topic on the same broker isn't delayed.
    • testDeleteRecordsInPhaseOneFailsWhileTheControlPlaneIsUnreachable: the request fails while the database is paused, and a retry succeeds afterward.
  • The cluster test class passes with 12 tests. With the production code of main, the first and the third new test fail.
  • :core:checkstyleMain, :core:checkstyleTest, and :core:spotbugsMain pass. make vale reports no alerts on the added lines.

🤖 Generated with Claude Code

…ed in phase 1 [KC-867]

In phase 1 of the switch, `DeleteRecords` below the seal advances the
log start of the leader and the cross-tier earliest offset in the control
plane, and returns success. The followers left the classic fetcher at the
seal, so they don't learn the new log start. The metadata routing sends
consumers to them, and they keep serving the deleted records until
phase 2.

On a 3-broker cluster, after `DeleteRecords` with offset 10 on a
partition sealed at 20, the leader had log start 10, both followers had
log start 0, and consumers in the zones of the followers read offset 0.

The change has three parts:

- Every replica refuses a consumer read below the seal of a phase 1
  partition with `OFFSET_OUT_OF_RANGE` if the offset is below the
  cross-tier earliest offset. `DisklessPhaseOneCrossTierEarliest` keeps
  that offset in memory. A scheduled task reads it from the control plane
  once per `cross.tier.log.start.report.interval.ms`, in one call for
  every phase 1 partition on the broker. The fetch path reads only the
  value in memory, so a slow control plane doesn't delay a request
  handler thread. After a failed read the broker keeps the last value,
  and with no value it serves the read.
- The leader holds the `DeleteRecords` response of a phase 1 partition
  for two of those intervals, so that the other replicas have the new
  value when the request succeeds. If the request timeout is shorter, the
  leader answers `REQUEST_TIMED_OUT` at the timeout and keeps the records
  deleted, as `DelayedDeleteRecords` does.
- If the control plane doesn't advance the cross-tier earliest offset of
  a phase 1 partition, the leader answers `KAFKA_STORAGE_ERROR`, which the
  client retries. It answered success before, and the followers then
  served the deleted records with nothing to correct them.

Phase 2 and born-diskless partitions don't change.

## Testing

- `ReplicaManagerInklessTest` covers the read check on a follower and on
  the leader, that the fetch path doesn't query the control plane, a
  failed refresh, the hold, the request timeout, and a cross-tier earliest
  offset that doesn't advance. The class passes with 321 tests.
- `InklessTopicTypeSwitcherClusterTest` has three new tests on 3 brokers:
  - `testDeleteRecordsInPhaseOneHidesDeletedRecordsOnEveryReplica`:
    consumers in every zone read from the new log start, also after
    leadership moves to a follower.
  - `testPhaseOnePrefixReadsDontWaitForAnUnreachableControlPlane`: with
    the control-plane database paused, 12 consumers read the whole prefix
    and a produce to a classic topic on the same broker isn't delayed.
  - `testDeleteRecordsInPhaseOneFailsWhileTheControlPlaneIsUnreachable`:
    the request fails while the database is paused, and a retry succeeds
    afterward.
  The class passes with 12 tests. With the production code of `main`,
  the first and the third test fail.
- `:core:checkstyleMain`, `:core:checkstyleTest`, and
  `:core:spotbugsMain` pass.

Assisted-by: Claude Opus 5.5
Assisted-by: Claude Fable 5.2
@giuseppelillo

Copy link
Copy Markdown
Contributor Author

Replaced by #903, which rejects DeleteRecords while the switch of a partition is pending or in phase 1, instead of making the request work in that window.

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.

1 participant