You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							36 lines
						
					
					
						
							1.2 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							36 lines
						
					
					
						
							1.2 KiB
						
					
					
				
								package pub_balancer
							 | 
						|
								
							 | 
						|
								import (
							 | 
						|
									"errors"
							 | 
						|
									"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
							 | 
						|
									"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
							 | 
						|
								)
							 | 
						|
								
							 | 
						|
								var (
							 | 
						|
									ErrNoBroker = errors.New("no broker")
							 | 
						|
								)
							 | 
						|
								
							 | 
						|
								func (balancer *PubBalancer) LookupTopicPartitions(topic *schema_pb.Topic) (assignments []*mq_pb.BrokerPartitionAssignment) {
							 | 
						|
									// find existing topic partition assignments
							 | 
						|
									for brokerStatsItem := range balancer.Brokers.IterBuffered() {
							 | 
						|
										broker, brokerStats := brokerStatsItem.Key, brokerStatsItem.Val
							 | 
						|
										for topicPartitionStatsItem := range brokerStats.TopicPartitionStats.IterBuffered() {
							 | 
						|
											topicPartitionStat := topicPartitionStatsItem.Val
							 | 
						|
											if topicPartitionStat.TopicPartition.Namespace == topic.Namespace &&
							 | 
						|
												topicPartitionStat.TopicPartition.Name == topic.Name {
							 | 
						|
												assignment := &mq_pb.BrokerPartitionAssignment{
							 | 
						|
													Partition: &schema_pb.Partition{
							 | 
						|
														RingSize:   MaxPartitionCount,
							 | 
						|
														RangeStart: topicPartitionStat.RangeStart,
							 | 
						|
														RangeStop:  topicPartitionStat.RangeStop,
							 | 
						|
														UnixTimeNs: topicPartitionStat.UnixTimeNs,
							 | 
						|
													},
							 | 
						|
												}
							 | 
						|
												// TODO fix follower setting
							 | 
						|
												assignment.LeaderBroker = broker
							 | 
						|
												assignments = append(assignments, assignment)
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
									return
							 | 
						|
								}
							 |