-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-6630: Speed up the processing of TopicDeletionStopReplicaResponseReceived events on the controller #4668
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
Merged
junrao
merged 3 commits into
apache:trunk
from
gitlw:speedup_processing_stop_replica_response
Mar 30, 2018
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,14 +31,46 @@ class ControllerContext { | |
| var epoch: Int = KafkaController.InitialControllerEpoch - 1 | ||
| var epochZkVersion: Int = KafkaController.InitialControllerEpochZkVersion - 1 | ||
| var allTopics: Set[String] = Set.empty | ||
| var partitionReplicaAssignment: mutable.Map[TopicPartition, Seq[Int]] = mutable.Map.empty | ||
| var partitionLeadershipInfo: mutable.Map[TopicPartition, LeaderIsrAndControllerEpoch] = mutable.Map.empty | ||
| private var partitionReplicaAssignmentUnderlying: mutable.Map[String, mutable.Map[Int, Seq[Int]]] = mutable.Map.empty | ||
| val partitionLeadershipInfo: mutable.Map[TopicPartition, LeaderIsrAndControllerEpoch] = mutable.Map.empty | ||
| val partitionsBeingReassigned: mutable.Map[TopicPartition, ReassignedPartitionsContext] = mutable.Map.empty | ||
| val replicasOnOfflineDirs: mutable.Map[Int, Set[TopicPartition]] = mutable.Map.empty | ||
|
|
||
| private var liveBrokersUnderlying: Set[Broker] = Set.empty | ||
| private var liveBrokerIdsUnderlying: Set[Int] = Set.empty | ||
|
|
||
| def partitionReplicaAssignment(topicPartition: TopicPartition) : Seq[Int] = { | ||
| partitionReplicaAssignmentUnderlying.getOrElse(topicPartition.topic, mutable.Map.empty) | ||
| .getOrElse(topicPartition.partition, Seq.empty) | ||
| } | ||
|
|
||
| def clearTopicsState(): Unit = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be private?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| allTopics = Set.empty | ||
| partitionReplicaAssignmentUnderlying.clear() | ||
| partitionLeadershipInfo.clear() | ||
| partitionsBeingReassigned.clear() | ||
| replicasOnOfflineDirs.clear() | ||
| } | ||
|
|
||
| def updatePartitionReplicaAssignment(topicPartition: TopicPartition, newReplicas: Seq[Int]) : Unit = { | ||
| partitionReplicaAssignmentUnderlying.getOrElseUpdate(topicPartition.topic, mutable.Map.empty) | ||
| .put(topicPartition.partition, newReplicas) | ||
| } | ||
|
|
||
| def partitionReplicaAssignmentForTopic(topic : String) : Map[TopicPartition, Seq[Int]] = { | ||
| partitionReplicaAssignmentUnderlying.getOrElse(topic, Map.empty).map { | ||
| case (partition, replicas) => (new TopicPartition(topic, partition), replicas) | ||
| }.toMap | ||
| } | ||
|
|
||
| def allPartitions : Set[TopicPartition] = { | ||
| partitionReplicaAssignmentUnderlying.flatMap { | ||
| case (topic, topicReplicaAssignment) => topicReplicaAssignment.map { | ||
| case (partition, _) => new TopicPartition(topic, partition) | ||
| } | ||
| }.toSet | ||
| } | ||
|
|
||
| // setter | ||
| def liveBrokers_=(brokers: Set[Broker]) { | ||
| liveBrokersUnderlying = brokers | ||
|
|
@@ -53,8 +85,12 @@ class ControllerContext { | |
| def liveOrShuttingDownBrokers = liveBrokersUnderlying | ||
|
|
||
| def partitionsOnBroker(brokerId: Int): Set[TopicPartition] = { | ||
| partitionReplicaAssignment.collect { | ||
| case (topicPartition, replicas) if replicas.contains(brokerId) => topicPartition | ||
| partitionReplicaAssignmentUnderlying.flatMap { | ||
| case (topic, topicReplicaAssignment) => topicReplicaAssignment.filter { | ||
| case (_, replicas) => replicas.contains(brokerId) | ||
| }.map { | ||
| case (partition, _) => new TopicPartition(topic, partition) | ||
| } | ||
| }.toSet | ||
| } | ||
|
|
||
|
|
@@ -68,22 +104,26 @@ class ControllerContext { | |
|
|
||
| def replicasOnBrokers(brokerIds: Set[Int]): Set[PartitionAndReplica] = { | ||
| brokerIds.flatMap { brokerId => | ||
| partitionReplicaAssignment.collect { case (topicPartition, replicas) if replicas.contains(brokerId) => | ||
| PartitionAndReplica(topicPartition, brokerId) | ||
| partitionReplicaAssignmentUnderlying.flatMap { | ||
| case (topic, topicReplicaAssignment) => topicReplicaAssignment.collect { | ||
| case (partition, replicas) if replicas.contains(brokerId) => | ||
| PartitionAndReplica(new TopicPartition(topic, partition), brokerId) | ||
| } | ||
| } | ||
| }.toSet | ||
| } | ||
| } | ||
|
|
||
| def replicasForTopic(topic: String): Set[PartitionAndReplica] = { | ||
| partitionReplicaAssignment | ||
| .filter { case (topicPartition, _) => topicPartition.topic == topic } | ||
| .flatMap { case (topicPartition, replicas) => | ||
| replicas.map(PartitionAndReplica(topicPartition, _)) | ||
| }.toSet | ||
| partitionReplicaAssignmentUnderlying.getOrElse(topic, mutable.Map.empty).flatMap { | ||
| case (partition, replicas) => replicas.map(r => PartitionAndReplica(new TopicPartition(topic, partition), r)) | ||
| }.toSet | ||
| } | ||
|
|
||
| def partitionsForTopic(topic: String): collection.Set[TopicPartition] = | ||
| partitionReplicaAssignment.keySet.filter(topicPartition => topicPartition.topic == topic) | ||
| def partitionsForTopic(topic: String): collection.Set[TopicPartition] = { | ||
| partitionReplicaAssignmentUnderlying.getOrElse(topic, mutable.Map.empty).map { | ||
| case (partition, _) => new TopicPartition(topic, partition) | ||
| }.toSet | ||
| } | ||
|
|
||
| def allLiveReplicas(): Set[PartitionAndReplica] = { | ||
| replicasOnBrokers(liveBrokerIds).filter { partitionAndReplica => | ||
|
|
@@ -98,10 +138,24 @@ class ControllerContext { | |
| } | ||
| } | ||
|
|
||
| def resetContext() : Unit = { | ||
| if (controllerChannelManager != null) { | ||
| controllerChannelManager.shutdown() | ||
| controllerChannelManager = null | ||
| } | ||
| shuttingDownBrokerIds.clear() | ||
| epoch = 0 | ||
| epochZkVersion = 0 | ||
| clearTopicsState() | ||
| liveBrokers = Set.empty | ||
| } | ||
|
|
||
| def removeTopic(topic: String) = { | ||
| partitionLeadershipInfo = partitionLeadershipInfo.filter { case (topicPartition, _) => topicPartition.topic != topic } | ||
| partitionReplicaAssignment = partitionReplicaAssignment.filter { case (topicPartition, _) => topicPartition.topic != topic } | ||
| allTopics -= topic | ||
| partitionReplicaAssignmentUnderlying.remove(topic) | ||
| partitionLeadershipInfo.foreach { | ||
| case (topicPartition, _) if topicPartition.topic == topic => partitionLeadershipInfo.remove(topicPartition) | ||
| case _ => | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove the space before : Seq[Int] and some other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.