Kafka partition and the allocation of replicas in broker

Source: Internet
Author: User

Kafka partition and the allocation of replicas in broker

Part of the content is referenced from: http://blog.csdn.net/lizhitao/article/details/41778193

The following is an example of 4 brokers in a Kafka cluster, creating 1 topic containing 4 partition,2 Replication; data producer Flow:
(1)

Pic

(2) When a new 2 node is added to the cluster, the distribution of partition to 6 is as follows:

The copy assignment logic rules are as follows:
In a Kafka cluster, each broker has an equal allocation of partition leader opportunities.
In the above diagram broker partition, the arrows point to a copy, in Partition-0 as an example: Leader,broker2 in Partition-0 as a copy in Broker1 parition-0.
Each broker in the above diagram (ordered by Brokerid) assigns the main partition, the next broker is a copy, so the iteration is iterated, and the multiple replicas follow this rule.

The copy assignment algorithm is as follows:
Sort all n broker and I partition to be allocated.
Assign the I partition to the first (i mod n) broker.
The first J copies of the partition are assigned to the ((i + j) mod n) broker.

In fact, the above algorithm is wrong, because it is obvious that each topic partition 0 will be allocated on broker 0, the 1th partition is assigned to broker 1, until the partition ID exceeds the broker's data begins to repeat from scratch, This causes the pressure on the front several machines to be greater than the pressure on the rear machine.

Therefore, Kafka is to randomly pick a broker to place partition 0, and then place other partitions sequentially. As the case:

Topic:ljh_test3 PartitionCount:10       ReplicationFactor:2     Configs:    Topic: ljh_test3        Partition: 0    Leader: 5       Replicas: 5,6   Isr: 5,6    Topic: ljh_test3        Partition: 1    Leader: 6       Replicas: 6,7   Isr: 6,7    Topic: ljh_test3        Partition: 2    Leader: 7       Replicas: 7,2   Isr: 7,2    Topic: ljh_test3        Partition: 3    Leader: 2       Replicas: 2,3   Isr: 2,3    Topic: ljh_test3        Partition: 4    Leader: 3       Replicas: 3,4   Isr: 3,4    Topic: ljh_test3        Partition: 5    Leader: 4       Replicas: 4,5   Isr: 4,5    Topic: ljh_test3        Partition: 6    Leader: 5       Replicas: 5,7   Isr: 5,7    Topic: ljh_test3        Partition: 7    Leader: 6       Replicas: 6,2   Isr: 6,2    Topic: ljh_test3        Partition: 8    Leader: 7       Replicas: 7,3   Isr: 7,3    Topic: ljh_test3        Partition: 9    Leader: 2       Replicas: 2,4   Isr: 2,4

Here partition 0 is put into BROKER5, partition 1–BROKER6, Partition 2-broker7 ....

Let's look at an example:

Topic:ljh_test2 PartitionCount:10       ReplicationFactor:2     Configs:    Topic: ljh_test2        Partition: 0    Leader: 2       Replicas: 2,7   Isr: 2,7    Topic: ljh_test2        Partition: 1    Leader: 3       Replicas: 3,2   Isr: 3,2    Topic: ljh_test2        Partition: 2    Leader: 4       Replicas: 4,3   Isr: 4,3    Topic: ljh_test2        Partition: 3    Leader: 5       Replicas: 5,4   Isr: 5,4    Topic: ljh_test2        Partition: 4    Leader: 6       Replicas: 6,5   Isr: 6,5    Topic: ljh_test2        Partition: 5    Leader: 7       Replicas: 7,6   Isr: 7,6    Topic: ljh_test2        Partition: 6    Leader: 2       Replicas: 2,3   Isr: 2,3    Topic: ljh_test2        Partition: 7    Leader: 3       Replicas: 3,4   Isr: 3,4    Topic: ljh_test2        Partition: 8    Leader: 4       Replicas: 4,5   Isr: 4,5    Topic: ljh_test2        Partition: 9    Leader: 5       Replicas: 5,6   Isr: 5,6

Copyright NOTICE: This article is the original blogger article, reprint please specify from http://www.lujinhong.com http://blog.csdn.net/lujinhong2/

Kafka partition and the allocation of replicas in broker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.