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.

67 lines
2.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years 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. func (broker *MessageQueueBroker) CreateTopic(ctx context.Context, request *mq_pb.CreateTopicRequest) (resp *mq_pb.CreateTopicResponse, err error) {
  9. if broker.currentBalancer == "" {
  10. return nil, status.Errorf(codes.Unavailable, "no balancer")
  11. }
  12. if !broker.lockAsBalancer.IsLocked() {
  13. proxyErr := broker.withBrokerClient(false, broker.currentBalancer, func(client mq_pb.SeaweedMessagingClient) error {
  14. resp, err = client.CreateTopic(ctx, request)
  15. return nil
  16. })
  17. if proxyErr != nil {
  18. return nil, proxyErr
  19. }
  20. return resp, err
  21. }
  22. ret := &mq_pb.CreateTopicResponse{}
  23. ret.BrokerPartitionAssignments, err = broker.Balancer.LookupOrAllocateTopicPartitions(request.Topic, true)
  24. return ret, err
  25. }
  26. // FindTopicBrokers returns the brokers that are serving the topic
  27. //
  28. // 1. lock the topic
  29. //
  30. // 2. find the topic partitions on the filer
  31. // 2.1 if the topic is not found, return error
  32. // 2.2 if the request is_for_publish, create the topic
  33. // 2.2.1 if the request is_for_subscribe, return error not found
  34. // 2.2.2 if the request is_for_publish, create the topic
  35. // 2.2 if the topic is found, return the brokers
  36. //
  37. // 3. unlock the topic
  38. func (broker *MessageQueueBroker) LookupTopicBrokers(ctx context.Context, request *mq_pb.LookupTopicBrokersRequest) (resp *mq_pb.LookupTopicBrokersResponse, err error) {
  39. if broker.currentBalancer == "" {
  40. return nil, status.Errorf(codes.Unavailable, "no balancer")
  41. }
  42. if !broker.lockAsBalancer.IsLocked() {
  43. proxyErr := broker.withBrokerClient(false, broker.currentBalancer, func(client mq_pb.SeaweedMessagingClient) error {
  44. resp, err = client.LookupTopicBrokers(ctx, request)
  45. return nil
  46. })
  47. if proxyErr != nil {
  48. return nil, proxyErr
  49. }
  50. return resp, err
  51. }
  52. ret := &mq_pb.LookupTopicBrokersResponse{}
  53. ret.Topic = request.Topic
  54. ret.BrokerPartitionAssignments, err = broker.Balancer.LookupOrAllocateTopicPartitions(ret.Topic, request.IsForPublish)
  55. return ret, err
  56. }
  57. // CheckTopicPartitionsStatus check the topic partitions on the broker
  58. func (broker *MessageQueueBroker) CheckTopicPartitionsStatus(c context.Context, request *mq_pb.CheckTopicPartitionsStatusRequest) (*mq_pb.CheckTopicPartitionsStatusResponse, error) {
  59. ret := &mq_pb.CheckTopicPartitionsStatusResponse{}
  60. return ret, nil
  61. }