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
1.8 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. cmap "github.com/orcaman/concurrent-map/v2"
  4. "github.com/seaweedfs/seaweedfs/weed/mq/topic"
  5. "reflect"
  6. "testing"
  7. )
  8. func TestBalanceTopicPartitionOnBrokers(t *testing.T) {
  9. brokers := cmap.New[*BrokerStats]()
  10. broker1Stats := &BrokerStats{
  11. TopicPartitionCount: 1,
  12. CpuUsagePercent: 1,
  13. TopicPartitionStats: cmap.New[*TopicPartitionStats](),
  14. }
  15. broker1Stats.TopicPartitionStats.Set("topic1:0", &TopicPartitionStats{
  16. TopicPartition: topic.TopicPartition{
  17. Topic: topic.Topic{Namespace: "topic1", Name: "topic1"},
  18. Partition: topic.Partition{RangeStart: 0, RangeStop: 512, RingSize: 1024},
  19. },
  20. })
  21. broker2Stats := &BrokerStats{
  22. TopicPartitionCount: 2,
  23. CpuUsagePercent: 1,
  24. TopicPartitionStats: cmap.New[*TopicPartitionStats](),
  25. }
  26. broker2Stats.TopicPartitionStats.Set("topic1:1", &TopicPartitionStats{
  27. TopicPartition: topic.TopicPartition{
  28. Topic: topic.Topic{Namespace: "topic1", Name: "topic1"},
  29. Partition: topic.Partition{RangeStart: 512, RangeStop: 1024, RingSize: 1024},
  30. },
  31. })
  32. broker2Stats.TopicPartitionStats.Set("topic2:0", &TopicPartitionStats{
  33. TopicPartition: topic.TopicPartition{
  34. Topic: topic.Topic{Namespace: "topic2", Name: "topic2"},
  35. Partition: topic.Partition{RangeStart: 0, RangeStop: 1024, RingSize: 1024},
  36. },
  37. })
  38. brokers.Set("broker1", broker1Stats)
  39. brokers.Set("broker2", broker2Stats)
  40. type args struct {
  41. brokers cmap.ConcurrentMap[string, *BrokerStats]
  42. }
  43. tests := []struct {
  44. name string
  45. args args
  46. want BalanceAction
  47. }{
  48. {
  49. name: "test",
  50. args: args{
  51. brokers: brokers,
  52. },
  53. want: nil,
  54. },
  55. }
  56. for _, tt := range tests {
  57. t.Run(tt.name, func(t *testing.T) {
  58. if got := BalanceTopicPartitionOnBrokers(tt.args.brokers); !reflect.DeepEqual(got, tt.want) {
  59. t.Errorf("BalanceTopicPartitionOnBrokers() = %v, want %v", got, tt.want)
  60. }
  61. })
  62. }
  63. }