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.

36 lines
1.2 KiB

  1. package coordinator
  2. import (
  3. cmap "github.com/orcaman/concurrent-map/v2"
  4. "github.com/seaweedfs/seaweedfs/weed/mq/topic"
  5. )
  6. type ConsumerGroupInstance struct {
  7. ClientId string
  8. // the consumer group instance may not have an active partition
  9. Partition *topic.Partition
  10. // processed message count
  11. ProcessedMessageCount int64
  12. }
  13. type ConsumerGroup struct {
  14. // map a client id to a consumer group instance
  15. ConsumerGroupInstances cmap.ConcurrentMap[string, *ConsumerGroupInstance]
  16. MinimumActiveInstances int32
  17. MaximumActiveInstances int32
  18. }
  19. type TopicConsumerGroups struct {
  20. // map a consumer group name to a consumer group
  21. ConsumerGroups cmap.ConcurrentMap[string, *ConsumerGroup]
  22. }
  23. // Coordinator coordinates the instances in the consumer group for one topic.
  24. // It is responsible for:
  25. // 1. Assigning partitions to consumer instances.
  26. // 2. Reassigning partitions when a consumer instance is down.
  27. // 3. Reassigning partitions when a consumer instance is up.
  28. type Coordinator struct {
  29. // map client id to subscriber
  30. Subscribers cmap.ConcurrentMap[string, *ConsumerGroupInstance]
  31. // map topic name to consumer groups
  32. TopicSubscribers cmap.ConcurrentMap[string, map[string]TopicConsumerGroups]
  33. }