diff options
| author | chrislu <chris.lu@gmail.com> | 2023-09-24 21:19:51 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2023-09-24 22:00:43 -0700 |
| commit | 3cf9b8d62149ae0a163635ef480af2c01bae872b (patch) | |
| tree | 2e2be77ddd3e87130b713eadf7e067cfbbe3ff52 /weed/mq/balancer | |
| parent | b3f94feeded8f0beb411ade49bda09baa3c5443f (diff) | |
| download | seaweedfs-3cf9b8d62149ae0a163635ef480af2c01bae872b.tar.xz seaweedfs-3cf9b8d62149ae0a163635ef480af2c01bae872b.zip | |
create topic and report topicorigin/sub
Diffstat (limited to 'weed/mq/balancer')
| -rw-r--r-- | weed/mq/balancer/allocate.go | 8 | ||||
| -rw-r--r-- | weed/mq/balancer/balancer.go | 5 | ||||
| -rw-r--r-- | weed/mq/balancer/lookup.go | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/weed/mq/balancer/allocate.go b/weed/mq/balancer/allocate.go index f7b17ab4b..96a7bcb81 100644 --- a/weed/mq/balancer/allocate.go +++ b/weed/mq/balancer/allocate.go @@ -6,10 +6,10 @@ import ( "math/rand" ) -func allocateTopicPartitions(brokers cmap.ConcurrentMap[string, *BrokerStats], partitionCount int) (assignments []*mq_pb.BrokerPartitionAssignment) { +func allocateTopicPartitions(brokers cmap.ConcurrentMap[string, *BrokerStats], partitionCount int32) (assignments []*mq_pb.BrokerPartitionAssignment) { // divide the ring into partitions rangeSize := MaxPartitionCount / partitionCount - for i := 0; i < partitionCount; i++ { + for i := int32(0); i < partitionCount; i++ { assignment := &mq_pb.BrokerPartitionAssignment{ Partition: &mq_pb.Partition{ RingSize: MaxPartitionCount, @@ -35,13 +35,13 @@ func allocateTopicPartitions(brokers cmap.ConcurrentMap[string, *BrokerStats], p // for now: randomly pick brokers // TODO pick brokers based on the broker stats -func pickBrokers(brokers cmap.ConcurrentMap[string, *BrokerStats], count int) []string { +func pickBrokers(brokers cmap.ConcurrentMap[string, *BrokerStats], count int32) []string { candidates := make([]string, 0, brokers.Count()) for brokerStatsItem := range brokers.IterBuffered() { candidates = append(candidates, brokerStatsItem.Key) } pickedBrokers := make([]string, 0, count) - for i := 0; i < count; i++ { + for i := int32(0); i < count; i++ { p := rand.Int() % len(candidates) if p < 0 { p = -p diff --git a/weed/mq/balancer/balancer.go b/weed/mq/balancer/balancer.go index b240f2d5f..4da735bd3 100644 --- a/weed/mq/balancer/balancer.go +++ b/weed/mq/balancer/balancer.go @@ -52,6 +52,11 @@ func (bs *BrokerStats) UpdateStats(stats *mq_pb.BrokerStats) { } +func (bs *BrokerStats) String() string { + return fmt.Sprintf("BrokerStats{TopicPartitionCount:%d, ConsumerCount:%d, CpuUsagePercent:%d, Stats:%+v}", + bs.TopicPartitionCount, bs.ConsumerCount, bs.CpuUsagePercent, bs.Stats.Items()) +} + type TopicPartition struct { Namespace string Topic string diff --git a/weed/mq/balancer/lookup.go b/weed/mq/balancer/lookup.go index f906a7d74..5a14b3317 100644 --- a/weed/mq/balancer/lookup.go +++ b/weed/mq/balancer/lookup.go @@ -47,5 +47,5 @@ func (b *Balancer) LookupOrAllocateTopicPartitions(topic *mq_pb.Topic, publish b if b.Brokers.IsEmpty() { return nil, ErrNoBroker } - return allocateTopicPartitions(b.Brokers, 6), nil + return allocateTopicPartitions(b.Brokers, partitionCount), nil } |
