模式注册表失败,因为 _schema 复制因子

Schema registry failed because _schema replication factor

我想在这里分享一个关于当注册服务是 Kafka 机器的一部分时失败的模式注册服务的研究案例

我们的集群中有 7 台 Kafka 代理机器,在每台机器上我们都有模式注册服务

我们在其中一个 Kafka 代理上发现了以下错误

WARN The replication factor of the schema topic _schemas is less than the desired one of 3. If this is a production environment, it's crucial to add more brokers and increase the replication factor of the topic. (io.confluent.kafka.schemaregistry.storage.KafkaStore)
[2022-02-10 15:09:59,958] ERROR Server died unexpectedly:  (io.confluent.kafka.schemaregistry.rest.SchemaRegistryMain)
java.lang.IllegalArgumentException: Unable to subscribe to the Kafka topic _schemas backing this data store. Topic may not exist.

所以从上面的日志看来模式失败是因为复制因子不是预期的 3?

所以我们 运行 描述了 Kafka,我们得到以下内容:

kafka-topics -zookeeper kafka01:2181 --describe --topic _schemas

Topic:_schemas  PartitionCount:1    ReplicationFactor:1 Configs:cleanup.policy=compact
    Topic: _schemas Partition: 0    Leader: 3   Replicas: 3 Isr: 3

从上面我们确实看到 topic-_schema 的复制因子为 1

基于这些细节,我们正在考虑执行以下步骤:

第 1 步

为了增加复制因子,我们需要创建以下 json 文件:

json 模板示例:

{"version":1,
  "partitions":[
     {"topic":"signals","partition":0,"replicas":[0,1,2]},
     {"topic":"signals","partition":1,"replicas":[0,1,2]},
     {"topic":"signals","partition":2,"replicas":[0,1,2]}
]}

但在我们的例子中,关于我们的 _schema 主题 json 应该是这样的:

more increase-replication-factor.json

{
 "version":1,
 "partitions":[
{"topic":"_schemas","partition":0,"replicas":[2,3,1]}
 ]
}

第 2 步

那么我们应该运行以下内容:

kafka-reassign-partitions --zookeeper kafka01:2181 --reassignment-json-file increase-replication-factor.json  --execute

非常感谢您对 STEP1,STEP2 的意见,以解决有关模式注册服务的问题

参考文献 -

如果您在该主题中已有架构,那么这些步骤肯定会奏效。 (注意:--zookeeper标志在最新版本的Kafka(v3.0+)中被--bootstrap-server取代)

否则,在全新安装时,您可以简单地删除主题,并编辑 schema-registry.properties 以设置 kafkastore.topic.replication.factor=3(顺便说一句,这是默认设置),然后重新启动注册表重新创建主题。

此外,您最多不需要超过 2 或 3 个注册表服务器。