|
@ -47,7 +47,7 @@ func (pcm *PartitionConsumerMapping) BalanceToConsumerInstances(partitionSlotToB |
|
|
|
|
|
|
|
|
func doBalanceSticky(partitions []*pub_balancer.PartitionSlotToBroker, consumerInstances []*ConsumerGroupInstance, prevMapping *PartitionSlotToConsumerInstanceList) (partitionSlots []*PartitionSlotToConsumerInstance) { |
|
|
func doBalanceSticky(partitions []*pub_balancer.PartitionSlotToBroker, consumerInstances []*ConsumerGroupInstance, prevMapping *PartitionSlotToConsumerInstanceList) (partitionSlots []*PartitionSlotToConsumerInstance) { |
|
|
// collect previous consumer instance ids
|
|
|
// collect previous consumer instance ids
|
|
|
prevConsumerInstanceIds := make(map[string]struct{}) |
|
|
|
|
|
|
|
|
prevConsumerInstanceIds := make(map[ConsumerGroupInstanceId]struct{}) |
|
|
if prevMapping != nil { |
|
|
if prevMapping != nil { |
|
|
for _, prevPartitionSlot := range prevMapping.PartitionSlots { |
|
|
for _, prevPartitionSlot := range prevMapping.PartitionSlots { |
|
|
if prevPartitionSlot.AssignedInstanceId != "" { |
|
|
if prevPartitionSlot.AssignedInstanceId != "" { |
|
@ -56,13 +56,13 @@ func doBalanceSticky(partitions []*pub_balancer.PartitionSlotToBroker, consumerI |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// collect current consumer instance ids
|
|
|
// collect current consumer instance ids
|
|
|
currConsumerInstanceIds := make(map[string]struct{}) |
|
|
|
|
|
|
|
|
currConsumerInstanceIds := make(map[ConsumerGroupInstanceId]struct{}) |
|
|
for _, consumerInstance := range consumerInstances { |
|
|
for _, consumerInstance := range consumerInstances { |
|
|
currConsumerInstanceIds[consumerInstance.InstanceId] = struct{}{} |
|
|
currConsumerInstanceIds[consumerInstance.InstanceId] = struct{}{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// check deleted consumer instances
|
|
|
// check deleted consumer instances
|
|
|
deletedConsumerInstanceIds := make(map[string]struct{}) |
|
|
|
|
|
|
|
|
deletedConsumerInstanceIds := make(map[ConsumerGroupInstanceId]struct{}) |
|
|
for consumerInstanceId := range prevConsumerInstanceIds { |
|
|
for consumerInstanceId := range prevConsumerInstanceIds { |
|
|
if _, ok := currConsumerInstanceIds[consumerInstanceId]; !ok { |
|
|
if _, ok := currConsumerInstanceIds[consumerInstanceId]; !ok { |
|
|
deletedConsumerInstanceIds[consumerInstanceId] = struct{}{} |
|
|
deletedConsumerInstanceIds[consumerInstanceId] = struct{}{} |
|
@ -100,7 +100,7 @@ func doBalanceSticky(partitions []*pub_balancer.PartitionSlotToBroker, consumerI |
|
|
|
|
|
|
|
|
// for all consumer instances, count the average number of partitions
|
|
|
// for all consumer instances, count the average number of partitions
|
|
|
// that are assigned to them
|
|
|
// that are assigned to them
|
|
|
consumerInstancePartitionCount := make(map[string]int) |
|
|
|
|
|
|
|
|
consumerInstancePartitionCount := make(map[ConsumerGroupInstanceId]int) |
|
|
for _, newPartitionSlot := range newPartitionSlots { |
|
|
for _, newPartitionSlot := range newPartitionSlots { |
|
|
if newPartitionSlot.AssignedInstanceId != "" { |
|
|
if newPartitionSlot.AssignedInstanceId != "" { |
|
|
consumerInstancePartitionCount[newPartitionSlot.AssignedInstanceId]++ |
|
|
consumerInstancePartitionCount[newPartitionSlot.AssignedInstanceId]++ |
|
|