-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-18311: Internal Topic Manager (5/5) #18442
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 1 commit
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||||||||||||||
| /* | ||||||||||||||||||||||
| * 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 org.apache.kafka.coordinator.group.streams; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import org.apache.kafka.common.Uuid; | ||||||||||||||||||||||
| import org.apache.kafka.coordinator.group.generated.StreamsGroupPartitionMetadataValue; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||
| import java.util.Objects; | ||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Immutable topic metadata, representing the current state of a topic in the broker. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @param id The topic id. | ||||||||||||||||||||||
| * @param name The topic name. | ||||||||||||||||||||||
| * @param numPartitions The number of partitions. | ||||||||||||||||||||||
| * @param partitionRacks Map of every partition ID to a set of its rack IDs, if they exist. If rack information is unavailable for all | ||||||||||||||||||||||
| * partitions, this is an empty map. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public record TopicMetadata(Uuid id, String name, int numPartitions, Map<Integer, Set<String>> partitionRacks) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public TopicMetadata( | ||||||||||||||||||||||
| Uuid id, | ||||||||||||||||||||||
| String name, | ||||||||||||||||||||||
| int numPartitions, | ||||||||||||||||||||||
| Map<Integer, Set<String>> partitionRacks | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
|
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. The following is the code style we usually use in Streams and that is more readable IMO.
Suggested change
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. Done |
||||||||||||||||||||||
| this.id = Objects.requireNonNull(id); | ||||||||||||||||||||||
| if (Uuid.ZERO_UUID.equals(id)) { | ||||||||||||||||||||||
| throw new IllegalArgumentException("Topic id cannot be ZERO_UUID."); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| this.name = Objects.requireNonNull(name); | ||||||||||||||||||||||
| if (name.isEmpty()) { | ||||||||||||||||||||||
| throw new IllegalArgumentException("Topic name cannot be empty."); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| this.numPartitions = numPartitions; | ||||||||||||||||||||||
| if (numPartitions < 0) { | ||||||||||||||||||||||
| throw new IllegalArgumentException("Number of partitions cannot be negative."); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| this.partitionRacks = Objects.requireNonNull(partitionRacks); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public static TopicMetadata fromRecord( | ||||||||||||||||||||||
| StreamsGroupPartitionMetadataValue.TopicMetadata record | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
|
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.
Suggested change
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. Done |
||||||||||||||||||||||
| // Converting the data type from a list stored in the record to a map for the topic metadata. | ||||||||||||||||||||||
| Map<Integer, Set<String>> partitionRacks = new HashMap<>(); | ||||||||||||||||||||||
| for (StreamsGroupPartitionMetadataValue.PartitionMetadata partitionMetadata : record.partitionMetadata()) { | ||||||||||||||||||||||
| partitionRacks.put( | ||||||||||||||||||||||
| partitionMetadata.partition(), | ||||||||||||||||||||||
| Set.copyOf(partitionMetadata.racks()) | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return new TopicMetadata( | ||||||||||||||||||||||
| record.topicId(), | ||||||||||||||||||||||
| record.topicName(), | ||||||||||||||||||||||
| record.numPartitions(), | ||||||||||||||||||||||
| partitionRacks); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
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.
nit:
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.
Done