-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10869: Gate topic IDs behind IBP 2.8 #9814
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
Changes from all commits
aec8237
8ff7be2
ff68a4d
ae5ec05
6b4c1c0
deb3123
12ca62e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,15 +47,17 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging { | |
| * @param replicationFactor Replication factor | ||
| * @param topicConfig topic configs | ||
| * @param rackAwareMode | ||
| * @param usesTopicId Boolean indicating whether the topic ID will be created | ||
| */ | ||
| def createTopic(topic: String, | ||
| partitions: Int, | ||
| replicationFactor: Int, | ||
| topicConfig: Properties = new Properties, | ||
| rackAwareMode: RackAwareMode = RackAwareMode.Enforced): Unit = { | ||
| rackAwareMode: RackAwareMode = RackAwareMode.Enforced, | ||
| usesTopicId: Boolean = false): Unit = { | ||
| val brokerMetadatas = getBrokerMetadatas(rackAwareMode) | ||
| val replicaAssignment = AdminUtils.assignReplicasToBrokers(brokerMetadatas, partitions, replicationFactor) | ||
| createTopicWithAssignment(topic, topicConfig, replicaAssignment) | ||
| createTopicWithAssignment(topic, topicConfig, replicaAssignment, usesTopicId = usesTopicId) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -90,11 +92,13 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging { | |
| * @param config The config of the topic | ||
| * @param partitionReplicaAssignment The assignments of the topic | ||
| * @param validate Boolean indicating if parameters must be validated or not (true by default) | ||
| * @param usesTopicId Boolean indicating whether the topic ID will be created | ||
| */ | ||
| def createTopicWithAssignment(topic: String, | ||
| config: Properties, | ||
| partitionReplicaAssignment: Map[Int, Seq[Int]], | ||
| validate: Boolean = true): Unit = { | ||
| validate: Boolean = true, | ||
| usesTopicId: Boolean = false): Unit = { | ||
| if (validate) | ||
| validateTopicCreate(topic, partitionReplicaAssignment, config) | ||
|
|
||
|
|
@@ -106,7 +110,7 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging { | |
|
|
||
| // create the partition assignment | ||
| writeTopicPartitionAssignment(topic, partitionReplicaAssignment.map { case (k, v) => k -> ReplicaAssignment(v) }, | ||
| isUpdate = false) | ||
| isUpdate = false, usesTopicId) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -153,16 +157,17 @@ class AdminZkClient(zkClient: KafkaZkClient) extends Logging { | |
| LogConfig.validate(config) | ||
| } | ||
|
|
||
| private def writeTopicPartitionAssignment(topic: String, replicaAssignment: Map[Int, ReplicaAssignment], isUpdate: Boolean): Unit = { | ||
| private def writeTopicPartitionAssignment(topic: String, replicaAssignment: Map[Int, ReplicaAssignment], | ||
| isUpdate: Boolean, usesTopicId: Boolean = false): Unit = { | ||
|
Member
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. Why do you set the default value to false? I don't think we should give it a default value since the caller can decide it by caller.
Member
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. Some places that eventually call this do not have access to IBP. The controller will eventually pick up and assign topic IDs that need them. |
||
| try { | ||
| val assignment = replicaAssignment.map { case (partitionId, replicas) => (new TopicPartition(topic,partitionId), replicas) }.toMap | ||
|
|
||
| if (!isUpdate) { | ||
| val topicId = Uuid.randomUuid() | ||
| zkClient.createTopicAssignment(topic, topicId, assignment.map { case (k, v) => k -> v.replicas }) | ||
| val topicIdOpt = if (usesTopicId) Some(Uuid.randomUuid()) else None | ||
| zkClient.createTopicAssignment(topic, topicIdOpt, assignment.map { case (k, v) => k -> v.replicas }) | ||
| } else { | ||
| val topicIds = zkClient.getTopicIdsForTopics(Set(topic)) | ||
| zkClient.setTopicAssignment(topic, topicIds(topic), assignment) | ||
| zkClient.setTopicAssignment(topic, topicIds.get(topic), assignment) | ||
| } | ||
| debug("Updated path %s with %s for replica assignment".format(TopicZNode.path(topic), assignment)) | ||
| } catch { | ||
|
|
||
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.
So if we use
TopicCommandwithZookeeperTopicServiceto create a topic, we will always not set a topicId?Uh oh!
There was an error while loading. Please reload this page.
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.
Initially yes. The controller will process and add topic IDs to these topics if IBP is at least 2.8 in processTopicChange() using the processTopicIds method.