Repository navigation
fix(inkless:switch): reject DeleteRecords while the switch is pending or in phase 1 [KC-867] - #903
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The test can delete before the leader observes phase 2, causing a non-retriable INVALID_REQUEST and nondeterministic failure; it must wait for every broker’s metadata view before deletion.
1 open issue
What changed in this PR
This PR prevents followers from serving records that DeleteRecords reports as deleted during a classic-to-diskless switch. It replaces #902’s synchronization approach with temporary request rejection.
Changes:
- Reject
DeleteRecordswithINVALID_REQUESTwhile a partition’s switch is pending or in phase 1, without blocking other partitions in the request. - Add unit and cluster tests for rejection, unchanged log starts, and phase 2 acceptance.
- Document the rejection window and the limits of deletions accepted immediately before a switch.
| File | Description |
|---|---|
docs/inkless/DISKLESS_CONSOLIDATION.md |
Clarifies when switched partitions support DeleteRecords. |
docs/inkless/CLASSIC_TO_DISKLESS_SWITCH.md |
Documents rejection, retry guidance, and pre-switch limitations. |
core/src/test/scala/unit/kafka/server/ReplicaManagerInklessTest.scala |
Tests pending switches, phase 1 offsets, and mixed requests. |
core/src/test/java/kafka/server/InklessTopicTypeSwitcherClusterTest.java |
Tests rejection across three brokers and acceptance after phase 2. |
core/src/main/scala/kafka/server/ReplicaManager.scala |
Filters switching partitions before processing deletions. |
Review effort: Balanced
jeqo
left a comment
There was a problem hiding this comment.
Added a couple of comments and have a finding on ConsolidationDisklessLogPruner along the same lines of this change that's maybe worth a small follow-up:
Once the leader finishes uploading the classic prefix (highestOffsetInRemoteStorage == seal - 1), there is a window before phase 2 commits where ConsolidatedDisklessLogPruner can still run on the partition. Because the pruner only filters out pending switches and not phase 1 (ConsolidatedDisklessLogPruner.scala:59-62), if SetClassicPrefixInRemoteStorage is delayed (for example during a controller outage), it can bootstrap remote_log_start_offset and unblock remote retention on the leader while followers are still stuck at the seal.
I'd suggest tracking a follow-up to also exclude !isClassicPrefixOnlyOnLocalDisks in ConsolidatedDisklessLogPruner.prune.
Current:
val eligiblePartitionsWithSeal = inklessMetadataView.getConsolidatingDisklessTopicPartitions.asScala
.map(tip => (tip, inklessMetadataView.getClassicToDisklessStartOffset(tip.topicPartition)))
.filter { case (_, seal) => seal != PartitionRegistration.CLASSIC_TO_DISKLESS_SWITCH_PENDING }
.map { case (tip, seal) => (replicaManager.getPartitionOrError(tip.topicPartition), seal) }Proposed:
val eligiblePartitionsWithSeal = inklessMetadataView.getConsolidatingDisklessTopicPartitions.asScala
.map(tip => (tip, inklessMetadataView.getClassicToDisklessStartOffset(tip.topicPartition)))
.filter { case (tip, seal) =>
seal != PartitionRegistration.CLASSIC_TO_DISKLESS_SWITCH_PENDING &&
!inklessMetadataView.isClassicPrefixOnlyOnLocalDisks(tip.topic, tip.partition)
}
.map { case (tip, seal) => (replicaManager.getPartitionOrError(tip.topicPartition), seal) }| // move its log start offset: remote retention waits for the remote log start in the control plane, which | ||
| // phase 2 sets. The followers stop fetching at the seal, so they would never learn a new log start | ||
| // offset, and the metadata routing sends consumers to them. So the broker rejects the request. | ||
| val (rejected, accepted) = ReplicaManager.rejectDeleteRecordsDuringSwitch(offsetPerPartition, _inklessMetadataView) |
There was a problem hiding this comment.
nit:
| val (rejected, accepted) = ReplicaManager.rejectDeleteRecordsDuringSwitch(offsetPerPartition, _inklessMetadataView) | |
| val (rejectedDuringSwitch, remainingOffsets) = ReplicaManager.rejectDeleteRecordsDuringSwitch(offsetPerPartition, _inklessMetadataView) |
There was a problem hiding this comment.
Renamed to rejectedDuringSwitch and remainingOffsets.
🤖 Addressed by Claude Code
There was a problem hiding this comment.
There is a small race window here where DeleteRecords request passes the switch check at the top of deleteRecords while the topic is still classic (e.g. broker image from KRaft is not updated yet), and the switch-pending metadata arrives right before the broker classifies the partitions. At this stage, this branch still treats a pending switch as a local delete instead of rejecting it. Because the topic now also looks like a consolidating diskless topic, the request skips DelayedDeleteRecords and returns NONE right away while followers still have logStartOffset = 0.
I'd suggest rejecting CLASSIC_TO_DISKLESS_SWITCH_PENDING here with INVALID_REQUEST, gating the crossTierResults split at line 1913 on disklessStartOffsetPerPartition.contains(topicPartition) so a pre-switch classic delete still waits on followers, and dropping the recursive deleteRecords(...) call at line 1768 by wrapping responseCallback once.
// ... line 1761
val (rejectedDuringSwitch, remainingOffsets) =
ReplicaManager.rejectDeleteRecordsDuringSwitch(offsetPerPartition, _inklessMetadataView)
if (rejectedDuringSwitch.nonEmpty) {
info(s"Rejecting DeleteRecords for ${rejectedDuringSwitch.keys.mkString(", ")}: the classic-to-diskless switch " +
"of these partitions is pending or in phase 1")
if (remainingOffsets.isEmpty) {
responseCallback(rejectedDuringSwitch)
return
}
}
// Merges rejected switching partitions into the response once the remaining partitions finish.
val effectiveCallback: Map[TopicPartition, DeleteRecordsPartitionResult] => Unit =
if (rejectedDuringSwitch.isEmpty) responseCallback
else response => responseCallback(response ++ rejectedDuringSwitch)
// ... line 1816 (with mutable failedDisklessDeleteRecords captured as immutable before async closures) ...
case Some(PartitionRegistration.CLASSIC_TO_DISKLESS_SWITCH_PENDING) =>
// Switch metadata arrived after the initial check; reject rather than deleting locally.
info(s"Rejecting DeleteRecords for $topicPartition: the classic-to-diskless switch of this partition is pending")
failedDisklessDeleteRecords += topicPartition -> new DeleteRecordsPartitionResult()
.setPartitionIndex(topicPartition.partition)
.setLowWatermark(DeleteRecordsResponse.INVALID_LOW_WATERMARK)
.setErrorCode(Errors.INVALID_REQUEST.code)
// ... line 1912 ...
val (crossTierResults, classicResults) = localDeleteRecordsResults.partition { case (topicPartition, _) =>
disklessStartOffsetPerPartition.contains(topicPartition) &&
_inklessMetadataView.isConsolidatingDisklessTopic(topicPartition.topic)
}There was a problem hiding this comment.
Good catch, the three reads can disagree. I applied all three parts:
- A pending switch that the classification sees gets
INVALID_REQUEST, and nothing is deleted. - Only a partition that this request classified as diskless skips the wait for the followers, so a delete of a classic partition still waits for them if the switch config arrives meanwhile.
- The recursive call is gone. The method wraps the response callback once and works on the remaining partitions.
ReplicaManagerInklessTest has a test for each case: testDeleteRecordsIsRejectedWhenTheSwitchStartsAfterTheFirstCheck and testDeleteRecordsOfAClassicPartitionWaitsForFollowersWhenTheSwitchStartsMeanwhile. Both fail without the change.
🤖 Addressed by Claude Code
| // While the classic-to-diskless switch of a partition is pending or in phase 1, only DeleteRecords can | ||
| // move its log start offset: remote retention waits for the remote log start in the control plane, which | ||
| // phase 2 sets. The followers stop fetching at the seal, so they would never learn a new log start | ||
| // offset, and the metadata routing sends consumers to them. So the broker rejects the request. |
There was a problem hiding this comment.
This comment says phase 2 sets the remote log start in the control plane, which can mislead a reader about what actually pauses remote retention during the switch. Moving to phase 2 (SetClassicPrefixInRemoteStorage) only updates KRaft metadata; the control plane's remote_log_start_offset stays unset until ConsolidatedDisklessLogPruner bootstraps it once the classic prefix finishes uploading (or DeleteRecords advances it in phase 2).
I'd suggest rewording to match CLASSIC_TO_DISKLESS_SWITCH.md:201 ("remote retention waits for the control plane to store the remote log start, which doesn't happen while the leader still uploads the classic prefix").
| // While the classic-to-diskless switch of a partition is pending or in phase 1, only DeleteRecords can | |
| // move its log start offset: remote retention waits for the remote log start in the control plane, which | |
| // phase 2 sets. The followers stop fetching at the seal, so they would never learn a new log start | |
| // offset, and the metadata routing sends consumers to them. So the broker rejects the request. | |
| // While the classic-to-diskless switch of a partition is pending or in phase 1, only DeleteRecords can | |
| // move its log start offset: remote retention waits for the control plane to store the remote log start, | |
| // which doesn't happen while the leader still uploads the classic prefix. The followers stop fetching at | |
| // the seal, so they would never learn a new log start offset, and the metadata routing sends consumers to | |
| // them. So the broker rejects the request. |
There was a problem hiding this comment.
Right, phase 2 does not set it. I used your wording.
🤖 Addressed by Claude Code
|
Thanks for the review. The I also corrected the PR description. It said that nothing moves the log start while the switch is pending or in phase 1. That holds while the leader still uploads the classic prefix, and not between the end of the upload and the phase 2 commit. 🤖 Addressed by Claude Code |
7ec1767 to
3b427c3
Compare
… or in phase 1 [KC-867] In phase 1 of the classic-to-diskless switch, `DeleteRecords` below the seal advances the log start of the leader 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 broker now rejects `DeleteRecords` for a partition with `INVALID_REQUEST` while its switch is pending or in phase 1, and deletes nothing. The other partitions of the same request proceed. The window is as long as the upload of the classic prefix, and the request works again from phase 2 on. Kafka Streams, which purges its repartition topics with `DeleteRecords`, sends a new request at its next purge interval after a failure. Making the request work in that window needs every replica to learn the new log start without a fetch. The rejection needs none of that, and it also covers a request that arrives before the leader initializes the partition in the control plane. Without `DeleteRecords`, nothing moves the log start in that window. For a consolidating partition, `RemoteLogManager` doesn't expire remote segments until the control plane stores the remote log start of the partition (`reclaimFloorLogStartOffset`). On a 3-broker cluster, with two segments in remote storage and `retention.ms` set to 1 second in phase 1, the expiration task deferred 5 times in 25 seconds and the log start stayed 0 on every replica. After phase 2 started, the same task moved the log start of the leader to 30. - `ReplicaManagerInklessTest` has new tests for a pending switch, for phase 1 with an offset below the seal, at the seal, past the seal, and with `HIGH_WATERMARK`, and for a request that mixes a classic partition with one in phase 1. - `InklessTopicTypeSwitcherClusterTest.testDeleteRecordsIsRejectedUntilPhaseTwo` runs on 3 brokers. In phase 1 the request fails with `InvalidRequestException`, no broker moves its log start, and consumers in every zone read from offset 0. After phase 2 starts, the request returns low watermark 10. - Without the change to `ReplicaManager`, the 7 new tests fail. - `ReplicaManagerInklessTest` (320 tests), `ReplicaManagerTest` (129 tests), and `InklessTopicTypeSwitcherClusterTest` (10 tests) pass. `:core:checkstyleMain`, `:core:checkstyleTest`, and `:core:spotbugsMain` pass. `make vale` reports no alerts. Assisted-by: Claude Fable 5.2
…ore the switch [KC-867] The leader rejects `DeleteRecords` from its own metadata. A request that the leader receives before it applies the record that starts the switch is a request for a classic partition, so the leader deletes the records. The leader then proposes the seal as soon as its high watermark equals its log end offset, without waiting for the followers to report the new log start. On a 3-broker cluster, with the request sent right before the switch, the leader accepted it in 3 of 4 runs. Every replica ended with log start 10, and the client got `TimeoutException` after 60 seconds. In the fourth run the leader rejected the request. The switch doc now states both effects, a request that times out and a follower that isn't guaranteed to have the new log start, and tells the operator not to send `DeleteRecords` right before a switch. Assisted-by: Claude Fable 5.2
…ete [KC-867] `testDeleteRecordsIsRejectedUntilPhaseTwo` waited for phase 2 with `waitForClassicPrefixInRemoteStorage`, which reads the phase from one broker through the admin client. The leader rejects `DeleteRecords` until its own metadata shows phase 2, and the admin client doesn't retry `INVALID_REQUEST`. So the delete could fail if that broker applied the phase 2 record before the leader did. The test now waits until the metadata view of every broker shows phase 2 before it sends the delete. Assisted-by: Claude Fable 5.2
…-867] The `Inkless Vale` workflow reported two alerts on the comment that the previous commit added to `testDeleteRecordsIsRejectedUntilPhaseTwo`: `admin` as a word, and `INVALID_REQUEST` without backticks. The comment now names the `Admin` client and puts the error code in backticks. Assisted-by: Claude Fable 5.2
…ter the first check [KC-867] `ReplicaManager.deleteRecords` reads the metadata three times: for the switch check at its start, to classify the partitions, and to decide which partitions skip the wait for the followers. The record that starts the switch can arrive between these reads, and a review found two outcomes: - The classification sees a pending switch that the first check didn't. It handled the partition as a local delete, and because the topic now looked like a consolidating diskless topic, the request returned success at once while the followers still had their old log start. - The classification sees a classic partition, and the topic looks like a consolidating diskless topic by the time the local delete finishes. The request skipped the wait for the followers. `deleteRecords` now rejects a pending switch at the classification with `INVALID_REQUEST`. Only a partition that the request classified as diskless skips the wait for the followers, so a delete of a classic partition waits for them as before. The method also wraps the response callback once and no longer calls itself for the partitions it doesn't reject. The comment on the check said that phase 2 sets the remote log start in the control plane. `ConsolidatedDisklessLogPruner` stores it once the classic prefix is uploaded, so the comment now says that remote retention waits while the leader still uploads the prefix. ## Testing - `ReplicaManagerInklessTest` has two new tests, one for each outcome: `testDeleteRecordsIsRejectedWhenTheSwitchStartsAfterTheFirstCheck` and `testDeleteRecordsOfAClassicPartitionWaitsForFollowersWhenTheSwitchStartsMeanwhile`. Both fail without the change to `ReplicaManager`. - `ReplicaManagerInklessTest` (322 tests), `ReplicaManagerTest` (129 tests), and `InklessTopicTypeSwitcherClusterTest` (10 tests) pass. `:core:checkstyleMain`, `:core:checkstyleTest`, and `:core:spotbugsMain` pass. `make vale` reports no alerts. Assisted-by: Claude Fable 5.2
3b427c3 to
429297f
Compare

In phase 1 of the classic-to-diskless switch,
DeleteRecordsbelow the seal returns success, but the followers keep serving the deleted records. With this change the broker rejectsDeleteRecordsfor a partition while its switch is pending or in phase 1.This PR replaces #902, which made the request work in phase 1.
Problem
DeleteRecordsbelow the seal advances the log start of the leader and returns at once. A follower learns the log start from fetch responses, and in phase 1 that path is closed:ReplicaManager.fetchMessagesanswers withlogStartOffset = 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.
Example before this change
On a 3-broker cluster, a topic with 3 replicas is sealed at offset 20 and stays in phase 1:
Admin.deleteRecords(beforeOffset(10))returns low watermark 10.logStartOffset=10, and both followers havelogStartOffset=0.Fix
ReplicaManager.deleteRecordsanswersINVALID_REQUESTfor a partition whose switch is pending or in phase 1, and deletes nothing. The other partitions of the same request proceed. The request works again from phase 2 on.deleteRecordsreads the metadata again when it classifies the partitions. If the record that starts the switch arrives between the two reads, the classification rejects the pending partition too. Only a partition that the request classified as diskless skips the wait for the followers, so a delete of a classic partition waits for them as before.The window is as long as the upload of the classic prefix. Kafka Streams purges its repartition topics with
DeleteRecords, and after a failure it sends a new request at its next purge interval.Making the request work in that window needs every replica to learn the new log start without a fetch, which #902 did with a scheduled control-plane read on every broker and a delayed response. The rejection needs none of that. It also covers a request that arrives before the leader initializes the partition in the control plane.
Retention in the same window
Without
DeleteRecords, nothing moves the log start while the switch is pending, or in phase 1 while the leader still uploads the classic prefix. For a consolidating partition,RemoteLogManagerdoesn't expire remote segments until the control plane stores the remote log start of the partition (reclaimFloorLogStartOffset).Once the prefix is uploaded,
ConsolidatedDisklessLogPrunerstores the remote log start, also for a partition in phase 1. If the controller commits phase 2 late, remote retention can then run in phase 1. A follow-up PR makes the pruner skip partitions in phase 1.On a 3-broker cluster, a tiered classic topic had two segments in remote storage. It was switched and kept in phase 1, and
retention.mswas set to 1 second:Cross-tier log start offset is not initialized, and the log start stayed 0 on every replica.Limits
The leader rejects the request from its own metadata. A
DeleteRecordsrequest that the leader receives before it applies the record that starts the switch is a request for a classic partition, so the leader deletes the records. It then proposes the seal as soon as its high watermark equals its log end offset, without waiting for the followers to report the new log start.On a 3-broker cluster, with the request sent right before the switch, the leader accepted it in 3 of 4 runs. Every replica ended with log start 10, and the client got
TimeoutExceptionafter 60 seconds. In the fourth run the leader rejected the request withInvalidRequestException.CLASSIC_TO_DISKLESS_SWITCH.mdstates this limit and tells the operator not to sendDeleteRecordsright before a switch.Test plan
ReplicaManagerInklessTesthas new tests for a pending switch, for phase 1 with an offset below the seal, at the seal, past the seal, and withHIGH_WATERMARK, and for a request that mixes a classic partition with one in phase 1.ReplicaManagerInklessTestalso covers the record that starts the switch arriving after the first check indeleteRecords: a pending switch that the classification sees is rejected, and a partition that the request classified as classic still waits for the followers.InklessTopicTypeSwitcherClusterTest.testDeleteRecordsIsRejectedUntilPhaseTworuns on 3 brokers. In phase 1 the request fails withInvalidRequestException, no broker moves its log start, and consumers in every zone read from offset 0. After phase 2 starts, the request returns low watermark 10.ReplicaManager, the 9 new tests fail.ReplicaManagerInklessTest(327 tests),ReplicaManagerTest(129 tests), andInklessTopicTypeSwitcherClusterTest(11 tests) pass.:core:checkstyleMain,:core:checkstyleTest, and:core:spotbugsMainpass.make valereports no alerts on the added lines.🤖 Generated with Claude Code