Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@
package org.apache.rocketmq.connect.runtime.config;

Copy link
Copy Markdown

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.


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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, exchange COMMA and SEMICOLON to maintain upgrade compatible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -273,7 +275,8 @@ private void setQueueOffset() {
}

private void registTopics() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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");
}
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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++;
Expand Down