RongtongJin commented on a change in pull request #2169:
URL: https://github.com/apache/rocketmq/pull/2169#discussion_r468360403



##########
File path: 
common/src/main/java/org/apache/rocketmq/common/rebalance/AllocateMessageQueueSticky.java
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.common.rebalance;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+import org.apache.rocketmq.common.AllocateMessageQueueStrategy;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.logging.InternalLogger;
+import org.apache.rocketmq.logging.InternalLoggerFactory;
+
+public class AllocateMessageQueueSticky implements 
AllocateMessageQueueStrategy {
+    private static final InternalLogger log = 
InternalLoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME);
+
+    private final Map<String, List<MessageQueue>> messageQueueAllocation;
+
+    private final List<MessageQueue> unassignedQueues = new 
ArrayList<MessageQueue>();
+
+    public AllocateMessageQueueSticky(Map<String, List<MessageQueue>> 
messageQueueAllocation)
+        throws NullPointerException {
+        if (messageQueueAllocation == null) {
+            throw new NullPointerException("currentMessageQueueAllocation is 
null");
+        }

Review comment:
       Throwing NPE is very strange, because even if you don’t write related 
code, it will still throw NPE.

##########
File path: 
broker/src/main/java/org/apache/rocketmq/broker/processor/ConsumerManageProcessor.java
##########
@@ -152,4 +168,75 @@ private RemotingCommand 
queryConsumerOffset(ChannelHandlerContext ctx, RemotingC
 
         return response;
     }
+
+    private RemotingCommand allocateMessageQueue(ChannelHandlerContext ctx, 
RemotingCommand request)
+        throws RemotingCommandException {
+        final RemotingCommand response =
+            
RemotingCommand.createResponseCommand(AllocateMessageQueueResponseHeader.class);
+        final AllocateMessageQueueRequestHeader requestHeader =
+            (AllocateMessageQueueRequestHeader) 
request.decodeCommandCustomHeader(AllocateMessageQueueRequestHeader.class);
+        final AllocateMessageQueueRequestBody requestBody = 
AllocateMessageQueueRequestBody.decode(request.getBody(),
+            AllocateMessageQueueRequestBody.class);
+
+        AllocateMessageQueueStrategy strategy = null;
+        String consumerGroup = requestHeader.getConsumerGroup();
+        String strategyName = requestHeader.getStrategyName();
+
+        if 
(this.brokerController.getAllocateMessageQueueStrategyTable().containsKey(consumerGroup))
 {
+            strategy = 
this.brokerController.getAllocateMessageQueueStrategyTable().get(consumerGroup);
+        } else {
+            if 
(strategyName.startsWith(AllocateMessageQueueStrategyConstants.ALLOCATE_MACHINE_ROOM_NEARBY))
 {
+                
response.setCode(ResponseCode.ALLOCATE_MESSAGE_QUEUE_STRATEGY_NOT_SUPPORTED);
+                response.setRemark("The broker does not support message queue 
strategy " + strategyName);
+                return response;
+            } else {
+                switch (strategyName) {
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_AVERAGELY:
+                        strategy = new AllocateMessageQueueAveragely();
+                        break;
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_AVERAGELY_BY_CIRCLE:
+                        strategy = new AllocateMessageQueueAveragelyByCircle();
+                        break;
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_BY_CONFIG:
+                        strategy = new AllocateMessageQueueByConfig();
+                        break;
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_BY_MACHINE_ROOM:
+                        strategy = new AllocateMessageQueueByMachineRoom();
+                        break;
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_CONSISTENT_HASH:
+                        strategy = new AllocateMessageQueueConsistentHash();
+                        break;
+                    case 
AllocateMessageQueueStrategyConstants.ALLOCATE_MESSAGE_QUEUE_STICKY:
+                        strategy = new AllocateMessageQueueSticky(new 
HashMap<String, List<MessageQueue>>());
+                    default:
+                        break;
+                }
+            }
+            
this.brokerController.getAllocateMessageQueueStrategyTable().put(consumerGroup, 
strategy);
+        }

Review comment:
       There may be a thread-safe issue, because multiple threads may call 
allocateMessageQueue at the same time

##########
File path: common/pom.xml
##########
@@ -24,6 +24,18 @@
 
     <modelVersion>4.0.0</modelVersion>
     <packaging>jar</packaging>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>

Review comment:
       Is it necessary to force the compilation version to 8, which may cause 
some compatibility issues




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to