简体   繁体   English

Kafka主题和分区

[英]Kafka topic and partition

I just started exploring kafka. 我刚刚开始探索卡夫卡。 I have query regarding kafka topic and partitions. 我有关于kafka主题和分区的查询。

Let assume we have 3 machines xxx1 , xxx2 , xxx3 假设我们有3台机器xxx1,xxx2,xxx3

We have a Topic Test and it has 3 partitions and 3 replica set as the 3 machines above 1,2,3. 我们有一个主题测试,它有3个分区和3个副本集,分别是1,2,3之上的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? 我们是否可以始终将第一分区数据写入计算机1。将第二分区数据写入计算机2,将第三分区数据始终写入第三计算机?

If it is possible than how? 如果有可能比呢?

The way the partition assignment works is the following. 分区分配的工作方式如下。 Starting from a random broker-id (which could not be xxx1 but xxx3 instead), the partition leader 0 will be assigned to such broker, the partition leader 1 to the next one and so on. 从一个随机代理ID(不能是xxx1,而是xxx3)开始,分区负责人0将分配给该代理,分区负责人1分配给下一个代理,依此类推。 So for example, if the broker xxx2 is chosen then partition leader 0 will be on it (2), partition leader 1 on xxx3 and finally partition leader 2 on xxx1. 因此,例如,如果选择了代理xxx2,则分区领导0将在其上(2),分区领导1在xxx3上,最后是分区领导2在xxx1上。 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 xxx3, the second follower will be on xxx1. 关于跟随者副本,分配给它们的启动代理增加一个:在此示例中,分区0的第一个跟随者将在xxx3上,第二个跟随者将在xxx1上。 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. 分区1和2的跟随者副本也会发生同样的情况。通过这种方式,复制允许HA,并且整个群集之间的流量保持平衡。 Btw there is a tool named "kafka-reassign-partitions.sh" you can use for specifying your preferred assignment through a JSON. 顺便说一句,有一个名为“ kafka-reassign-partitions.sh”的工具,可用于通过JSON指定首选的分配。 You can find more here : https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-4.ReassignPartitionsTool 您可以在此处找到更多信息: https : //cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-4.ReassignPartitionsTool

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

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