Skip to content

[ISSUE #253]Adjust RSQLDB #252

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

Merged
merged 2 commits into from
Jan 17, 2023
Merged
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 @@ -75,4 +75,8 @@ public void stop() {
workerThreads.clear();
this.started.set(false);
}

public boolean isRunning() {
return this.started.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public void process(T data) throws Throwable {
producer.send(message);
} else {
message = new Message(this.topicName, value);
String hexKey = Utils.toHexString(this.key);
//the real key is in the body, this key is used to route the same key into the same queue.
message.setKeys(Utils.toHexString(this.key));
message.setKeys(hexKey);


message.putUserProperty(Constant.SHUFFLE_KEY_CLASS_NAME, this.key.getClass().getName());
Expand All @@ -94,7 +95,7 @@ public void process(T data) throws Throwable {
message.putUserProperty(Constant.SOURCE_TIMESTAMP, String.valueOf(this.context.getDataTime()));
}

producer.send(message, new SelectMessageQueueByHash(), this.key);
producer.send(message, new SelectMessageQueueByHash(), hexKey);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void init() throws Throwable {
@Override
public void recover(Set<MessageQueue> addQueues, Set<MessageQueue> removeQueues) throws Throwable {
this.loadState(addQueues);
//todo what to to with the data in flight, if the source queue is be removed.
this.removeState(removeQueues);
}

Expand Down Expand Up @@ -396,7 +397,7 @@ private void createStateTopic(String stateTopic) throws Exception {
String sourceTopic = stateTopic2SourceTopic(stateTopic);
Pair<Integer, Set<String>> clustersPair = getTotalQueueNumAndClusters(sourceTopic);

RocketMQUtil.createStaticCompactTopic(mqAdmin, stateTopic, clustersPair.getKey(), clustersPair.getValue());
RocketMQUtil.createNormalTopic(mqAdmin, stateTopic, clustersPair.getKey(), clustersPair.getValue());
}

private Pair<Integer, Set<String>> getTotalQueueNumAndClusters(String sourceTopic) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import org.apache.commons.cli.PosixParser;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.TopicConfig;
import org.apache.rocketmq.common.constant.PermName;
import org.apache.rocketmq.common.protocol.ResponseCode;
import org.apache.rocketmq.common.protocol.body.ClusterInfo;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.apache.rocketmq.srvutil.ServerUtil;
import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
import org.apache.rocketmq.tools.command.CommandUtil;
import org.apache.rocketmq.tools.command.topic.UpdateStaticTopicSubCommand;
import org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand;
import org.slf4j.Logger;
Expand All @@ -41,6 +44,30 @@ public class RocketMQUtil {

private static final List<String> existTopic = new ArrayList<>();

//neither static topic nor compact topic. expansion with source topic.
public static void createNormalTopic(DefaultMQAdminExt mqAdmin, String topicName, int queueNum, Set<String> clusters) throws Exception {
if (check(mqAdmin, topicName)) {
logger.info("topic[{}] already exist.", topicName);
return;
}

if (clusters == null || clusters.size() == 0) {
clusters = getCluster(mqAdmin);
}

TopicConfig topicConfig = new TopicConfig(topicName, queueNum, queueNum, PermName.PERM_READ | PermName.PERM_WRITE);

for (String cluster : clusters) {
Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdmin, cluster);

for (String addr : masterSet) {
mqAdmin.createAndUpdateTopicConfig(addr, topicConfig);
logger.info("create topic to broker:{} cluster:{}, success.", addr, cluster);
}
}
}

//used in RSQLDB,maybe.
public static void createStaticCompactTopic(DefaultMQAdminExt mqAdmin, String topicName, int queueNum, Set<String> clusters) throws Exception {
if (check(mqAdmin, topicName)) {
logger.info("topic[{}] already exist.", topicName);
Expand Down