简体   繁体   English

故障转移如何在 kafka 中与保持复制因子一起工作

[英]How failover works in kafka along with keeping up replication factor

I am trying to understand how failover and replication factors work in kafka.我试图了解故障转移和复制因素在 kafka 中是如何工作的。

Let's say my cluster has 3 brokers and replication factor is also 3. In this case each broker will have one copy of partition and one of the broker is leader.假设我的集群有 3 个代理,复制因子也是 3。在这种情况下,每个代理将拥有一份分区副本,其中一个代理是领导者。 If leader broker fails, then one of the follower broker will become leader but now the replication factor is down to 2. At this point if I add a new broker in the cluster, will kafka make sure that replication factor is 3 and will it copy the required data on the new broker.如果领导代理失败,那么其中一个跟随代理将成为领导,但现在复制因子降至 2。此时如果我在集群中添加一个新代理,kafka 将确保复制因子为 3 并复制新经纪人所需的数据。

How will above scenario work if my cluster already has an addition broker.如果我的集群已经有一个附加代理,上述场景将如何工作。

Leaving out partitions (which is another concept of Kafka):省略分区(这是 Kafka 的另一个概念):

The replication factor does not say how many times a topic is replicated, but rather how many times it should be replicated.复制因子不是说一个主题复制了多少次,而是它应该被复制多少次。 It is not affected by brokers shutting down.它不受经纪人关闭的影响。

Once a leader broker shuts down, the "leader" status goes over to another broker which is in sync , that means a broker that has the current state replicated and is not behind.一旦领导者代理关闭,“领导者”状态就会转移到另一个同步的代理,这意味着复制了当前状态并且不落后的代理。 Electing "leader" status to a broker that is not in sync would obviously lead to data loss, so this will never happen (when using the right settings).为不同步的代理选择“领导者”状态显然会导致数据丢失,因此这永远不会发生(使用正确的设置时)。

These replicas eligible for taking "leader status" are called in-sync replica (ISR) , which is important, as there is a configuration called min.insync.replicas that specifies how many ISR have to exist for a Kafka message to be acknowledged.这些符合“领导地位”的副本称为同步副本(ISR) ,这很重要,因为有一个名为min.insync.replicas的配置,它指定必须存在多少个 ISR 才能确认 Kafka 消息。 If this is set to 0, every Kafka message is acknowledged as "successful" as soon as it enters the "leader" broker, if this broker would die, all data that was not replicated yet is lost.如果将其设置为 0,则每条 Kafka 消息一进入“领导”代理就被确认为“成功”,如果该代理死亡,则所有尚未复制的数据都将丢失。 If min.insync.replicas would be set to 1, every message waits with the acknowledgement, until at least 1 replica exists in order to be "successful", so if the broker would die now, there would be a replica covering this data.如果将min.insync.replicas设置为 1,则每条消息都会等待确认,直到至少存在 1 个副本才能“成功”,因此如果代理现在死亡,则会有一个副本覆盖此数据。 If there are not enough brokers to cover the minimum amount of replicas, your cluster will fail eventually.如果没有足够的代理来覆盖最小数量的副本,您的集群最终将失败。

So to answer your question: if you had 2 running brokers, min.insync.replicas=1 (default) and replication factor of 3, your cluster runs fine and will add a replica as soon as you start up another broker.所以回答你的问题:如果你有 2 个正在运行的代理, min.insync.replicas=1 (默认)和 3 的复制因子,你的集群运行良好,并且会在你启动另一个代理后立即添加一个副本。 If another of the 2 brokers dies before you launch the third one, you will run into problems.如果 2 个经纪人中的另一个在您启动第三个经纪人之前死亡,您将遇到问题。

In your setup (3 broker, 3 replicas), when 1 broker fails Kafka will automatically elect new leaders (on the remaining brokers) for all the partitions whose leaders were on the failing broker.在您的设置中(3 个代理,3 个副本),当 1 个代理失败时,Kafka 将自动为其领导者在失败的代理上的所有分区选举新的领导者(在剩余的代理上)。

The replication factor does not change.复制因子不会改变。 The replication factor is a topic configuration that can only be changed by the user.复制因子是一种只能由用户更改的主题配置。

Similarly the Replica list does not change.同样,副本列表不会更改。 This lists the brokers that should host each partition.这列出了应该托管每个分区的代理。

However, the In Sync Replicas (ISR) list will change and only contain the 2 remaining brokers.但是,In Sync Replicas (ISR) 列表将更改并且仅包含剩余的 2 个代理。

If you add another broker to the cluster, what happens depend on its broker.id :如果您向集群添加另一个代理,会发生什么取决于它的broker.id

  • if the broker.id is the same as the broker that failed, this new broker will start replicating data and eventually join the ISR for all the existing partitions.如果broker.id与失败的 broker 相同,则这个新 broker 将开始复制数据并最终加入所有现有分区的 ISR。
  • if it uses a different broker.id , nothing will happen.如果它使用不同的broker.id ,则不会发生任何事情。 You will be able to create new topics with 3 replicas (that is not possible while there are only 2 brokers) but Kafka will not automatically replicate existing partitions.您将能够使用 3 个副本创建新主题(只有 2 个代理时这是不可能的),但 Kafka 不会自动复制现有分区。 You can manually trigger a reassignment if needed, see the docs .如果需要,您可以手动触发重新分配,请参阅文档

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

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