wenfengwang commented on a change in pull request #141: [ISSUE#120]update 
AllocateByAveragely and AllocateByAveragelyCircle and add their tests
URL: https://github.com/apache/rocketmq-client-go/pull/141#discussion_r310466324
 
 

 ##########
 File path: consumer/strategy.go
 ##########
 @@ -84,20 +84,46 @@ func AllocateByAveragely(consumerGroup, currentCID string, 
mqAll []*primitive.Me
        }
 
        num := utils.MinInt(averageSize, mqSize-startIndex)
-       result := make([]*primitive.MessageQueue, num)
+       result := []*primitive.MessageQueue{}
        for i := 0; i < num; i++ {
-               result[i] = mqAll[(startIndex+i)%mqSize]
+               result = append(result, mqAll[(startIndex+i)%mqSize])
        }
        return result
 }
 
-// TODO
-func AllocateByMachineNearby(consumerGroup, currentCID string, mqAll 
[]*primitive.MessageQueue,
+func AllocateByAveragelyCircle(consumerGroup, currentCID string, mqAll 
[]*primitive.MessageQueue,
        cidAll []string) []*primitive.MessageQueue {
-       return AllocateByAveragely(consumerGroup, currentCID, mqAll, cidAll)
+       if currentCID == "" || len(mqAll) == 0 || len(cidAll) == 0 {
+               return nil
+       }
+
+       var (
+               find  bool
+               index int
+       )
+       for idx := range cidAll {
+               if cidAll[idx] == currentCID {
+                       find = true
+                       index = idx
+                       break
+               }
+       }
+       if !find {
+               rlog.Infof("[BUG] ConsumerGroup=%s, ConsumerId=%s not in 
cidAll:%+v", consumerGroup, currentCID, cidAll)
 
 Review comment:
   use warn level

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


With regards,
Apache Git Services

Reply via email to