简体   繁体   English

如果为主题创建新分区,Kafka 会发生什么情况?

[英]What happens in Kafka if you create a new partition for a topic?

I read on some guides online that if you are using key ordering the new partition will eventually break that ordering, I really can't see how.我在网上阅读了一些指南,如果您使用密钥排序,新分区最终将打破该排序,我真的看不出如何。 Is this really what happens?这真的发生了吗?

Yes, this is what is usually happening.是的,这是通常发生的事情。 To be more precise, there is no guarantee that the old ordering stays the same .更准确地说,不能保证旧的顺序保持不变

The partitioning of messages is basically happening through消息的分区基本上是通过

hash(key) % number_of_partitions

Let us assume you have a topic with two partitions.让我们假设您有一个包含两个分区的主题。 Your data (key:value) looks like this您的数据(键:值)如下所示

a:1
b:1
c:1
a:2
b:2
c:2

Now, those messages would go into two partitions:现在,这些消息将 go 分为两个分区:

partition0: a:1, b:1, a:2, b:2
partition1: c:1, c:2

If you now add one partition and you produce new messages a:3, b:3, c:3 into the topic you could end up like this:如果您现在添加一个分区并在主题中生成新消息a:3, b:3, c:3 ,您可能会像这样结束:

partition0: a:1, b:1, a:2, b:2, a:3
partition1: c:1, c:2, c:3
partition2: b:3

Now, consuming the messages from this topic, you could end up processing b:3 before processing b:2 because the one consumer reading partition0 might take longer then another consumer of the same ConsumerGroup reading partition2 .现在,使用来自该主题的消息,您可能会在处理b:2之前结束处理b:3 ,因为一个消费者读取partition0可能比同一 ConsumerGroup 的另一个消费者读取partition2花费更长的时间。

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

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