|
|
@ -61,17 +61,17 @@ func (ms MemberState) String() string { |
|
|
|
|
|
|
|
|
// GroupMember represents a consumer in a consumer group
|
|
|
// GroupMember represents a consumer in a consumer group
|
|
|
type GroupMember struct { |
|
|
type GroupMember struct { |
|
|
ID string // Member ID (generated by gateway)
|
|
|
|
|
|
ClientID string // Client ID from consumer
|
|
|
|
|
|
ClientHost string // Client host/IP
|
|
|
|
|
|
SessionTimeout int32 // Session timeout in milliseconds
|
|
|
|
|
|
RebalanceTimeout int32 // Rebalance timeout in milliseconds
|
|
|
|
|
|
Subscription []string // Subscribed topics
|
|
|
|
|
|
Assignment []PartitionAssignment // Assigned partitions
|
|
|
|
|
|
Metadata []byte // Protocol-specific metadata
|
|
|
|
|
|
State MemberState // Current member state
|
|
|
|
|
|
LastHeartbeat time.Time // Last heartbeat timestamp
|
|
|
|
|
|
JoinedAt time.Time // When member joined group
|
|
|
|
|
|
|
|
|
ID string // Member ID (generated by gateway)
|
|
|
|
|
|
ClientID string // Client ID from consumer
|
|
|
|
|
|
ClientHost string // Client host/IP
|
|
|
|
|
|
SessionTimeout int32 // Session timeout in milliseconds
|
|
|
|
|
|
RebalanceTimeout int32 // Rebalance timeout in milliseconds
|
|
|
|
|
|
Subscription []string // Subscribed topics
|
|
|
|
|
|
Assignment []PartitionAssignment // Assigned partitions
|
|
|
|
|
|
Metadata []byte // Protocol-specific metadata
|
|
|
|
|
|
State MemberState // Current member state
|
|
|
|
|
|
LastHeartbeat time.Time // Last heartbeat timestamp
|
|
|
|
|
|
JoinedAt time.Time // When member joined group
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// PartitionAssignment represents partition assignment for a member
|
|
|
// PartitionAssignment represents partition assignment for a member
|
|
|
@ -82,16 +82,16 @@ type PartitionAssignment struct { |
|
|
|
|
|
|
|
|
// ConsumerGroup represents a Kafka consumer group
|
|
|
// ConsumerGroup represents a Kafka consumer group
|
|
|
type ConsumerGroup struct { |
|
|
type ConsumerGroup struct { |
|
|
ID string // Group ID
|
|
|
|
|
|
State GroupState // Current group state
|
|
|
|
|
|
Generation int32 // Generation ID (incremented on rebalance)
|
|
|
|
|
|
Protocol string // Assignment protocol (e.g., "range", "roundrobin")
|
|
|
|
|
|
Leader string // Leader member ID
|
|
|
|
|
|
Members map[string]*GroupMember // Group members by member ID
|
|
|
|
|
|
SubscribedTopics map[string]bool // Topics subscribed by group
|
|
|
|
|
|
OffsetCommits map[string]map[int32]OffsetCommit // Topic -> Partition -> Offset
|
|
|
|
|
|
CreatedAt time.Time // Group creation time
|
|
|
|
|
|
LastActivity time.Time // Last activity (join, heartbeat, etc.)
|
|
|
|
|
|
|
|
|
ID string // Group ID
|
|
|
|
|
|
State GroupState // Current group state
|
|
|
|
|
|
Generation int32 // Generation ID (incremented on rebalance)
|
|
|
|
|
|
Protocol string // Assignment protocol (e.g., "range", "roundrobin")
|
|
|
|
|
|
Leader string // Leader member ID
|
|
|
|
|
|
Members map[string]*GroupMember // Group members by member ID
|
|
|
|
|
|
SubscribedTopics map[string]bool // Topics subscribed by group
|
|
|
|
|
|
OffsetCommits map[string]map[int32]OffsetCommit // Topic -> Partition -> Offset
|
|
|
|
|
|
CreatedAt time.Time // Group creation time
|
|
|
|
|
|
LastActivity time.Time // Last activity (join, heartbeat, etc.)
|
|
|
|
|
|
|
|
|
Mu sync.RWMutex // Protects group state
|
|
|
Mu sync.RWMutex // Protects group state
|
|
|
} |
|
|
} |
|
|
@ -105,8 +105,8 @@ type OffsetCommit struct { |
|
|
|
|
|
|
|
|
// GroupCoordinator manages consumer groups
|
|
|
// GroupCoordinator manages consumer groups
|
|
|
type GroupCoordinator struct { |
|
|
type GroupCoordinator struct { |
|
|
groups map[string]*ConsumerGroup // Group ID -> Group
|
|
|
|
|
|
groupsMu sync.RWMutex // Protects groups map
|
|
|
|
|
|
|
|
|
groups map[string]*ConsumerGroup // Group ID -> Group
|
|
|
|
|
|
groupsMu sync.RWMutex // Protects groups map
|
|
|
|
|
|
|
|
|
// Configuration
|
|
|
// Configuration
|
|
|
sessionTimeoutMin int32 // Minimum session timeout (ms)
|
|
|
sessionTimeoutMin int32 // Minimum session timeout (ms)
|
|
|
@ -123,10 +123,10 @@ type GroupCoordinator struct { |
|
|
func NewGroupCoordinator() *GroupCoordinator { |
|
|
func NewGroupCoordinator() *GroupCoordinator { |
|
|
gc := &GroupCoordinator{ |
|
|
gc := &GroupCoordinator{ |
|
|
groups: make(map[string]*ConsumerGroup), |
|
|
groups: make(map[string]*ConsumerGroup), |
|
|
sessionTimeoutMin: 6000, // 6 seconds
|
|
|
|
|
|
|
|
|
sessionTimeoutMin: 6000, // 6 seconds
|
|
|
sessionTimeoutMax: 300000, // 5 minutes
|
|
|
sessionTimeoutMax: 300000, // 5 minutes
|
|
|
rebalanceTimeoutMs: 300000, // 5 minutes
|
|
|
rebalanceTimeoutMs: 300000, // 5 minutes
|
|
|
stopChan: make(chan struct{}), |
|
|
|
|
|
|
|
|
stopChan: make(chan struct{}), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Start cleanup routine
|
|
|
// Start cleanup routine
|
|
|
|