-
Notifications
You must be signed in to change notification settings - Fork 119
[ISSUE #150] sink support topic tag #151
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -19,25 +19,30 @@ | |
| package org.apache.rocketmq.connect.runtime.config; | ||
|
|
||
| import com.google.common.base.Splitter; | ||
| import java.util.HashSet; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.Map; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.rocketmq.common.message.MessageQueue; | ||
| import org.apache.rocketmq.connect.runtime.common.ConnectKeyValue; | ||
|
|
||
| public class SinkConnectorConfig extends ConnectConfig { | ||
|
|
||
|
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 separator semantics have been swapped from the previous version: topics were previously split by SEMICOLON, now they are split by COMMA, and SEMICOLON now separates topic from tag. This is a backward-incompatible configuration format change. Any existing deployment using SEMICOLON-delimited topic lists will silently treat the entire string as one topic name, breaking existing connectors without any warning or migration path. 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 variable name 'topicNameAndTagss' (double 's') is a typo that propagates through the method. Minor, but reduces readability. |
||
|
|
||
|
|
||
| public static Set<String> parseTopicList(ConnectKeyValue taskConfig) { | ||
| String messageQueueStr = taskConfig.getString(RuntimeConfigDefine.CONNECT_TOPICNAME); | ||
| if (StringUtils.isBlank(messageQueueStr)) { | ||
| return null; | ||
| public static Map<String, String> parseTopicList(ConnectKeyValue taskConfig) { | ||
|
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. No null/blank check on topicNameAndTagss before passing to Splitter. If the config key is absent or blank, Splitter.on(COMMA).splitToList(null) will throw a NullPointerException. The old code guarded with StringUtils.isBlank and returned null; that guard was removed without replacement. |
||
| String topicNameAndTagss = taskConfig.getString(RuntimeConfigDefine.CONNECT_TOPICNAME); | ||
| List<String> topicTagList = Splitter.on(COMMA).omitEmptyStrings().trimResults().splitToList(topicNameAndTagss); | ||
| Map<String, String> topicNameAndTagssMap = new HashMap<>(8); | ||
| for (String topicTagPair : topicTagList) { | ||
|
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. When a topic-tag pair contains more than two SEMICOLON-separated segments (e.g. 'topicA;tag1;tag2'), the extra segments are silently discarded and only the first tag is used. There is no validation or error reported, which could hide misconfigured connector configs. |
||
| List<String> topicAndTag = Splitter.on(SEMICOLON).omitEmptyStrings().trimResults().splitToList(topicTagPair); | ||
|
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. IMO, exchange COMMA and SEMICOLON to maintain upgrade compatible.
Contributor
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. When there is no tag, if you configure multiple topics, it should be topic1, topic2, topic3. If there is a tag, it should be topic1;tag1, topic2;tag2, topic3;tag3, if so, is there no compatibility problem? |
||
| if (topicAndTag.size() == 1) { | ||
| topicNameAndTagssMap.put(topicAndTag.get(0), "*"); | ||
| } else { | ||
| topicNameAndTagssMap.put(topicAndTag.get(0), topicAndTag.get(1)); | ||
| } | ||
| } | ||
| List<String> topicList = Splitter.on(SEMICOLON).omitEmptyStrings().trimResults().splitToList(messageQueueStr); | ||
| return new HashSet<>(topicList); | ||
| return topicNameAndTagssMap; | ||
| } | ||
|
|
||
| public static MessageQueue parseMessageQueueList(String messageQueueStr) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,8 @@ public class WorkerSinkTask implements WorkerTask { | |
|
|
||
| private WorkerSinkTaskContext sinkTaskContext; | ||
|
|
||
| private Map<String, String> topicTagMap; | ||
|
|
||
| private final TransformChain<ConnectRecord> transformChain; | ||
|
|
||
| public static final String BROKER_NAME = "brokerName"; | ||
|
|
@@ -273,7 +275,8 @@ private void setQueueOffset() { | |
| } | ||
|
|
||
| private void registTopics() { | ||
|
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. topicTagMap is assigned in registTopics() but read in pullMessageFromQueues(). If pullMessageFromQueues() is ever called before registTopics() (e.g. due to a future refactor or concurrent access), it will throw a NullPointerException. The field should be initialized to an empty map or the access should be guarded. |
||
| Set<String> topics = SinkConnectorConfig.parseTopicList(taskConfig); | ||
| topicTagMap = SinkConnectorConfig.parseTopicList(taskConfig); | ||
| Set<String> topics = topicTagMap.keySet(); | ||
| if (org.apache.commons.collections4.CollectionUtils.isEmpty(topics)) { | ||
| throw new ConnectException("sink connector topics config can be null, please check sink connector config info"); | ||
| } | ||
|
|
@@ -372,7 +375,7 @@ private void pullMessageFromQueues() throws InterruptedException { | |
| final long beginPullMsgTimestamp = System.currentTimeMillis(); | ||
| try { | ||
| shouldStopPullMsg(); | ||
| pullResult = consumer.pullBlockIfNotFound(entry.getKey(), "*", entry.getValue(), MAX_MESSAGE_NUM); | ||
| pullResult = consumer.pullBlockIfNotFound(entry.getKey(), topicTagMap.get(entry.getKey().getTopic()), entry.getValue(), MAX_MESSAGE_NUM); | ||
|
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. topicTagMap.get(entry.getKey().getTopic()) can return null if the MessageQueue's topic is not present in the map (e.g. dynamically assigned queues or rebalance edge cases). Passing null as the subscription expression to pullBlockIfNotFound will likely cause an NPE or an unfiltered pull depending on the client implementation, and is not equivalent to '*'. |
||
| pullMsgErrorCount = 0; | ||
| } catch (MQClientException e) { | ||
| pullMsgErrorCount++; | ||
|
|
||
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.
No test changes detected alongside source modifications. Consider adding tests to cover the changes.