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.

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