From d564dcd31a7e5740693e5faef8863ea9fd739a9c Mon Sep 17 00:00:00 2001 From: weibubli <46190832+weibubli@users.noreply.github.com> Date: Fri, 7 Jan 2022 20:23:15 +0800 Subject: [PATCH] [ISSUE #3709] Resolve export metadata errors while multiple brokers. (#3727) * Update ExportMetadataCommand.java * Update ExportMetadataCommand.java --- .../command/export/ExportMetadataCommand.java | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportMetadataCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportMetadataCommand.java index 1909436467b..397be8a20d0 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportMetadataCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/export/ExportMetadataCommand.java @@ -25,7 +25,6 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; -import org.apache.rocketmq.common.MQVersion; import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.TopicConfig; import org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper; @@ -119,6 +118,7 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) Map topicConfigMap = new HashMap<>(); Map subGroupConfigMap = new HashMap<>(); + Map result = new HashMap<>(); for (String addr : masterSet) { TopicConfigSerializeWrapper topicConfigSerializeWrapper = defaultMQAdminExt.getUserTopicConfig( @@ -127,50 +127,47 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getUserSubscriptionGroup( addr, 10000); - if (commandLine.hasOption('t')) { - filePath = filePath + "/topic.json"; - MixAll.string2FileNotSafe(JSON.toJSONString(topicConfigSerializeWrapper, true), filePath); - System.out.printf("export %s success", filePath); - return; - } else if (commandLine.hasOption('g')) { - filePath = filePath + "/subscriptionGroup.json"; - MixAll.string2FileNotSafe(JSON.toJSONString(subscriptionGroupWrapper, true), filePath); - System.out.printf("export %s success", filePath); - return; - } else { - for (Map.Entry entry : topicConfigSerializeWrapper.getTopicConfigTable().entrySet()) { - TopicConfig topicConfig = topicConfigMap.get(entry.getKey()); - if (null != topicConfig) { - entry.getValue().setWriteQueueNums( - topicConfig.getWriteQueueNums() + entry.getValue().getWriteQueueNums()); - entry.getValue().setReadQueueNums( - topicConfig.getReadQueueNums() + entry.getValue().getReadQueueNums()); - } - topicConfigMap.put(entry.getKey(), entry.getValue()); + for (Map.Entry entry : topicConfigSerializeWrapper.getTopicConfigTable() + .entrySet()) { + TopicConfig topicConfig = topicConfigMap.get(entry.getKey()); + if (null != topicConfig) { + entry.getValue().setWriteQueueNums( + topicConfig.getWriteQueueNums() + entry.getValue().getWriteQueueNums()); + entry.getValue().setReadQueueNums( + topicConfig.getReadQueueNums() + entry.getValue().getReadQueueNums()); } + topicConfigMap.put(entry.getKey(), entry.getValue()); + } - for (Map.Entry entry : subscriptionGroupWrapper.getSubscriptionGroupTable().entrySet()) { + for (Map.Entry entry : subscriptionGroupWrapper.getSubscriptionGroupTable() + .entrySet()) { - SubscriptionGroupConfig subscriptionGroupConfig = subGroupConfigMap.get(entry.getKey()); - if (null != subscriptionGroupConfig) { - entry.getValue().setRetryQueueNums( - subscriptionGroupConfig.getRetryQueueNums() + entry.getValue().getRetryQueueNums()); - } - subGroupConfigMap.put(entry.getKey(), entry.getValue()); + SubscriptionGroupConfig subscriptionGroupConfig = subGroupConfigMap.get(entry.getKey()); + if (null != subscriptionGroupConfig) { + entry.getValue().setRetryQueueNums( + subscriptionGroupConfig.getRetryQueueNums() + entry.getValue().getRetryQueueNums()); } - - Map result = new HashMap<>(); - result.put("topicConfigTable", topicConfigMap); - result.put("subscriptionGroupTable", subGroupConfigMap); - result.put("rocketmqVersion", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); - result.put("exportTime", System.currentTimeMillis()); - - filePath = filePath + "/metadata.json"; - MixAll.string2FileNotSafe(JSON.toJSONString(result, true), filePath); - System.out.printf("export %s success", filePath); + subGroupConfigMap.put(entry.getKey(), entry.getValue()); } } + + String exportPath; + if (commandLine.hasOption('t')) { + result.put("topicConfigTable", topicConfigMap); + exportPath = filePath + "/topic.json"; + } else if (commandLine.hasOption('g')) { + result.put("subscriptionGroupTable", subGroupConfigMap); + exportPath = filePath + "/subscriptionGroup.json"; + } else { + result.put("topicConfigTable", topicConfigMap); + result.put("subscriptionGroupTable", subGroupConfigMap); + exportPath = filePath + "/metadata.json"; + } + result.put("exportTime", System.currentTimeMillis()); + MixAll.string2FileNotSafe(JSON.toJSONString(result, true), exportPath); + System.out.printf("export %s success%n", exportPath); + } else { ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options); }