Browse Source

Sort the assignment priority queue in descending order using member-id if the assignment counts are identical

Scott Kidder 5 years ago
parent
commit
df5d0c0ba1
1 changed files with 5 additions and 1 deletions
  1. 5 1
      balance_strategy.go

+ 5 - 1
balance_strategy.go

@@ -4,6 +4,7 @@ import (
 	"container/heap"
 	"math"
 	"sort"
+	"strings"
 )
 
 const (
@@ -1048,7 +1049,10 @@ type assignmentPriorityQueue []*consumerGroupMember
 func (pq assignmentPriorityQueue) Len() int { return len(pq) }
 
 func (pq assignmentPriorityQueue) Less(i, j int) bool {
-	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
+	// order asssignment priority queue in descending order using assignment-count/member-id
+	if len(pq[i].assignments) == len(pq[j].assignments) {
+		return strings.Compare(pq[i].id, pq[j].id) > 0
+	}
 	return len(pq[i].assignments) > len(pq[j].assignments)
 }