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.

58 lines
1.9 KiB

Merge accumulated changes related to message queue (#5098) * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * tracking topic=>broker * merge * comment
1 year ago
  1. package pub_balancer
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  7. "google.golang.org/grpc"
  8. )
  9. // Balancer <= PublisherToPubBalancer() <= Broker <=> Publish()
  10. // ExecuteBalanceActionMove from Balancer => AssignTopicPartitions() => Broker => Publish()
  11. func (balancer *Balancer) ExecuteBalanceActionMove(move *BalanceActionMove, grpcDialOption grpc.DialOption) error {
  12. if _, found := balancer.Brokers.Get(move.SourceBroker); !found {
  13. return fmt.Errorf("source broker %s not found", move.SourceBroker)
  14. }
  15. if _, found := balancer.Brokers.Get(move.TargetBroker); !found {
  16. return fmt.Errorf("target broker %s not found", move.TargetBroker)
  17. }
  18. err := pb.WithBrokerGrpcClient(false, move.TargetBroker, grpcDialOption, func(client mq_pb.SeaweedMessagingClient) error {
  19. _, err := client.AssignTopicPartitions(context.Background(), &mq_pb.AssignTopicPartitionsRequest{
  20. Topic: move.TopicPartition.Topic.ToPbTopic(),
  21. BrokerPartitionAssignments: []*mq_pb.BrokerPartitionAssignment{
  22. {
  23. Partition: move.TopicPartition.ToPbPartition(),
  24. },
  25. },
  26. IsLeader: true,
  27. IsDraining: false,
  28. })
  29. return err
  30. })
  31. if err != nil {
  32. return fmt.Errorf("assign topic partition %v to %s: %v", move.TopicPartition, move.TargetBroker, err)
  33. }
  34. err = pb.WithBrokerGrpcClient(false, move.SourceBroker, grpcDialOption, func(client mq_pb.SeaweedMessagingClient) error {
  35. _, err := client.AssignTopicPartitions(context.Background(), &mq_pb.AssignTopicPartitionsRequest{
  36. Topic: move.TopicPartition.Topic.ToPbTopic(),
  37. BrokerPartitionAssignments: []*mq_pb.BrokerPartitionAssignment{
  38. {
  39. Partition: move.TopicPartition.ToPbPartition(),
  40. },
  41. },
  42. IsLeader: true,
  43. IsDraining: true,
  44. })
  45. return err
  46. })
  47. if err != nil {
  48. return fmt.Errorf("assign topic partition %v to %s: %v", move.TopicPartition, move.SourceBroker, err)
  49. }
  50. return nil
  51. }