简体   繁体   English

如果我在 kafka 中有复制因子为 3 的单个代理怎么办?

[英]what if I have single broker with replication factor as 3 in kafka?

If I am creating a new cluster with 1 broker 1 topic 1 partition and replication factor as 3,then what happens ?It creates 3 replicas(Partition) under that single broker ?如果我创建一个新集群,其中 1 个代理 1 个主题 1 个分区和复制因子为 3,那么会发生什么?它在该单个代理下创建了 3 个副本(分区)? If yes,how the leader is elected ?如果是,领导者是如何选举出来的?

If you try to create a topic with a replication factor larger than the available number of brokers in your clusters you will get an Exception as below.如果您尝试创建复制因子大于集群中可用代理数量的主题,您将收到如下异常。

> ./kip-kafka-topics --create --topic multiple_replicas_on_single_broker --replication-factor 3 --partitions 10

Error while executing topic command : org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 1.
[2020-09-15 17:45:42,649] ERROR java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 1.
        at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)
        at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)
        at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:89)
        at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:260)
        at kafka.admin.TopicCommand$AdminClientTopicService.createTopic(TopicCommand.scala:175)
        at kafka.admin.TopicCommand$TopicService.createTopic(TopicCommand.scala:134)
        at kafka.admin.TopicCommand$TopicService.createTopic$(TopicCommand.scala:129)
        at kafka.admin.TopicCommand$AdminClientTopicService.createTopic(TopicCommand.scala:157)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:60)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)
Caused by: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 3 larger than available brokers: 1.

In the Kafka documentaion in the section Replication it is explained that the replication is done for server failures:在复制部分的 Kafka 文档中,解释了复制是针对服务器故障完成的:

Kafka replicates the log for each topic's partitions across a configurable number of servers (you can set this replication factor on a topic-by-topic basis). Kafka 在可配置数量的服务器上复制每个主题分区的日志(您可以逐个主题地设置此复制因子)。 This allows automatic failover to these replicas when a server in the cluster fails so messages remain available in the presence of failures.这允许在集群中的服务器出现故障时自动故障转移到这些副本,以便在出现故障时消息仍然可用。

Therefore, if you place more than one replca on a single server it would not be able to recover if that one server goes down.因此,如果您在一台服务器上放置多个 replca,如果该服务器出现故障,它将无法恢复。


Looking at your question "It creates 3 replicas(Partition) under that single broker ?"查看您的问题“它在该单个代理下创建了 3 个副本(分区)?” I would also recommend to clearly understand the difference between a replica and a partition .我还建议您清楚地了解副本分区之间的区别。 This post might help you.这篇文章可能对你有帮助。

You are welcome to try yourself...欢迎你自己尝试...

You will get an error saying replicas is more than available brokers你会得到一个错误,说副本比可用的代理多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM