-
Notifications
You must be signed in to change notification settings - Fork 120
[ISSUE #436]BrokerBasedLog supports initialization of compaction topic #437
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
73bc139
8fa5457
312d33c
3278370
6b3b798
39b8eae
0918f10
2b94a7a
63f815d
c137fab
19ad60c
bfd8e62
faf0fba
f6b65d2
507770d
1336681
910b7da
ab0ad85
6ffc39e
47f0aac
80b4d74
cc040b2
f697554
1f5080b
01d16c8
da77b22
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 |
|---|---|---|
|
|
@@ -16,6 +16,11 @@ | |
| */ | ||
| package org.apache.rocketmq.connect.debezium; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.rocketmq.acl.common.AclClientRPCHook; | ||
| import org.apache.rocketmq.acl.common.SessionCredentials; | ||
|
|
@@ -24,28 +29,22 @@ | |
| import org.apache.rocketmq.client.exception.MQClientException; | ||
| import org.apache.rocketmq.client.producer.DefaultMQProducer; | ||
| import org.apache.rocketmq.common.TopicConfig; | ||
| import org.apache.rocketmq.common.admin.TopicOffset; | ||
| import org.apache.rocketmq.common.admin.TopicStatsTable; | ||
| import org.apache.rocketmq.common.consumer.ConsumeFromWhere; | ||
| import org.apache.rocketmq.common.message.MessageQueue; | ||
| import org.apache.rocketmq.common.protocol.body.ClusterInfo; | ||
| import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; | ||
| import org.apache.rocketmq.common.protocol.route.BrokerData; | ||
| import org.apache.rocketmq.common.protocol.route.TopicRouteData; | ||
| import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig; | ||
| import org.apache.rocketmq.remoting.RPCHook; | ||
| import org.apache.rocketmq.remoting.exception.RemotingException; | ||
| import org.apache.rocketmq.remoting.protocol.LanguageCode; | ||
| import org.apache.rocketmq.remoting.protocol.ResponseCode; | ||
| import org.apache.rocketmq.remoting.protocol.admin.TopicOffset; | ||
| import org.apache.rocketmq.remoting.protocol.admin.TopicStatsTable; | ||
| import org.apache.rocketmq.remoting.protocol.body.ClusterInfo; | ||
| import org.apache.rocketmq.remoting.protocol.body.SubscriptionGroupWrapper; | ||
| import org.apache.rocketmq.remoting.protocol.route.BrokerData; | ||
| import org.apache.rocketmq.remoting.protocol.route.TopicRouteData; | ||
| import org.apache.rocketmq.remoting.protocol.subscription.SubscriptionGroupConfig; | ||
| import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; | ||
| import org.apache.rocketmq.tools.command.CommandUtil; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Tools for creating RocketMq topic and group | ||
| */ | ||
|
|
@@ -130,7 +129,7 @@ public static void createTopic(RocketMqConfig config, TopicConfig topicConfig) { | |
| try { | ||
| defaultMQAdminExt = startMQAdminTool(config); | ||
| ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo(); | ||
| HashMap<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable(); | ||
| Map<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable(); | ||
| Set<String> clusterNameSet = clusterAddrTable.keySet(); | ||
| for (String clusterName : clusterNameSet) { | ||
| Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); | ||
|
|
@@ -201,7 +200,7 @@ public static String createSubGroup(RocketMqConfig connectConfig, String subGrou | |
| SubscriptionGroupConfig initConfig = new SubscriptionGroupConfig(); | ||
| initConfig.setGroupName(subGroup); | ||
| ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo(); | ||
| HashMap<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable(); | ||
| Map<String, Set<String>> clusterAddrTable = clusterInfo.getClusterAddrTable(); | ||
| Set<String> clusterNameSet = clusterAddrTable.keySet(); | ||
| for (String clusterName : clusterNameSet) { | ||
| Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); | ||
|
|
@@ -231,9 +230,9 @@ public static Map<MessageQueue, TopicOffset> offsets(RocketMqConfig config, Stri | |
| DefaultMQAdminExt adminClient = null; | ||
| try { | ||
| adminClient = RocketMqAdminUtil.startMQAdminTool(config); | ||
| TopicStatsTable topicStatsTable = adminClient.examineTopicStats(topic); | ||
| TopicStatsTable topicStatsTable = examineTopicStats(adminClient,topic); | ||
| return topicStatsTable.getOffsetTable(); | ||
| } catch (MQClientException | MQBrokerException | RemotingException | InterruptedException e) { | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| if (adminClient != null) { | ||
|
|
@@ -242,4 +241,59 @@ public static Map<MessageQueue, TopicOffset> offsets(RocketMqConfig config, Stri | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Compatible with 4.9.4 and earlier | ||
| * | ||
| * @param adminClient | ||
| * @param topic | ||
| * @return | ||
| */ | ||
| private static TopicStatsTable examineTopicStats(DefaultMQAdminExt adminClient, String topic) { | ||
| try { | ||
| return adminClient.examineTopicStats(topic); | ||
| } catch (MQBrokerException e) { | ||
| // Compatible with 4.9.4 and earlier | ||
| if (e.getResponseCode() == ResponseCode.REQUEST_CODE_NOT_SUPPORTED) { | ||
| try { | ||
| return overrideExamineTopicStats(adminClient, topic); | ||
| } catch (Exception ex) { | ||
| throw new RuntimeException(ex); | ||
| } | ||
| } else { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } catch (Exception ex) { | ||
| throw new RuntimeException(ex); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Compatible with version 4.9.4 | ||
| * | ||
| * @param adminClient | ||
| * @param topic | ||
| * @return | ||
|
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. overrideExamineTopicStats uses a hardcoded 5000ms timeout for getTopicStatsInfo(addr, topic, 5000). For topics with many queues or under network latency, this may be insufficient and cause intermittent failures on the 4.9.4 compatibility path. Consider making the timeout configurable or increasing it. |
||
| * @throws RemotingException | ||
| * @throws InterruptedException | ||
| * @throws MQClientException | ||
| * @throws MQBrokerException | ||
| */ | ||
| private static TopicStatsTable overrideExamineTopicStats(DefaultMQAdminExt adminClient, | ||
| String topic) throws RemotingException, InterruptedException, MQClientException, MQBrokerException { | ||
| TopicRouteData topicRouteData = adminClient.examineTopicRouteInfo(topic); | ||
| TopicStatsTable topicStatsTable = new TopicStatsTable(); | ||
| for (BrokerData bd : topicRouteData.getBrokerDatas()) { | ||
| String addr = bd.selectBrokerAddr(); | ||
| if (addr != null) { | ||
| TopicStatsTable tst = adminClient | ||
| .getDefaultMQAdminExtImpl() | ||
| .getMqClientInstance() | ||
| .getMQClientAPIImpl() | ||
| .getTopicStatsInfo(addr, topic, 5000); | ||
| topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable()); | ||
| } | ||
| } | ||
| return topicStatsTable; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,7 +196,7 @@ | |
| <dependency> | ||
| <groupId>org.apache.rocketmq</groupId> | ||
| <artifactId>rocketmq-openmessaging</artifactId> | ||
| <version>5.1.0</version> | ||
| <version>4.9.4</version> | ||
|
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. rocketmq-openmessaging is downgraded from 5.1.0 to 4.9.4 for the mongo connector, which is the opposite direction of the overall upgrade. If this was intentional (e.g., 5.1.0 incompatibility), it should be documented. If accidental, it should be corrected to match the intended target version. |
||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
|
|
||
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.
The offsets() method broadened its catch clause from specific exceptions (MQClientException | MQBrokerException | RemotingException | InterruptedException) to catch(Exception e). This can mask programming errors like NullPointerException or IllegalArgumentException from startMQAdminTool or getOffsetTable, making debugging harder. Consider keeping the specific exception types or at least separating RuntimeException from expected checked exceptions.