rename Balancer to PubBalancer
This commit is contained in:
@@ -43,7 +43,7 @@ type MessageQueueBroker struct {
|
|||||||
filers map[pb.ServerAddress]struct{}
|
filers map[pb.ServerAddress]struct{}
|
||||||
currentFiler pb.ServerAddress
|
currentFiler pb.ServerAddress
|
||||||
localTopicManager *topic.LocalTopicManager
|
localTopicManager *topic.LocalTopicManager
|
||||||
Balancer *pub_balancer.Balancer
|
Balancer *pub_balancer.PubBalancer
|
||||||
lockAsBalancer *cluster.LiveLock
|
lockAsBalancer *cluster.LiveLock
|
||||||
Coordinator *sub_coordinator.Coordinator
|
Coordinator *sub_coordinator.Coordinator
|
||||||
accessLock sync.Mutex
|
accessLock sync.Mutex
|
||||||
|
|||||||
@@ -54,12 +54,12 @@ type BalanceActionCreate struct {
|
|||||||
|
|
||||||
// BalancePublishers check the stats of all brokers,
|
// BalancePublishers check the stats of all brokers,
|
||||||
// and balance the publishers to the brokers.
|
// and balance the publishers to the brokers.
|
||||||
func (balancer *Balancer) BalancePublishers() []BalanceAction {
|
func (balancer *PubBalancer) BalancePublishers() []BalanceAction {
|
||||||
action := BalanceTopicPartitionOnBrokers(balancer.Brokers)
|
action := BalanceTopicPartitionOnBrokers(balancer.Brokers)
|
||||||
return []BalanceAction{action}
|
return []BalanceAction{action}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (balancer *Balancer) ExecuteBalanceAction(actions []BalanceAction, grpcDialOption grpc.DialOption) (err error) {
|
func (balancer *PubBalancer) ExecuteBalanceAction(actions []BalanceAction, grpcDialOption grpc.DialOption) (err error) {
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
switch action.(type) {
|
switch action.(type) {
|
||||||
case *BalanceActionMove:
|
case *BalanceActionMove:
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Balancer <= PublisherToPubBalancer() <= Broker <=> Publish()
|
// PubBalancer <= PublisherToPubBalancer() <= Broker <=> Publish()
|
||||||
// ExecuteBalanceActionMove from Balancer => AssignTopicPartitions() => Broker => Publish()
|
// ExecuteBalanceActionMove from PubBalancer => AssignTopicPartitions() => Broker => Publish()
|
||||||
|
|
||||||
func (balancer *Balancer) ExecuteBalanceActionMove(move *BalanceActionMove, grpcDialOption grpc.DialOption) error {
|
func (balancer *PubBalancer) ExecuteBalanceActionMove(move *BalanceActionMove, grpcDialOption grpc.DialOption) error {
|
||||||
if _, found := balancer.Brokers.Get(move.SourceBroker); !found {
|
if _, found := balancer.Brokers.Get(move.SourceBroker); !found {
|
||||||
return fmt.Errorf("source broker %s not found", move.SourceBroker)
|
return fmt.Errorf("source broker %s not found", move.SourceBroker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const (
|
|||||||
LockBrokerBalancer = "broker_balancer"
|
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 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.
|
// 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.
|
// 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.
|
// 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
|
Brokers cmap.ConcurrentMap[string, *BrokerStats] // key: broker address
|
||||||
// Collected from all brokers when they connect to the broker leader
|
// Collected from all brokers when they connect to the broker leader
|
||||||
TopicToBrokers cmap.ConcurrentMap[string, *PartitionSlotToBrokerList] // key: topic name
|
TopicToBrokers cmap.ConcurrentMap[string, *PartitionSlotToBrokerList] // key: topic name
|
||||||
@@ -37,14 +37,14 @@ type Balancer struct {
|
|||||||
OnRemoveBroker func(broker string, brokerStats *BrokerStats)
|
OnRemoveBroker func(broker string, brokerStats *BrokerStats)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBalancer() *Balancer {
|
func NewBalancer() *PubBalancer {
|
||||||
return &Balancer{
|
return &PubBalancer{
|
||||||
Brokers: cmap.New[*BrokerStats](),
|
Brokers: cmap.New[*BrokerStats](),
|
||||||
TopicToBrokers: cmap.New[*PartitionSlotToBrokerList](),
|
TopicToBrokers: cmap.New[*PartitionSlotToBrokerList](),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (balancer *Balancer) AddBroker(broker string) (brokerStats *BrokerStats) {
|
func (balancer *PubBalancer) AddBroker(broker string) (brokerStats *BrokerStats) {
|
||||||
var found bool
|
var found bool
|
||||||
brokerStats, found = balancer.Brokers.Get(broker)
|
brokerStats, found = balancer.Brokers.Get(broker)
|
||||||
if !found {
|
if !found {
|
||||||
@@ -58,7 +58,7 @@ func (balancer *Balancer) AddBroker(broker string) (brokerStats *BrokerStats) {
|
|||||||
return brokerStats
|
return brokerStats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (balancer *Balancer) RemoveBroker(broker string, stats *BrokerStats) {
|
func (balancer *PubBalancer) RemoveBroker(broker string, stats *BrokerStats) {
|
||||||
balancer.Brokers.Remove(broker)
|
balancer.Brokers.Remove(broker)
|
||||||
|
|
||||||
// update TopicToBrokers
|
// update TopicToBrokers
|
||||||
@@ -78,7 +78,7 @@ func (balancer *Balancer) RemoveBroker(broker string, stats *BrokerStats) {
|
|||||||
balancer.OnRemoveBroker(broker, stats)
|
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)
|
brokerStats.UpdateStats(receivedStats)
|
||||||
|
|
||||||
// update TopicToBrokers
|
// 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
|
// 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
|
// 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) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ var (
|
|||||||
ErrNoBroker = errors.New("no broker")
|
ErrNoBroker = errors.New("no broker")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (balancer *Balancer) LookupTopicPartitions(topic *mq_pb.Topic) (assignments []*mq_pb.BrokerPartitionAssignment) {
|
func (balancer *PubBalancer) LookupTopicPartitions(topic *mq_pb.Topic) (assignments []*mq_pb.BrokerPartitionAssignment) {
|
||||||
// find existing topic partition assignments
|
// find existing topic partition assignments
|
||||||
for brokerStatsItem := range balancer.Brokers.IterBuffered() {
|
for brokerStatsItem := range balancer.Brokers.IterBuffered() {
|
||||||
broker, brokerStats := brokerStatsItem.Key, brokerStatsItem.Val
|
broker, brokerStats := brokerStatsItem.Key, brokerStatsItem.Val
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (balancer *Balancer) RepairTopics() []BalanceAction {
|
func (balancer *PubBalancer) RepairTopics() []BalanceAction {
|
||||||
action := BalanceTopicPartitionOnBrokers(balancer.Brokers)
|
action := BalanceTopicPartitionOnBrokers(balancer.Brokers)
|
||||||
return []BalanceAction{action}
|
return []BalanceAction{action}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ type ConsumerGroup struct {
|
|||||||
ConsumerGroupInstances cmap.ConcurrentMap[string, *ConsumerGroupInstance]
|
ConsumerGroupInstances cmap.ConcurrentMap[string, *ConsumerGroupInstance]
|
||||||
mapping *PartitionConsumerMapping
|
mapping *PartitionConsumerMapping
|
||||||
reBalanceTimer *time.Timer
|
reBalanceTimer *time.Timer
|
||||||
pubBalancer *pub_balancer.Balancer
|
pubBalancer *pub_balancer.PubBalancer
|
||||||
filerClientAccessor *FilerClientAccessor
|
filerClientAccessor *FilerClientAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsumerGroup(t *mq_pb.Topic, pubBalancer *pub_balancer.Balancer, filerClientAccessor *FilerClientAccessor) *ConsumerGroup {
|
func NewConsumerGroup(t *mq_pb.Topic, pubBalancer *pub_balancer.PubBalancer, filerClientAccessor *FilerClientAccessor) *ConsumerGroup {
|
||||||
return &ConsumerGroup{
|
return &ConsumerGroup{
|
||||||
topic: topic.FromPbTopic(t),
|
topic: topic.FromPbTopic(t),
|
||||||
ConsumerGroupInstances: cmap.New[*ConsumerGroupInstance](),
|
ConsumerGroupInstances: cmap.New[*ConsumerGroupInstance](),
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ type TopicConsumerGroups struct {
|
|||||||
type Coordinator struct {
|
type Coordinator struct {
|
||||||
// map topic name to consumer groups
|
// map topic name to consumer groups
|
||||||
TopicSubscribers cmap.ConcurrentMap[string, *TopicConsumerGroups]
|
TopicSubscribers cmap.ConcurrentMap[string, *TopicConsumerGroups]
|
||||||
balancer *pub_balancer.Balancer
|
balancer *pub_balancer.PubBalancer
|
||||||
FilerClientAccessor *FilerClientAccessor
|
FilerClientAccessor *FilerClientAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCoordinator(balancer *pub_balancer.Balancer) *Coordinator {
|
func NewCoordinator(balancer *pub_balancer.PubBalancer) *Coordinator {
|
||||||
return &Coordinator{
|
return &Coordinator{
|
||||||
TopicSubscribers: cmap.New[*TopicConsumerGroups](),
|
TopicSubscribers: cmap.New[*TopicConsumerGroups](),
|
||||||
balancer: balancer,
|
balancer: balancer,
|
||||||
|
|||||||
Reference in New Issue
Block a user