-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: further InternalTopologyBuilder cleanup #8046
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
28bc575
fbd9fcf
39a8224
4a42c57
d61a5f7
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 |
|---|---|---|
|
|
@@ -118,9 +118,9 @@ public class InternalTopologyBuilder { | |
|
|
||
| private String applicationId = null; | ||
|
|
||
| private Pattern topicPattern = null; | ||
| private Pattern sourceTopicPattern = null; | ||
|
|
||
| private List<String> topicCollection = null; | ||
| private List<String> sourceTopicCollection = null; | ||
|
|
||
| private Map<Integer, Set<String>> nodeGroups = null; | ||
|
|
||
|
|
@@ -790,23 +790,18 @@ private int putNodeGroupName(final String nodeName, | |
| } | ||
|
|
||
| public synchronized ProcessorTopology build() { | ||
| return build((Integer) null); | ||
| final Set<String> nodeGroup = new HashSet<>(); | ||
| for (final Set<String> value : nodeGroups().values()) { | ||
| nodeGroup.addAll(value); | ||
| } | ||
| nodeGroup.removeAll(globalNodeGroups()); | ||
|
|
||
| initializeSubscription(); | ||
| return build(nodeGroup); | ||
| } | ||
|
|
||
| public synchronized ProcessorTopology build(final Integer topicGroupId) { | ||
| final Set<String> nodeGroup; | ||
| if (topicGroupId != null) { | ||
| nodeGroup = nodeGroups().get(topicGroupId); | ||
| } else { | ||
| // when topicGroupId is null, we build the full topology minus the global groups | ||
| final Set<String> globalNodeGroups = globalNodeGroups(); | ||
| final Collection<Set<String>> values = nodeGroups().values(); | ||
| nodeGroup = new HashSet<>(); | ||
| for (final Set<String> value : values) { | ||
| nodeGroup.addAll(value); | ||
| } | ||
| nodeGroup.removeAll(globalNodeGroups); | ||
| } | ||
| public synchronized ProcessorTopology build(final int topicGroupId) { | ||
| final Set<String> nodeGroup = nodeGroups().get(topicGroupId); | ||
| return build(nodeGroup); | ||
| } | ||
|
|
||
|
|
@@ -1210,32 +1205,29 @@ private String decorateTopic(final String topic) { | |
| return applicationId + "-" + topic; | ||
| } | ||
|
|
||
| void initializeSubscription() { | ||
| if (usesPatternSubscription()) { | ||
| log.debug("Found pattern subscribed source topics, initializing consumer's subscription pattern."); | ||
| final List<String> allSourceTopics = maybeDecorateInternalSourceTopics(sourceTopicNames); | ||
| Collections.sort(allSourceTopics); | ||
| sourceTopicPattern = buildPattern(allSourceTopics, nodeToSourcePatterns.values()); | ||
| } else { | ||
| log.debug("No source topics using pattern subscription found, initializing consumer's subscription collection."); | ||
| sourceTopicCollection = maybeDecorateInternalSourceTopics(sourceTopicNames); | ||
| Collections.sort(sourceTopicCollection); | ||
| } | ||
| } | ||
|
|
||
| boolean usesPatternSubscription() { | ||
| return !nodeToSourcePatterns.isEmpty(); | ||
| } | ||
|
|
||
| synchronized Collection<String> sourceTopicCollection() { | ||
| log.debug("No source topics using pattern subscription found, using regular subscription for the main consumer."); | ||
|
|
||
| if (topicCollection == null) { | ||
| topicCollection = maybeDecorateInternalSourceTopics(sourceTopicNames); | ||
| Collections.sort(topicCollection); | ||
| } | ||
|
|
||
| return topicCollection; | ||
| return sourceTopicCollection; | ||
|
Contributor
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.. inside StreamThread do we guarantee we always call
Contributor
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. If not we should call
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. I put this initialization inside |
||
| } | ||
|
|
||
| synchronized Pattern sourceTopicPattern() { | ||
| if (topicPattern == null) { | ||
| final List<String> allSourceTopics = maybeDecorateInternalSourceTopics(sourceTopicNames); | ||
| Collections.sort(allSourceTopics); | ||
| topicPattern = buildPattern(allSourceTopics, nodeToSourcePatterns.values()); | ||
| } | ||
|
|
||
| log.debug("Found pattern subscribed source topics, falling back to pattern " + | ||
| "subscription for the main consumer: {}", topicPattern); | ||
|
|
||
| return topicPattern; | ||
| return sourceTopicPattern; | ||
| } | ||
|
|
||
| private boolean isGlobalSource(final String nodeName) { | ||
|
|
@@ -1872,37 +1864,35 @@ private boolean hasSubscriptionUpdates() { | |
| } | ||
|
|
||
| synchronized void addSubscribedTopicsFromAssignment(final List<TopicPartition> partitions, final String logPrefix) { | ||
| if (sourceTopicPattern() != null) { | ||
| if (usesPatternSubscription()) { | ||
| final Set<String> assignedTopics = new HashSet<>(); | ||
| for (final TopicPartition topicPartition : partitions) { | ||
| assignedTopics.add(topicPartition.topic()); | ||
| } | ||
|
|
||
| final Collection<String> existingTopics = subscriptionUpdates(); | ||
| if (!existingTopics.containsAll(assignedTopics)) { | ||
| assignedTopics.addAll(existingTopics); | ||
| updateSubscribedTopics(assignedTopics, logPrefix); | ||
| } | ||
| updateSubscribedTopics(assignedTopics, logPrefix); | ||
| } | ||
| } | ||
|
|
||
| synchronized void addSubscribedTopicsFromMetadata(final Set<String> topics, final String logPrefix) { | ||
| if (sourceTopicPattern() != null) { | ||
| final Collection<String> existingTopics = subscriptionUpdates(); | ||
| if (!existingTopics.equals(topics)) { | ||
| topics.addAll(existingTopics); | ||
| updateSubscribedTopics(topics, logPrefix); | ||
| } | ||
| if (usesPatternSubscription()) { | ||
| updateSubscribedTopics(topics, logPrefix); | ||
| } | ||
| } | ||
|
|
||
| private void updateSubscribedTopics(final Set<String> topics, final String logPrefix) { | ||
| log.debug("{}found {} topics possibly matching subscription", logPrefix, topics.size()); | ||
| subscriptionUpdates.clear(); | ||
| subscriptionUpdates.addAll(topics); | ||
| final Collection<String> existingTopics = subscriptionUpdates(); | ||
|
|
||
| if (!existingTopics.equals(topics)) { | ||
| topics.addAll(existingTopics); | ||
|
|
||
| setRegexMatchedTopicsToSourceNodes(); | ||
| setRegexMatchedTopicToStateStore(); | ||
| subscriptionUpdates.clear(); | ||
| subscriptionUpdates.addAll(topics); | ||
|
|
||
| log.debug("{}found {} topics possibly matching subscription", logPrefix, topics.size()); | ||
|
|
||
| setRegexMatchedTopicsToSourceNodes(); | ||
| setRegexMatchedTopicToStateStore(); | ||
| } | ||
| } | ||
|
|
||
| // following functions are for test only | ||
|
|
||
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.
Should we check that topicGroupId is not null?
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.
I moved all calls where
topicGroupIdwould be null to now call the parameterlessbuild()instead. We can actually maketopicGroupIdjust a regularintnowThere 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.
Sounds good.