|
|
@ -11,7 +11,7 @@ const ( |
|
|
|
LockBrokerBalancer = "broker_balancer" |
|
|
|
) |
|
|
|
|
|
|
|
// Balancer collects stats from all brokers.
|
|
|
|
// PubBalancer collects stats from all brokers.
|
|
|
|
//
|
|
|
|
// When publishers wants to create topics, it picks brokers to assign the topic partitions.
|
|
|
|
// When consumers wants to subscribe topics, it tells which brokers are serving the topic partitions.
|
|
|
@ -28,7 +28,7 @@ const ( |
|
|
|
//
|
|
|
|
// When a consumer instance is down, the broker will notice this and inform the balancer.
|
|
|
|
// The balancer will then tell the broker to send the partition to another standby consumer instance.
|
|
|
|
type Balancer struct { |
|
|
|
type PubBalancer struct { |
|
|
|
Brokers cmap.ConcurrentMap[string, *BrokerStats] // key: broker address
|
|
|
|
// Collected from all brokers when they connect to the broker leader
|
|
|
|
TopicToBrokers cmap.ConcurrentMap[string, *PartitionSlotToBrokerList] // key: topic name
|
|
|
@ -37,14 +37,14 @@ type Balancer struct { |
|
|
|
OnRemoveBroker func(broker string, brokerStats *BrokerStats) |
|
|
|
} |
|
|
|
|
|
|
|
func NewBalancer() *Balancer { |
|
|
|
return &Balancer{ |
|
|
|
func NewBalancer() *PubBalancer { |
|
|
|
return &PubBalancer{ |
|
|
|
Brokers: cmap.New[*BrokerStats](), |
|
|
|
TopicToBrokers: cmap.New[*PartitionSlotToBrokerList](), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (balancer *Balancer) AddBroker(broker string) (brokerStats *BrokerStats) { |
|
|
|
func (balancer *PubBalancer) AddBroker(broker string) (brokerStats *BrokerStats) { |
|
|
|
var found bool |
|
|
|
brokerStats, found = balancer.Brokers.Get(broker) |
|
|
|
if !found { |
|
|
@ -58,7 +58,7 @@ func (balancer *Balancer) AddBroker(broker string) (brokerStats *BrokerStats) { |
|
|
|
return brokerStats |
|
|
|
} |
|
|
|
|
|
|
|
func (balancer *Balancer) RemoveBroker(broker string, stats *BrokerStats) { |
|
|
|
func (balancer *PubBalancer) RemoveBroker(broker string, stats *BrokerStats) { |
|
|
|
balancer.Brokers.Remove(broker) |
|
|
|
|
|
|
|
// update TopicToBrokers
|
|
|
@ -78,7 +78,7 @@ func (balancer *Balancer) RemoveBroker(broker string, stats *BrokerStats) { |
|
|
|
balancer.OnRemoveBroker(broker, stats) |
|
|
|
} |
|
|
|
|
|
|
|
func (balancer *Balancer) OnBrokerStatsUpdated(broker string, brokerStats *BrokerStats, receivedStats *mq_pb.BrokerStats) { |
|
|
|
func (balancer *PubBalancer) OnBrokerStatsUpdated(broker string, brokerStats *BrokerStats, receivedStats *mq_pb.BrokerStats) { |
|
|
|
brokerStats.UpdateStats(receivedStats) |
|
|
|
|
|
|
|
// update TopicToBrokers
|
|
|
@ -97,9 +97,9 @@ func (balancer *Balancer) OnBrokerStatsUpdated(broker string, brokerStats *Broke |
|
|
|
} |
|
|
|
|
|
|
|
// OnPubAddBroker is called when a broker is added for a publisher coordinator
|
|
|
|
func (balancer *Balancer) onPubAddBroker(broker string, brokerStats *BrokerStats) { |
|
|
|
func (balancer *PubBalancer) onPubAddBroker(broker string, brokerStats *BrokerStats) { |
|
|
|
} |
|
|
|
|
|
|
|
// OnPubRemoveBroker is called when a broker is removed for a publisher coordinator
|
|
|
|
func (balancer *Balancer) onPubRemoveBroker(broker string, brokerStats *BrokerStats) { |
|
|
|
func (balancer *PubBalancer) onPubRemoveBroker(broker string, brokerStats *BrokerStats) { |
|
|
|
} |