KAFKA-18311: Internal Topic Manager (5/5)#18442
Conversation
|
PTAL @aliehsaeedii |
42f344d to
3ee997b
Compare
3ee997b to
3b195a0
Compare
|
@cadonna I moved the source topic check as you suggested. |
| /** | ||
| * Immutable topic metadata, representing the current state of a topic in the broker. | ||
| * | ||
| * @param id The topic id. |
There was a problem hiding this comment.
nit:
| * @param id The topic id. | |
| * @param id The topic ID. |
| public TopicMetadata( | ||
| Uuid id, | ||
| String name, | ||
| int numPartitions, | ||
| Map<Integer, Set<String>> partitionRacks | ||
| ) { |
There was a problem hiding this comment.
The following is the code style we usually use in Streams and that is more readable IMO.
| public 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) { |
| public static TopicMetadata fromRecord( | ||
| StreamsGroupPartitionMetadataValue.TopicMetadata record | ||
| ) { |
There was a problem hiding this comment.
| public static TopicMetadata fromRecord( | |
| StreamsGroupPartitionMetadataValue.TopicMetadata record | |
| ) { | |
| public static TopicMetadata fromRecord(StreamsGroupPartitionMetadataValue.TopicMetadata record) { |
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithNegativeNumPartitions() { |
There was a problem hiding this comment.
Could you add a test with partition number 0?
This seems a special case that should be documented with a unit test.
There was a problem hiding this comment.
Hmm, actually not sure why the implementation allows this. I changed it to require positive, let's see if it breaks anything.
| public class TopicMetadataTest { | ||
|
|
||
| @Test | ||
| public void testConstructorWithZeroUuid() { |
There was a problem hiding this comment.
A positive constructor unit test is missing.
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology) { |
There was a problem hiding this comment.
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology( | |
| final StreamsGroupTopologyValue.Subtopology subtopology) { | |
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology(final StreamsGroupTopologyValue.Subtopology subtopology) { |
There was a problem hiding this comment.
This will make the line too long, and my IDE (based on imported checkstyle config) will wrap it the same way.... I added another line break.
I didn't know this was an accepted standard in the streams code that everybody follows. Is there something I can do in my IDE to follow this? I imported the official Kafka checkstyle configuration, and it produces this kind of wrapping. It would be good if our "review nitpicking" and automated formatting tools somewhat agree.
There was a problem hiding this comment.
I agree but I do also not know where it comes from. I would put it in one line although it exceeds the 120 characters, but it is also fine as you did it. The best would be to have an automatic formatter, but we never manged in the past to setup one. There was an attempt: #10428 but it was never merged.
| private static ConfiguredInternalTopic fromPersistedTopicInfo( | ||
| final StreamsGroupTopologyValue.TopicInfo topicInfo, | ||
| Map<String, Integer> decidedPartitionCountsForInternalTopics) { |
There was a problem hiding this comment.
| private static ConfiguredInternalTopic fromPersistedTopicInfo( | |
| final StreamsGroupTopologyValue.TopicInfo topicInfo, | |
| Map<String, Integer> decidedPartitionCountsForInternalTopics) { | |
| private static ConfiguredInternalTopic fromPersistedTopicInfo(final StreamsGroupTopologyValue.TopicInfo topicInfo, | |
| final Map<String, Integer> decidedPartitionCountsForInternalTopics) { |
| private static ConfiguredSubtopology fromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology, | ||
| Map<String, Integer> decidedPartitionCountsForInternalTopics | ||
| ) { |
There was a problem hiding this comment.
| private static ConfiguredSubtopology fromPersistedSubtopology( | |
| final StreamsGroupTopologyValue.Subtopology subtopology, | |
| Map<String, Integer> decidedPartitionCountsForInternalTopics | |
| ) { | |
| private static ConfiguredSubtopology fromPersistedSubtopology(final StreamsGroupTopologyValue.Subtopology subtopology, | |
| final Map<String, Integer> decidedPartitionCountsForInternalTopics | |
| ) { |
| final Set<String> fixedRepartitionTopics = | ||
| topology.subtopologies().values().stream().flatMap(x -> | ||
| x.repartitionSourceTopics().stream().filter(y -> y.partitions() != 0) | ||
| ).map(StreamsGroupTopologyValue.TopicInfo::name).collect(Collectors.toSet()); | ||
| final Set<String> flexibleRepartitionTopics = | ||
| topology.subtopologies().values().stream().flatMap(x -> | ||
| x.repartitionSourceTopics().stream().filter(y -> y.partitions() == 0) | ||
| ).map(StreamsGroupTopologyValue.TopicInfo::name).collect(Collectors.toSet()); | ||
|
|
||
| if (fixedRepartitionTopics.isEmpty() && flexibleRepartitionTopics.isEmpty()) { | ||
| log.info("Skipping the repartition topic validation since there are no repartition topics."); | ||
| } else { | ||
| // ensure the co-partitioning topics within the group have the same number of partitions, | ||
| // and enforce the number of partitions for those repartition topics to be the same if they | ||
| // are co-partitioned as well. | ||
| for (Collection<Set<String>> copartitionGroups : copartitionGroupsBySubtopology.values()) { | ||
| for (Set<String> copartitionGroup : copartitionGroups) { | ||
| decidedPartitionCountsForInternalTopics.putAll( | ||
| copartitionedTopicsEnforcer.enforce(copartitionGroup, fixedRepartitionTopics, flexibleRepartitionTopics)); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Maybe export this block into a private method, so that we have each of repartition topics setup, co-partition enforcer, and changelog topcis setup in one line. Just a proposal.
| public TopicMetadata( | ||
| Uuid id, | ||
| String name, | ||
| int numPartitions, | ||
| Map<Integer, Set<String>> partitionRacks | ||
| ) { |
| /** | ||
| * Immutable topic metadata, representing the current state of a topic in the broker. | ||
| * | ||
| * @param id The topic id. |
| public static TopicMetadata fromRecord( | ||
| StreamsGroupPartitionMetadataValue.TopicMetadata record | ||
| ) { |
| final Set<String> fixedRepartitionTopics = | ||
| topology.subtopologies().values().stream().flatMap(x -> | ||
| x.repartitionSourceTopics().stream().filter(y -> y.partitions() != 0) | ||
| ).map(StreamsGroupTopologyValue.TopicInfo::name).collect(Collectors.toSet()); | ||
| final Set<String> flexibleRepartitionTopics = | ||
| topology.subtopologies().values().stream().flatMap(x -> | ||
| x.repartitionSourceTopics().stream().filter(y -> y.partitions() == 0) | ||
| ).map(StreamsGroupTopologyValue.TopicInfo::name).collect(Collectors.toSet()); | ||
|
|
||
| if (fixedRepartitionTopics.isEmpty() && flexibleRepartitionTopics.isEmpty()) { | ||
| log.info("Skipping the repartition topic validation since there are no repartition topics."); | ||
| } else { | ||
| // ensure the co-partitioning topics within the group have the same number of partitions, | ||
| // and enforce the number of partitions for those repartition topics to be the same if they | ||
| // are co-partitioned as well. | ||
| for (Collection<Set<String>> copartitionGroups : copartitionGroupsBySubtopology.values()) { | ||
| for (Set<String> copartitionGroup : copartitionGroups) { | ||
| decidedPartitionCountsForInternalTopics.putAll( | ||
| copartitionedTopicsEnforcer.enforce(copartitionGroup, fixedRepartitionTopics, flexibleRepartitionTopics)); | ||
| } | ||
| } | ||
| } |
| private static ConfiguredSubtopology fromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology, | ||
| Map<String, Integer> decidedPartitionCountsForInternalTopics | ||
| ) { |
| private static ConfiguredInternalTopic fromPersistedTopicInfo( | ||
| final StreamsGroupTopologyValue.TopicInfo topicInfo, | ||
| Map<String, Integer> decidedPartitionCountsForInternalTopics) { |
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology) { |
There was a problem hiding this comment.
This will make the line too long, and my IDE (based on imported checkstyle config) will wrap it the same way.... I added another line break.
I didn't know this was an accepted standard in the streams code that everybody follows. Is there something I can do in my IDE to follow this? I imported the official Kafka checkstyle configuration, and it produces this kind of wrapping. It would be good if our "review nitpicking" and automated formatting tools somewhat agree.
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithNegativeNumPartitions() { |
There was a problem hiding this comment.
Hmm, actually not sure why the implementation allows this. I changed it to require positive, let's see if it breaks anything.
| public class TopicMetadataTest { | ||
|
|
||
| @Test | ||
| public void testConstructorWithZeroUuid() { |
cadonna
left a comment
There was a problem hiding this comment.
Thanks for the updates!
I had just one very minor comment. I leave it to you whether you want to change that or not.
| enforceCopartitioning(topology, copartitionGroupsBySubtopology, log, | ||
| decidedPartitionCountsForInternalTopics, copartitionedTopicsEnforcer); |
There was a problem hiding this comment.
nit:
| enforceCopartitioning(topology, copartitionGroupsBySubtopology, log, | |
| decidedPartitionCountsForInternalTopics, copartitionedTopicsEnforcer); | |
| enforceCopartitioning( | |
| topology, | |
| copartitionGroupsBySubtopology, | |
| log, | |
| decidedPartitionCountsForInternalTopics, | |
| copartitionedTopicsEnforcer | |
| ); |
documented here: https://kafka.apache.org/coding-guide
There are always exceptions like log-messages.
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology) { |
There was a problem hiding this comment.
I agree but I do also not know where it comes from. I would put it in one line although it exceeds the 120 characters, but it is also fine as you did it. The best would be to have an automatic formatter, but we never manged in the past to setup one. There was an attempt: #10428 but it was never merged.
The internal topic manager takes a requested topology and returns a configured topology, as well as any internal topics that need to be created. Shares with the client-side "InternalTopicManager" the name only. Reviewers: Bruno Cadonna <cadonna@apache.org>
The internal topic manager takes a requested topology and returns a configured topology, as well as any internal topics that need to be created. Shares with the client-side "InternalTopicManager" the name only. Reviewers: Bruno Cadonna <cadonna@apache.org>
The internal topic manager takes a requested topology and returns a configured topology, as well as any internal topics that need to be created. Shares with the client-side "InternalTopicManager" the name only. Reviewers: Bruno Cadonna <cadonna@apache.org>
The internal topic manager takes a requested topology and returns a configured topology, as well as any internal topics that need to be created.
Shares with the client-side "InternalTopicManager" the name only.
Committer Checklist (excluded from commit message)