You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/12/14 11:50:00 UTC

[GitHub] [rocketmq] lizhimins commented on a diff in pull request #5696: [ISSUE #5695] Optimize broker startup

lizhimins commented on code in PR #5696:
URL: https://github.com/apache/rocketmq/pull/5696#discussion_r1048373423


##########
broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java:
##########
@@ -79,163 +79,165 @@ public static void shutdown(final BrokerController controller) {
         }
     }
 
-    public static BrokerController createBrokerController(String[] args) {
+    public static BrokerController buildBrokerController(String[] args) throws Exception {
         System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
 
-        try {
-            //PackageConflictDetect.detectFastjson();
-            Options options = ServerUtil.buildCommandlineOptions(new Options());
-            commandLine = ServerUtil.parseCmdLine("mqbroker", args, buildCommandlineOptions(options),
-                new DefaultParser());
-            if (null == commandLine) {
-                System.exit(-1);
-            }
-
-            final BrokerConfig brokerConfig = new BrokerConfig();
-            final NettyServerConfig nettyServerConfig = new NettyServerConfig();
-            final NettyClientConfig nettyClientConfig = new NettyClientConfig();
-            nettyServerConfig.setListenPort(10911);
-            final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
+        final BrokerConfig brokerConfig = new BrokerConfig();
+        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
+        final NettyClientConfig nettyClientConfig = new NettyClientConfig();
+        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
+        nettyServerConfig.setListenPort(10911);
 
-            if (BrokerRole.SLAVE == messageStoreConfig.getBrokerRole()) {
-                int ratio = messageStoreConfig.getAccessMessageInMemoryMaxRatio() - 10;
-                messageStoreConfig.setAccessMessageInMemoryMaxRatio(ratio);
-            }
+        Options options = ServerUtil.buildCommandlineOptions(new Options());
+        CommandLine commandLine = ServerUtil.parseCmdLine(
+            "mqbroker", args, buildCommandlineOptions(options), new DefaultParser());
+        if (null == commandLine) {
+            System.exit(-1);
+        }
 
-            if (commandLine.hasOption('c')) {
-                String file = commandLine.getOptionValue('c');
-                if (file != null) {
-                    CONFIG_FILE_HELPER.setFile(file);
-                    configFile = file;
-                    BrokerPathConfigHelper.setBrokerConfigPath(file);
-                    properties = CONFIG_FILE_HELPER.loadConfig();
-                }
+        Properties properties = null;
+        if (commandLine.hasOption('c')) {
+            String file = commandLine.getOptionValue('c');
+            if (file != null) {
+                CONFIG_FILE_HELPER.setFile(file);
+                BrokerPathConfigHelper.setBrokerConfigPath(file);
+                properties = CONFIG_FILE_HELPER.loadConfig();
             }
+        }
 
-            if (properties != null) {
-                properties2SystemEnv(properties);
-                MixAll.properties2Object(properties, brokerConfig);
-                MixAll.properties2Object(properties, nettyServerConfig);
-                MixAll.properties2Object(properties, nettyClientConfig);
-                MixAll.properties2Object(properties, messageStoreConfig);
-            }
+        if (properties != null) {
+            properties2SystemEnv(properties);
+            MixAll.properties2Object(properties, brokerConfig);
+            MixAll.properties2Object(properties, nettyServerConfig);
+            MixAll.properties2Object(properties, nettyClientConfig);
+            MixAll.properties2Object(properties, messageStoreConfig);
+        }
 
-            MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), brokerConfig);
+        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), brokerConfig);
+        if (null == brokerConfig.getRocketmqHome()) {
+            System.out.printf("Please set the %s variable in your environment " +
+                "to match the location of the RocketMQ installation", MixAll.ROCKETMQ_HOME_ENV);
+            System.exit(-2);
+        }

Review Comment:
   User may not have correctly loaded the log related configuration file(such as logback.xml), resulting in the error message not being displayed. It would be better to keep current situation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org