-
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 |
|---|---|---|
|
|
@@ -148,6 +148,19 @@ private static Map<String, Integer> decidePartitionCounts(final LogContext logCo | |
|
|
||
| decidedPartitionCountsForInternalTopics.putAll(repartitionTopics.setup()); | ||
|
|
||
| enforceCopartitioning(topology, copartitionGroupsBySubtopology, log, | ||
| decidedPartitionCountsForInternalTopics, copartitionedTopicsEnforcer); | ||
|
|
||
| decidedPartitionCountsForInternalTopics.putAll(changelogTopics.setup()); | ||
|
|
||
| return decidedPartitionCountsForInternalTopics; | ||
| } | ||
|
|
||
| private static void enforceCopartitioning(final StreamsTopology topology, | ||
| final Map<String, Collection<Set<String>>> copartitionGroupsBySubtopology, | ||
| final Logger log, | ||
| final Map<String, Integer> decidedPartitionCountsForInternalTopics, | ||
| final CopartitionedTopicsEnforcer copartitionedTopicsEnforcer) { | ||
| final Set<String> fixedRepartitionTopics = | ||
| topology.subtopologies().values().stream().flatMap(x -> | ||
| x.repartitionSourceTopics().stream().filter(y -> y.partitions() != 0) | ||
|
|
@@ -170,10 +183,6 @@ private static Map<String, Integer> decidePartitionCounts(final LogContext logCo | |
| } | ||
| } | ||
| } | ||
|
Comment on lines
+169
to
+190
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. 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.
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 |
||
|
|
||
| decidedPartitionCountsForInternalTopics.putAll(changelogTopics.setup()); | ||
|
|
||
| return decidedPartitionCountsForInternalTopics; | ||
| } | ||
|
|
||
| private static Map<String, CreatableTopic> missingInternalTopics(Map<String, ConfiguredSubtopology> subtopologyMap, | ||
|
|
@@ -241,9 +250,8 @@ private static CreatableTopic toCreatableTopic(final ConfiguredInternalTopic con | |
| return creatableTopic; | ||
| } | ||
|
|
||
| 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 | ||
| ) { | ||
| return new ConfiguredSubtopology( | ||
| new HashSet<>(subtopology.sourceTopics()), | ||
|
|
@@ -257,9 +265,8 @@ private static ConfiguredSubtopology fromPersistedSubtopology( | |
| ); | ||
| } | ||
|
|
||
| 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) { | ||
| if (topicInfo.partitions() == 0 && !decidedPartitionCountsForInternalTopics.containsKey(topicInfo.name())) { | ||
| throw new IllegalStateException("Number of partitions must be set for topic " + topicInfo.name()); | ||
| } | ||
|
|
@@ -277,7 +284,8 @@ private static ConfiguredInternalTopic fromPersistedTopicInfo( | |
| } | ||
|
|
||
| private static Collection<Set<String>> copartitionGroupsFromPersistedSubtopology( | ||
| final StreamsGroupTopologyValue.Subtopology subtopology) { | ||
| final StreamsGroupTopologyValue.Subtopology subtopology | ||
| ) { | ||
| return subtopology.copartitionGroups().stream().map(copartitionGroup -> | ||
| Stream.concat( | ||
| copartitionGroup.sourceTopics().stream() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,18 @@ | |
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| public class TopicMetadataTest { | ||
|
|
||
| @Test | ||
| public void testConstructor() { | ||
| assertDoesNotThrow(() -> | ||
| new TopicMetadata(Uuid.randomUuid(), "valid-topic", 3, new HashMap<>())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithZeroUuid() { | ||
|
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. A positive constructor unit test is missing.
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 |
||
| Exception exception = assertThrows(IllegalArgumentException.class, () -> | ||
|
|
@@ -57,11 +64,18 @@ public void testConstructorWithEmptyName() { | |
| assertEquals("Topic name cannot be empty.", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithZeroNumPartitions() { | ||
| Exception exception = assertThrows(IllegalArgumentException.class, () -> | ||
| new TopicMetadata(Uuid.randomUuid(), "valid-topic", 0, new HashMap<>())); | ||
| assertEquals("Number of partitions must be positive.", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorWithNegativeNumPartitions() { | ||
|
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. Could you add a test with partition number 0?
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. Hmm, actually not sure why the implementation allows this. I changed it to require positive, let's see if it breaks anything. |
||
| Exception exception = assertThrows(IllegalArgumentException.class, () -> | ||
| new TopicMetadata(Uuid.randomUuid(), "valid-topic", -1, new HashMap<>())); | ||
| assertEquals("Number of partitions cannot be negative.", exception.getMessage()); | ||
| assertEquals("Number of partitions must be positive.", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
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:
documented here: https://kafka.apache.org/coding-guide
There are always exceptions like log-messages.
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