Kafka GroupCoordinator机制(十):GroupCoordinator之GroupState

本文详细解析了Kafka中消费者组的四种状态:PreparingRebalance、AwaitngSync、Stable和Dead,以及它们之间的转换条件。在不同状态下,消费者组如何处理offsetFetchRequest、leaveGroupRequest、offsetCommitRequest等请求,为理解Kafka消费者组的工作机制提供了深入的视角。

GroupState接口用于表示消费者组的状态,四个子类分别代表四个不同的状态:

PreparingRebalance:消费者组正在进行rebalance操作
当消费者处于这个状态时,GroupCoordinator可以正常处理offsetFetchRequest、leaveGroupRequest、offsetCommitRequest,但对于收到heartbeatrequest和SyncGropRequest,则会在其响应中携带REBALANCE_IN_PROGRESS错误进行标识。当收到joinGroupRequest时,GroupCoordinator会创建对应的DelayJoin,等待条件满足后进行响应。
PreparingRebalance --> AwaitngSync
当有delayedJoin超时或者消费者组之前的member已经重新申请加入时进行的切换
PreparingRebalance --> Dead
所有member离开消费者组

AwaitngSync:消费者组正在等待group leader将分区的分配结果发送到GroupCoordinator
当消费者组处于这个状态时,表示正在等待group leader将分区的分配结果。当收到offsetCommitRequest和HeartbeatRequest时,则会在其响应中携带REBALANCE_IN_PROGRESS错误进行标识。对于来自Group Follower的SyncGroupRequest,则直接抛弃,直到收到leader的SyncGroupRequest时一起响应。
AwaitngSync --> Stable 
收到leader的SyncGroupRequest
AwaitngSync --> PreparingRebalance
三种情况触发:1. 有消费者加入或者退出消费者组。2. 新的member请求加入消费者组。3. 消费者组中有member心跳超时


Stable:消费者处于正常状态
此状态可以处理所有请求
Stable --> PreparingRebalance
1. 消费者组中有member心跳超时。2. 有消费者主动退出消费者组。 3. 新的member请求加入消费者组 4. 当前group leader发送JoinGroupRequest


Dead:已经没有member存在。
除了OffsetCommitRequest,其他请求的响应会携带UNKNOWN_MEMBER_ID错误码标志。.

 

ta@10-102-21-72:/app/ta#[2025-11-30 15:07:58,504] INFO [GroupCoordinator 0]: Member consumer-ta-system-1-6a5ce779-f148-49cd-a80e-493c5fd9fb07 in group ta-system has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:58,505] INFO [GroupCoordinator 0]: Preparing to rebalance group ta-system in state PreparingRebalance with old generation 1 (__consumer_offsets-27) (reason: removing member consumer-ta-system-1-6a5ce779-f148-49cd-a80e-493c5fd9fb07 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:58,505] INFO [GroupCoordinator 0]: Member consumer-ta-system-2-26c2148c-bc0b-44c2-beca-ed1959310432 in group ta-system has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,131] INFO [GroupCoordinator 0]: Member consumer-1.10.102.21.72.8081-7-a6d9374c-f30c-441a-81d1-0d8e6ee24087 in group 1.10.102.21.72.8081 has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,132] INFO [GroupCoordinator 0]: Preparing to rebalance group 1.10.102.21.72.8081 in state PreparingRebalance with old generation 1 (__consumer_offsets-26) (reason: removing member consumer-1.10.102.21.72.8081-7-a6d9374c-f30c-441a-81d1-0d8e6ee24087 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,132] INFO [GroupCoordinator 0]: Group 1.10.102.21.72.8081 with generation 2 is now empty (__consumer_offsets-26) (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,140] INFO [GroupCoordinator 0]: Member consumer-ta-system-6-4c313058-e169-4e8e-9a1a-a5cbbb7ff564 in group ta-system has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,141] INFO [GroupCoordinator 0]: Member consumer-ta-system-3-17359b5c-8a72-4771-9337-547610041773 in group ta-system has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,141] INFO [GroupCoordinator 0]: Group ta-system with generation 2 is now empty (__consumer_offsets-27) (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,142] INFO [GroupCoordinator 0]: Member consumer-ta-system-0-5-e4b4818a-7859-4ee9-86d4-10a6f84ba63a in group ta-system-0 has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,142] INFO [GroupCoordinator 0]: Preparing to rebalance group ta-system-0 in state PreparingRebalance with old generation 1 (__consumer_offsets-0) (reason: removing member consumer-ta-system-0-5-e4b4818a-7859-4ee9-86d4-10a6f84ba63a on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,142] INFO [GroupCoordinator 0]: Member consumer-ta-system-0-4-5b716cbf-c54c-4489-87ed-0f032b5d7787 in group ta-system-0 has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-11-30 15:07:59,142] INFO [GroupCoordinator 0]: Group ta-system-0 with generation 2 is now empty (__consumer_offsets-0) (kafka.coordinator.group.GroupCoordinator) 什么意思
最新发布
12-01
[2025-08-27 13:09:01,678] INFO [GroupCoordinator 0]: Member consumer-parameter-center-1-d95fce90-e26e-48d7-837c-2845cb0438c2 in group parameter-center has failed, removing it from the group (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:01,678] INFO [GroupCoordinator 0]: Preparing to rebalance group parameter-center in state PreparingRebalance with old generation 45 (__consumer_offsets-5) (reason: removing member consumer-parameter-center-1-d95fce90-e26e-48d7-837c-2845cb0438c2 on heartbeat expiration) (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:01,679] INFO [GroupCoordinator 0]: Group parameter-center with generation 46 is now empty (__consumer_offsets-5) (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:15,081] INFO [GroupCoordinator 0]: Dynamic member with unknown member id joins group parameter-center in Empty state. Created a new member id consumer-parameter-center-1-259749a3-143e-40ae-bef8-88710069ea5d and request the member to rejoin with this id. (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:15,083] INFO [GroupCoordinator 0]: Preparing to rebalance group parameter-center in state PreparingRebalance with old generation 46 (__consumer_offsets-5) (reason: Adding new member consumer-parameter-center-1-259749a3-143e-40ae-bef8-88710069ea5d with group instance id None; client reason: rebalance failed due to MemberIdRequiredException) (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:15,085] INFO [GroupCoordinator 0]: Stabilized group parameter-center generation 47 (__consumer_offsets-5) with 1 members (kafka.coordinator.group.GroupCoordinator) [2025-08-27 13:09:15,100] INFO [GroupCoordinator 0]: Assignment received from leader consumer-parameter-center-1-259749a3-143e-40ae-bef8-88710069ea5d for group parameter-center for generation 47. The group has 1 members, 0 of which are static. (kafka.coordinator.group.GroupCoordinator) ^C 什么错误
08-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值