__consumer_offsets成为位移主题,有以下知识点
1.由kafka自己创建,默认50个分区,每个分区3个副本
2.例如partition-1的leader为broker 4. isr为 4,6,8 ar为4,6,8
3.一个group,计算group的hash值,对50取余得出0-49的值,如果是1则这个group的group coordinator在partition-1的leader所在的broker上
4.__consumer_offsets保存了组元数据和offset元数据,根据key不同来区分为
OffsetKey和GroupMetadataKey,两种key根据key的第一个字节的值确定,现在只有1,2两种
5.组元数据内容如下
connect-standalone-test-sink::GroupMetadata(groupId=connect-standalone-test-sink, generation=152, protocolType=Some(consumer), currentState=Stable, members=Map(connector-consumer-standalone-test-sink-1-269a4f9d-65e9-4093-bf8b-94d435d7ab66 -> MemberMetadata(memberId=connector-consumer-standalone-test-sink-1-269a4f9d-65e9-4093-bf8b-94d435d7ab66, clientId=connector-consumer-standalone-test-sink-1, clientHost=/10.73.42.235, sessionTimeoutMs=10000, rebalanceTimeoutMs=300000, supportedProtocols=List(range), ), connector-consumer-standalone-test-sink-2-42ada095-1ec4-4702-a292-bcf9df8afe8e -> MemberMetadata(memberId=connector-consumer-standalone-test-sink-2-42ada095-1ec4-4702-a292-bcf9df8afe8e, clientId=connector-consumer-standalone-test-sink-2, clientHost=/10.73.42.235, sessionTimeoutMs=10000, rebalanceTimeoutMs=300000, supportedProtocols=List(range), ), connector-consumer-standalone-test-sink-0-2ef73063-a458-4411-990a-46390ff06e89 -> MemberMetadata(memberId=connector-consumer-standalone-test-sink-0-2ef73063-a458-4411-990a-46390ff06e89, clientId=connector-consumer-standalone-test-sink-0, clientHost=/10.73.42.235, sessionTimeoutMs=10000, rebalanceTimeoutMs=300000, supportedProtocols=List(range), )))
connect-standalone-test-sink为组名
generation=152 新建group为0,rebalance一次+1
protocolType现在只有consumer和connect两种
currentState组状态,有5种
members组成员信息
6.offsets数据内容:
[test-consumer-group,__consumer_offsets,5]::[OffsetMetadata[4,NO_METADATA],CommitTime 1615969332496,ExpirationTime 1616833332496]
[group名,topic名,partition]
OffsetMetadata[4,NO_METADATA] 里面保存了具体的offset,这个offset为4
读取__consumer_offsets的方式:
./kafka-console-consumer --topic __consumer_offsets --bootstrap-server ip:9092 --formatter "kafka.coordinator.group.GroupMetadataManager\$OffsetsMessageFormatter" --consumer.config ../etc/kafka/consumer.properties --from-beginning