Skip to content

KAFKA-12403; Ensure local state deleted on RemoveTopicRecord received#10252

Merged
hachikuji merged 7 commits into
apache:trunkfrom
hachikuji:KAFKA-12403
Mar 8, 2021
Merged

KAFKA-12403; Ensure local state deleted on RemoveTopicRecord received#10252
hachikuji merged 7 commits into
apache:trunkfrom
hachikuji:KAFKA-12403

Conversation

@hachikuji

@hachikuji hachikuji commented Mar 3, 2021

Copy link
Copy Markdown
Contributor

This patch implements additional handling logic for RemoveTopic records:

  • Update MetadataPartitions to ensure addition of deleted partitions to localRemoved set
  • Ensure topic configs are removed from ConfigRepository
  • Propagate deleted partitions to GroupCoordinator so that corresponding offset commits can be removed

This patch also changes the controller topic id generation logic to use Uuid.randomUuid rather than Random.

Committer Checklist (excluded from commit message)

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

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hachikuji Thanks for this fix. a couple of comments. Please take a look.

Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala
record.asInstanceOf[RemoveTopicRecord])
case QUOTA_RECORD => handleQuotaRecord(imageBuilder,
record.asInstanceOf[QuotaRecord])
// TODO: handle FEATURE_LEVEL_RECORD

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this TODO no longer relevant?

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hachikuji thanks for your response and updates. Left some questions for this PR.


private def maybeAddToLocalRemoved(partition: MetadataPartition): Unit = {
if (partition.isReplicaFor(brokerId)) {
val currentTopicId = newReverseIdMap.get(partition.topicName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible that newReverseIdMap has no related id? For example, PartitionRecord is processed before TopicRecord or TopicRecord was discarded (due to error)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For another, could it be replaced by prevPartitions.contains(partition.topicName)? It seems all we want to check is the existence of topic name in previous image.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The intent is to only return the change in _localRemoved if the topic existed in the previous image. If we only check topic name, then successive deletions and recreations might leave some partitions in _localRemoved that were not in the previous image.

It's worth noting that this is strictly more defensive than the current replay logic requires. A new image is built for each batch of records from the controller, and we would never see a topic deleted and recreated (or vice versa) in the same batch. This is an implicit contract though and not protected by the builder API, so I thought we might as well try to make the logic more resilient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for nice explanation. I have another question for this check. It seems to me three collections in prevPartitions should be consistent. For example: a topic which exists one of collection should also exists in other two (vice versa). If above comment is right, why we need this if-else? Calling prevPartitions.contains(partition.topicName) appears to be enough?

Comment thread core/src/test/scala/kafka/server/metadata/MetadataPartitionsTest.scala Outdated
@hachikuji

Copy link
Copy Markdown
Contributor Author

I am working on some integration tests here. Hopefully then we can wrap this up.

@hachikuji

Copy link
Copy Markdown
Contributor Author

Well, I was going to write some integration tests, but it seems we are still awaiting some infrastructure for that. I tested it out manually and it works correctly. I see the brokers deleting the partition data as expected. I tested deletion as well as recreation.

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hachikuji thanks for updating code. a couple of comments are left. Otherwise, LGTM.

Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala Outdated
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala
Comment thread core/src/main/scala/kafka/server/metadata/MetadataPartitions.scala

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for this nice patch. LGTM. one trivial question is left.

import scala.collection.mutable
import scala.jdk.CollectionConverters._

class BrokerMetadataListenerTest {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems not all messages are covered in this class? If so, is there a jira to complete those test cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hachikuji
hachikuji merged commit 31a121c into apache:trunk Mar 8, 2021
hachikuji added a commit that referenced this pull request Mar 8, 2021
…ed (#10252)

This patch implements additional handling logic for `RemoveTopic` records:

- Update `MetadataPartitions` to ensure addition of deleted partitions to `localRemoved` set
- Ensure topic configs are removed from `ConfigRepository`
- Propagate deleted partitions to `GroupCoordinator` so that corresponding offset commits can be removed

This patch also changes the controller topic id generation logic to use `Uuid.randomUuid` rather than `Random`.

Reviewers: Ismael Juma <ismael@juma.me.uk>, Chia-Ping Tsai <chia7712@gmail.com>
@ijuma ijuma added the kraft label Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants