Kafka Queue: 完成 alterShareGroupOffsets Api

Share group支持重置偏移量

支持重置偏移量,换句话说也就是支持消息的重放;classic group支持按照偏移量或者时间重置到最新、最老以及指定时间的偏移量

PR list

命令

kafka-share-groups.sh --bootstrap-server localhost:9092 --group S1 --topic T1 --reset-offsets --to-earliest --execute

SPSO

Share group引入了SPSO(Share-partition start offset) 的概念,可以理解为当前第一个被客户端拉走,但是未被提交的record batches,这个功能主要就是对SPSO进行操作

新增请求与响应

请求体

json 复制代码
{
  "apiKey": 91,
  "type": "request",
  "listeners": ["broker"],
  "name": "AlterShareGroupOffsetsRequest",
  "validVersions": "0",
  "flexibleVersions": "0+",
  "fields": [
    { "name": "GroupId", "type": "string", "versions": "0+", "entityType": "groupId",
      "about": "The group identifier." },
    { "name": "Topics", "type": "[]AlterShareGroupOffsetsRequestTopic", "versions": "0+",
      "about": "The topics to alter offsets for.",  "fields": [
        { "name": "TopicName", "type": "string", "versions": "0+", "entityType": "topicName", "mapKey": true,
          "about": "The topic name." },
        { "name": "Partitions", "type": "[]AlterShareGroupOffsetsRequestPartition", "versions": "0+",
          "about": "Each partition to alter offsets for.", "fields": [
            { "name": "PartitionIndex", "type": "int32", "versions": "0+",
              "about": "The partition index." },
            { "name": "StartOffset", "type": "int64", "versions": "0+",
              "about": "The share-partition start offset." }
          ]}
      ]}
  ]
}

响应体

json 复制代码
{
  "apiKey": 91,
  "type": "response",
  "name": "AlterShareGroupOffsetsResponse",
  "validVersions": "0",
  "flexibleVersions": "0+",
  // Supported errors:
  // - GROUP_AUTHORIZATION_FAILED (version 0+)
  // - TOPIC_AUTHORIZATION_FAILED (version 0+)
  // - NOT_COORDINATOR (version 0+)
  // - COORDINATOR_NOT_AVAILABLE (version 0+)
  // - COORDINATOR_LOAD_IN_PROGRESS (version 0+)
  // - GROUP_ID_NOT_FOUND (version 0+)
  // - NON_EMPTY_GROUP (version 0+)
  // - KAFKA_STORAGE_ERROR (version 0+)
  // - INVALID_REQUEST (version 0+)
  // - UNKNOWN_SERVER_ERROR (version 0+)
  "fields": [
    { "name": "ThrottleTimeMs", "type": "int32", "versions": "0+",
      "about": "The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota." },
    { "name": "ErrorCode", "type": "int16", "versions": "0+",
      "about": "The top-level error code, or 0 if there was no error." },
    { "name": "ErrorMessage", "type": "string", "versions": "0+", "nullableVersions": "0+", "default": "null",
      "about": "The top-level error message, or null if there was no error." },
    { "name": "Responses", "type": "[]AlterShareGroupOffsetsResponseTopic", "versions": "0+",
      "about": "The results for each topic.", "fields": [
        { "name": "TopicName", "type": "string", "versions": "0+", "entityType": "topicName", "mapKey": true,
          "about": "The topic name." },
        { "name": "TopicId", "type": "uuid", "versions": "0+",
          "about": "The unique topic ID." },
        { "name": "Partitions", "type": "[]AlterShareGroupOffsetsResponsePartition", "versions": "0+", "fields": [
          { "name": "PartitionIndex", "type": "int32", "versions": "0+",
            "about": "The partition index." },
          { "name": "ErrorCode", "type": "int16", "versions": "0+",
            "about": "The error code, or 0 if there was no error." },
          { "name": "ErrorMessage", "type": "string", "versions": "0+", "nullableVersions": "0+", "default": "null",
            "about": "The error message, or null if there was no error." }
        ]}
      ]}
  ]
}

主要过程

  1. 只有空的消费组支持重置
  2. 重置过程中,会触发一次Group Coordinator初始化ShareGroupState的过程
  3. Group Coordinator向Share Coordinator持久化一条InitialzeShareGroupState的请求,持久化写入__share_group_state内部Topic

过程中遇到的问题

1、代码习惯、缩进以及语言风格的问题;

2、参数校验以及异常处理,各种情况下的参数抛出,比如下面这些场景

3、因为写API的过程中参考了ConsumerGroup的实现,没有注意到错误码的处理过程,实际上对于经典消费组重置偏移量的过程,是通过提交一个新的CommitOffset 请求来实现的,并没有所为顶层错误码的概念; 但是后在AlterShareGroupOffsetsResponse的响应体存在顶层的异常ErrorCode与ErrorMessage,但是实做过程中没有处理并封装到各个分区的响应中。后来AJ写了一个follow-up完成了这块:https://github.com/apache/kafka/pull/20049/files

相关推荐
旷野说2 小时前
如何用 Redpanda + 本地事务,实现“发消息 + 写 DB” 的强一致性!
java·数据库·kafka
最笨的羊羊2 小时前
Flink CDC系列之: Kafka 数据接收器工厂类KafkaDataSinkFactory
kafka·flink cdc系列·数据接收器工厂类·kafkadata·sinkfactory
s***46983 小时前
Spring Boot集成Kafka:最佳实践与详细指南
spring boot·kafka·linq
Rust语言中文社区8 小时前
【Rust日报】 walrus:分布式消息流平台,比 Kafka 快
开发语言·分布式·后端·rust·kafka
最笨的羊羊11 小时前
Flink CDC系列之: Kafka 数据接收器实现类KafkaDataSink
kafka·flink cdc系列·数据接收器实现类·kafkadatasink
大迪吃小迪11 小时前
Kafka 技术问答总结文档(与RocketMQ对比)
分布式·kafka
杀死那个蝈坦12 小时前
UV 统计(独立访客统计)
java·jvm·spring·kafka·tomcat·maven
z***565612 小时前
Spring Boot集成Kafka:最佳实践与详细指南
spring boot·kafka·linq
9***Y481 天前
后端在分布式中的Apache Kafka
分布式·kafka
yumgpkpm1 天前
腾讯TBDS和Cloud Data AI CMP 比较的缺陷在哪里?
hive·hadoop·elasticsearch·zookeeper·spark·kafka·hbase