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.

47 lines
1.7 KiB

1 year ago
1 year ago
1 year ago
1 year ago
  1. package broker
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  5. "google.golang.org/grpc/codes"
  6. "google.golang.org/grpc/status"
  7. )
  8. // FindTopicBrokers returns the brokers that are serving the topic
  9. //
  10. // 1. lock the topic
  11. //
  12. // 2. find the topic partitions on the filer
  13. // 2.1 if the topic is not found, return error
  14. // 2.2 if the request is_for_publish, create the topic
  15. // 2.2.1 if the request is_for_subscribe, return error not found
  16. // 2.2.2 if the request is_for_publish, create the topic
  17. // 2.2 if the topic is found, return the brokers
  18. //
  19. // 3. unlock the topic
  20. func (broker *MessageQueueBroker) LookupTopicBrokers(ctx context.Context, request *mq_pb.LookupTopicBrokersRequest) (resp *mq_pb.LookupTopicBrokersResponse, err error) {
  21. if broker.currentBalancer == "" {
  22. return nil, status.Errorf(codes.Unavailable, "no balancer")
  23. }
  24. if !broker.lockAsBalancer.IsLocked() {
  25. proxyErr := broker.withBrokerClient(false, broker.currentBalancer, func(client mq_pb.SeaweedMessagingClient) error {
  26. resp, err = client.LookupTopicBrokers(ctx, request)
  27. return nil
  28. })
  29. if proxyErr != nil {
  30. return nil, proxyErr
  31. }
  32. return resp, err
  33. }
  34. ret := &mq_pb.LookupTopicBrokersResponse{}
  35. ret.Topic = request.Topic
  36. ret.BrokerPartitionAssignments, err = broker.Balancer.LookupOrAllocateTopicPartitions(ret.Topic, request.IsForPublish)
  37. return ret, err
  38. }
  39. // CheckTopicPartitionsStatus check the topic partitions on the broker
  40. func (broker *MessageQueueBroker) CheckTopicPartitionsStatus(c context.Context, request *mq_pb.CheckTopicPartitionsStatusRequest) (*mq_pb.CheckTopicPartitionsStatusResponse, error) {
  41. ret := &mq_pb.CheckTopicPartitionsStatusResponse{}
  42. return ret, nil
  43. }