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.

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