You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2019/08/05 17:06:19 UTC

[GitHub] [rocketmq-client-go] luther-siyuan commented on a change in pull request #141: [ISSUE#120]update AllocateByAveragely and AllocateByAveragelyCircle and add their tests

luther-siyuan 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_r310702955
 
 

 ##########
 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:
   ok

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services