Kafka - 故障排除.NotEnoughReplicasException

Kafka - Troubleshooting .NotEnoughReplicasException

我开始看到以下错误

[2020-06-12 20:09:01,324] ERROR [ReplicaManager broker=3] Error processing append operation on partition __consumer_offsets-10 (kafka.server.ReplicaManager)
org.apache.kafka.common.errors.NotEnoughReplicasException: The size of the current ISR Set(3) is insufficient to satisfy the min.isr requirement of 2 for partition __consumer_offsets-10    

My setup is having three brokers and all brokers are up. Couple of things i did before this error was about pop up

I configured min.isr to be 2 in all the brokers. I created a topic with replication factor 3 and starting producing the message from a producer with ack = 1 with two brokers down. I brought up all the brokers and started consumer.

  1. 如何解决此错误
  2. 消费者也无法看到此消息(不知道为什么,该消息应该被视为 "committed",因为当生产者 运行 时,一个代理已启动)

几个事实

看到再平衡没有发生很有趣 WRT 首选领导者策略

$ kafka-topics --zookeeper 127.0.0.1:2181 --topic stock-prices --describe                             
  Topic: stock-prices     PartitionCount: 3       ReplicationFactor: 3    Configs: min.insync.replicas=2
  Topic: stock-prices     Partition: 0    Leader: 1       Replicas: 1,3,2 Isr: 1,2,3            
  Topic: stock-prices     Partition: 1    Leader: 1       Replicas: 2,1,3 Isr: 1,2,3            
  Topic: stock-prices     Partition: 2    Leader: 1       Replicas: 3,2,1 Isr: 1,2,3

这是你的问题:

您已设置min.insync.replicas=2,这意味着您至少需要两个代理人并运行向主题发布消息。如果你让 2 个经纪人失望,那么你就只剩下一个了。这意味着您的 insync.replica 要求未满足。

这与消费者无关,因为这是关于经纪人的。当您设置 acks=1 时,这意味着您的生产者会在消息发布到一个代理时获得确认。 (它不会确认所有副本都已创建)。

所以问题是,当单个代理(领导者)收到消息时,您有生产者确认收到了消息。但是领导者不能放置副本,因为没有任何代理要同步。

完成此操作的一种方法是设置 acks=all,这样您的生产者在所有副本完成之前不会得到确认。它将重试,直到至少 2 个同步副本在线。