领导者下线后,卡夫卡是否保持同步复制因子?

Does Kafka maintain the In-sync replication factor after leader goes down?

有人可以解释一下 Kafka 中在以下情况下的同步复制因子维护吗:

场景:

  1. 考虑一下,最初我们的复制因子为 3。
  2. 在 Kafka 中,如果领导者宕机,其中一个同步副本将成为新的领导者。

因此,对于新的领导者(同步副本之一),Kafka 是否再次保持 3 的复制因子。

希望使 Kafka 符号更加清晰:没有“同步复制因子”。每个主题都有一个“复制因子”和一个单独的“同步副本”列表(也称为 ISR)。在一个健康的集群中,复制因子和同步副本的数量匹配,但一旦一个代理崩溃,这些数字可能会偏离,因为您将拥有不同步的副本。

"so, for the new leader(one of the in-sync replica) does Kafka again maintain the replication factor of 3."

是(也不是)。 Kafka 将坚持 3 的复制因子。但是,它希望崩溃的代理再次可用。在那段时间你的话题将有

  • 新领导(正如您在第二个要点中提到的那样)
  • 复制因子 3
  • 只有两个同步副本

因此,尽管您的复制因子为 3,但您的主题将有一个不同步的副本。

在代理重启之前,它现在取决于 KafkaProducer 配置 acksmin.insync.replicas 生产者是否仍然可以成功地将数据写入主题。 min.insync.replicas 的描述提供了更多细节:

"When a producer sets acks to "all" (or "-1"), min.insync.replicas specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful."

Balancing leadership 上的 Kafka 文档提供了分区领导者发生的一些背景:

Whenever a broker stops or crashes, leadership for that broker's partitions transfers to other replicas. When the broker is restarted it will only be a follower for all its partitions, meaning it will not be used for client reads and writes.

To avoid this imbalance, Kafka has a notion of preferred replicas. If the list of replicas for a partition is 1,5,9 then node 1 is preferred as the leader to either node 5 or 9 because it is earlier in the replica list. By default the Kafka cluster will try to restore leadership to the restored replicas. This behaviour is configured with:

auto.leader.rebalance.enable=true