-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-14458: Introduce RPC support during ZK migration #13028
Add infrastructure for sending UpdateMetadataRequest and LeaderAndIsr RPCs during the migration process from ZK to KRaft. The new classes use ControllerChannelManager to send the RPCs. The information to send comes from MetadataDelta and MetadataImage. Reviewers: David Arthur <mumrah@gmail.com>, Colin P. McCabe <cmccabe@apache.org>
- Loading branch information
1 parent
ef3b581
commit 0e51a20
Showing
17 changed files
with
763 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
core/src/main/scala/kafka/controller/ControllerChannelContext.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package kafka.controller | ||
|
||
import kafka.cluster.Broker | ||
import org.apache.kafka.common.{TopicPartition, Uuid} | ||
|
||
trait ControllerChannelContext { | ||
def isTopicDeletionInProgress(topicName: String): Boolean | ||
|
||
def topicIds: collection.Map[String, Uuid] | ||
|
||
def liveBrokerIdAndEpochs: collection.Map[Int, Long] | ||
|
||
def liveOrShuttingDownBrokers: collection.Set[Broker] | ||
|
||
def isTopicQueuedUpForDeletion(topic: String): Boolean | ||
|
||
def isReplicaOnline(brokerId: Int, partition: TopicPartition): Boolean | ||
|
||
def partitionReplicaAssignment(partition: TopicPartition): collection.Seq[Int] | ||
|
||
def leaderEpoch(topicPartition: TopicPartition): Int | ||
|
||
def liveOrShuttingDownBrokerIds: collection.Set[Int] | ||
|
||
def partitionLeadershipInfo(topicPartition: TopicPartition): Option[LeaderIsrAndControllerEpoch] | ||
} |
243 changes: 146 additions & 97 deletions
243
core/src/main/scala/kafka/controller/ControllerChannelManager.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
115 changes: 115 additions & 0 deletions
115
core/src/main/scala/kafka/migration/MigrationControllerChannelContext.scala
This file contains 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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package kafka.migration | ||
|
||
import kafka.api.LeaderAndIsr | ||
import kafka.cluster.Broker | ||
import kafka.controller.{ControllerChannelContext, LeaderIsrAndControllerEpoch} | ||
import org.apache.kafka.common.{TopicPartition, Uuid} | ||
import org.apache.kafka.image.MetadataImage | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
object MigrationControllerChannelContext { | ||
def isReplicaOnline(image: MetadataImage, brokerId: Int, replicaAssignment: Set[Int]): Boolean = { | ||
val brokerOnline = image.cluster().containsBroker(brokerId) | ||
brokerOnline && replicaAssignment.contains(brokerId) | ||
} | ||
|
||
def partitionReplicaAssignment(image: MetadataImage, tp: TopicPartition): collection.Seq[Int] = { | ||
image.topics().topicsByName().asScala.get(tp.topic()) match { | ||
case Some(topic) => topic.partitions().asScala.get(tp.partition()) match { | ||
case Some(partition) => partition.replicas.toSeq | ||
case None => collection.Seq.empty | ||
} | ||
case None => collection.Seq.empty | ||
} | ||
} | ||
|
||
def partitionLeadershipInfo(image: MetadataImage, topicPartition: TopicPartition): Option[LeaderIsrAndControllerEpoch] = { | ||
image.topics().topicsByName().asScala.get(topicPartition.topic()) match { | ||
case Some(topic) => topic.partitions().asScala.get(topicPartition.partition()) match { | ||
case Some(partition) => | ||
val leaderAndIsr = LeaderAndIsr(partition.leader, partition.leaderEpoch, partition.isr.toList, | ||
partition.leaderRecoveryState, partition.partitionEpoch) | ||
Some(LeaderIsrAndControllerEpoch(leaderAndIsr, image.highestOffsetAndEpoch().epoch())) | ||
case None => None | ||
} | ||
case None => None | ||
} | ||
} | ||
} | ||
|
||
sealed class MigrationControllerChannelContext( | ||
val image: MetadataImage | ||
) extends ControllerChannelContext { | ||
override def isTopicDeletionInProgress(topicName: String): Boolean = { | ||
!image.topics().topicsByName().containsKey(topicName) | ||
} | ||
|
||
override val topicIds: collection.Map[String, Uuid] = { | ||
image.topics().topicsByName().asScala.map { | ||
case (name, topic) => name -> topic.id() | ||
}.toMap | ||
} | ||
|
||
override val liveBrokerIdAndEpochs: collection.Map[Int, Long] = { | ||
image.cluster().zkBrokers().asScala.map { | ||
case (brokerId, broker) => brokerId.intValue() -> broker.epoch() | ||
} | ||
} | ||
|
||
override val liveOrShuttingDownBrokers: collection.Set[Broker] = { | ||
image.cluster().zkBrokers().asScala.values.map { registration => | ||
Broker.fromBrokerRegistration(registration) | ||
}.toSet | ||
} | ||
|
||
override def isTopicQueuedUpForDeletion(topic: String): Boolean = { | ||
!image.topics().topicsByName().containsKey(topic) | ||
} | ||
|
||
override def isReplicaOnline(brokerId: Int, partition: TopicPartition): Boolean = { | ||
MigrationControllerChannelContext.isReplicaOnline( | ||
image, brokerId, partitionReplicaAssignment(partition).toSet) | ||
} | ||
|
||
override def partitionReplicaAssignment(tp: TopicPartition): collection.Seq[Int] = { | ||
MigrationControllerChannelContext.partitionReplicaAssignment(image, tp) | ||
} | ||
|
||
override def leaderEpoch(topicPartition: TopicPartition): Int = { | ||
// Topic is deleted use a special sentinel -2 to the indicate the same. | ||
if (isTopicQueuedUpForDeletion(topicPartition.topic())) { | ||
LeaderAndIsr.EpochDuringDelete | ||
} else { | ||
image.topics().topicsByName.asScala.get(topicPartition.topic()) match { | ||
case Some(topic) => topic.partitions().asScala.get(topicPartition.partition()) match { | ||
case Some(partition) => partition.leaderEpoch | ||
case None => LeaderAndIsr.NoEpoch | ||
} | ||
case None => LeaderAndIsr.NoEpoch | ||
} | ||
} | ||
} | ||
|
||
override val liveOrShuttingDownBrokerIds: collection.Set[Int] = liveBrokerIdAndEpochs.keySet | ||
|
||
override def partitionLeadershipInfo(topicPartition: TopicPartition): Option[LeaderIsrAndControllerEpoch] = { | ||
MigrationControllerChannelContext.partitionLeadershipInfo(image, topicPartition) | ||
} | ||
} |
Oops, something went wrong.