0
votes

I just started exploring kafka. I have query regarding kafka topic and partitions.

Let assume we have 3 machines x.x.x.1 , x.x.x.2 , x.x.x.3

We have a Topic Test and it has 3 partitions and 3 replica set as the 3 machines above 1,2,3.

Can it be possible that we can write 1st partition data to machine 1. 2nd partition data to machine 2 and 3rd partition data to 3rd machine always?

If it is possible than how?

1

1 Answers

2
votes

The way the partition assignment works is the following. Starting from a random broker-id (which could not be x.x.x.1 but x.x.x.3 instead), the partition leader 0 will be assigned to such broker, the partition leader 1 to the next one and so on. So for example, if the broker x.x.x.2 is chosen then partition leader 0 will be on it (2), partition leader 1 on x.x.x.3 and finally partition leader 2 on x.x.x.1. Regarding the follower replicas they are assigned increasing by one the starting broker : in this example the first follower for partition 0 will be on x.x.x.3, the second follower will be on x.x.x.1. The same will happen for follower replicas for partition 1 and 2. In this way the replication allows HA and the traffic is balanced across the cluster. Btw there is a tool named "kafka-reassign-partitions.sh" you can use for specifying your preferred assignment through a JSON. You can find more here : https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-4.ReassignPartitionsTool