Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-13972; Ensure replica state deleted after reassignment cancellation #13107

Merged

Conversation

hachikuji
Copy link
Contributor

@hachikuji hachikuji commented Jan 12, 2023

When a reassignment is cancelled, we need to delete the partition state of adding replicas. Failing to do so causes "stray" replicas which take up disk space and can cause topicId conflicts if the topic is later recreated. Currently, this logic does not work because the leader epoch does not always get bumped after cancellation. Without a leader epoch bump, the replica will ignore StopReplica requests sent by the controller and the replica may remain online.

In this patch, we fix the problem by loosening the epoch check on the broker side when a StopReplica request is received. Instead of ignoring the request when the request epoch matches the current epoch, the request will be accepted.

Note, this problem only affects the ZK controller. The integration tests added here nevertheless cover both metadata modes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@hachikuji
Copy link
Contributor Author

@jolshan @dajac This patch has been updated to loosen the epoch check on the broker side. The original approach seemed a little risky in the case a reassignment is cancelled and resubmitted. It might be possible for aStopReplica request corresponding to the cancellation to get ordered after the LeaderAndIsr for the resubmitted reassignment. With the loosened check, that would not be possible since a new reassignment would have a leader epoch bump: https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/controller/KafkaController.scala#L747.

@@ -390,7 +390,7 @@ class ReplicaManager(val config: KafkaConfig,
// epoch, a sentinel value (NoEpoch) is used and bypass the epoch validation.
if (requestLeaderEpoch == LeaderAndIsr.EpochDuringDelete ||
requestLeaderEpoch == LeaderAndIsr.NoEpoch ||
requestLeaderEpoch > currentLeaderEpoch) {
requestLeaderEpoch >= currentLeaderEpoch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious -- was the epoch check put in place because we were concerned about stale stop replicas? Just trying to figure out why we need it and the implications for adding the current epoch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is part of KIP-570. I will take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the concern there was reassignment. I think equal to the leader epoch is ok though because if we are a replica for the current leader epoch then we can't send a stop replica unless the reassignment was cancelled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the main thing is that a new reassignment will always have a leader epoch bump, so we are still ensured that the StopReplica cannot be reordered. It is still possible to have a stray replica though if the StopReplica from a cancellation is received before the initial LeaderAndIsr when the reassignment began. A better fix would be to bump the epoch after cancellation, but I didn't see a really simple way to do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Thanks for clarifying.

Copy link
Contributor

@dajac dajac left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Copy link
Contributor

@jolshan jolshan left a comment

Choose a reason for hiding this comment

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

thanks Jason. I'm excited to see this fix. :)

@jolshan jolshan merged commit 653e284 into apache:trunk Jan 18, 2023
guozhangwang pushed a commit to guozhangwang/kafka that referenced this pull request Jan 25, 2023
…tion (apache#13107)

When a reassignment is cancelled, we need to delete the partition state of adding replicas. Failing to do so causes "stray" replicas which take up disk space and can cause topicId conflicts if the topic is later recreated. Currently, this logic does not work because the leader epoch does not always get bumped after cancellation. Without a leader epoch bump, the replica will ignore StopReplica requests sent by the controller and the replica may remain online.

In this patch, we fix the problem by loosening the epoch check on the broker side when a StopReplica request is received. Instead of ignoring the request when the request epoch matches the current epoch, the request will be accepted.

Note, this problem only affects the ZK controller. The integration tests added here nevertheless cover both metadata modes.

Reviewers:  David Jacot <[email protected]>, Justine Olshan <[email protected]>
hachikuji added a commit that referenced this pull request Feb 6, 2023
…tion (#13107)

When a reassignment is cancelled, we need to delete the partition state of adding replicas. Failing to do so causes "stray" replicas which take up disk space and can cause topicId conflicts if the topic is later recreated. Currently, this logic does not work because the leader epoch does not always get bumped after cancellation. Without a leader epoch bump, the replica will ignore StopReplica requests sent by the controller and the replica may remain online.

In this patch, we fix the problem by loosening the epoch check on the broker side when a StopReplica request is received. Instead of ignoring the request when the request epoch matches the current epoch, the request will be accepted.

Note, this problem only affects the ZK controller. The integration tests added here nevertheless cover both metadata modes.

Reviewers:  David Jacot <[email protected]>, Justine Olshan <[email protected]>
showuon pushed a commit that referenced this pull request Jan 26, 2024
After this #13107 PR, an if-else block became unreachable. We need remove it and make the code clean.

Reviewers: Luke Chen <[email protected]>, Divij Vaidya <[email protected]>
yyu1993 pushed a commit to yyu1993/kafka that referenced this pull request Feb 15, 2024
…he#15220)

After this apache#13107 PR, an if-else block became unreachable. We need remove it and make the code clean.

Reviewers: Luke Chen <[email protected]>, Divij Vaidya <[email protected]>
clolov pushed a commit to clolov/kafka that referenced this pull request Apr 5, 2024
…he#15220)

After this apache#13107 PR, an if-else block became unreachable. We need remove it and make the code clean.

Reviewers: Luke Chen <[email protected]>, Divij Vaidya <[email protected]>
Phuc-Hong-Tran pushed a commit to Phuc-Hong-Tran/kafka that referenced this pull request Jun 6, 2024
…he#15220)

After this apache#13107 PR, an if-else block became unreachable. We need remove it and make the code clean.

Reviewers: Luke Chen <[email protected]>, Divij Vaidya <[email protected]>
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.

3 participants