如果没有可用的 min.insync.replicas 并且生产者使用 ack=all,则消息不会提交,消费者也不会收到该消息,即使崩溃的副本返回并再次添加到 ISR 列表中也是如此。您可以通过以下方式对此进行测试。
使用 min.insync.replicas = 2 启动两个代理
$ ./bin/kafka-server-start.sh ./config/server-1.properties
$ ./bin/kafka-server-start.sh ./config/server-2.properties
创建一个具有 1 个分区和 RF=2 的主题。确保两个代理都在 ISR 列表中。
$ ./bin/kafka-topics.sh --zookeeper zookeeper-1 --create --topic topic1 --partitions 1 --replication-factor 2
Created topic "topic1".
$ ./bin/kafka-topics.sh --zookeeper zookeeper-1 --describe --topic topic1
Topic:topic1 PartitionCount:1 ReplicationFactor:2 Configs:
Topic: topic1 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2
运行控制台消费者和控制台生产者。确保生产使用 ack=-1
$ ./bin/kafka-console-consumer.sh --new-consumer --bootstrap-server kafka-1:9092,kafka-2:9092 --topic topic1
$ ./bin/kafka-console-producer.sh --broker-list kafka-1:9092,kafka-2:9092 --topic topic1 --request-required-acks -1
产生一些消息。消费者应该收到它们。
杀死一个经纪人(我杀死了 id=2 的经纪人)。检查 ISR 列表是否已减少到一个代理。
$ ./bin/kafka-topics.sh --zookeeper zookeeper-1 --describe --topic topic1
Topic:topic1 PartitionCount:1 ReplicationFactor:2 Configs:
Topic: topic1 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1
再次尝试制作。在生产者中你应该得到一些
Error: NOT_ENOUGH_REPLICAS
(每次重试一次),最后
Messages are rejected since there are fewer in-sync replicas than required.
消费者不会收到这些消息。
重新启动被杀死的代理并尝试再次生产。
消费者将收到这些消息,但不会收到您在其中一个副本关闭时发送的消息。