简体   繁体   English

Kafka 主题、分区和主题日志压缩

[英]Kafka Topic, Partitioning and Topic Log Compaction

I am new to Kafka.我是卡夫卡的新手。 I have a question regarding how to partition the topic.我有一个关于如何划分主题的问题。

I have Kafka topic and plan to have 2 partitions into it.我有 Kafka 主题并计划在其中包含 2 个分区。 I have two operations - Project Create / Update and Project Validate.我有两个操作 - 项目创建/更新和项目验证。

Project Create / Update operation is long one and takes time to complete.项目创建/更新操作很长,需要时间才能完成。 Project Validate is faster operation and is expected to return result quickly. Project Validate 运行速度更快,预计会快速返回结果。

I am planning to have 2 different keys - One for Create / Update operation and one for Validate operation, so that each operation goes to individual partition and eventually listened by one consumer in consumer group for performance.我计划有 2 个不同的键 - 一个用于创建/更新操作,一个用于验证操作,这样每个操作都会进入单独的分区,并最终由消费者组中的一个消费者监听以获取性能。

I came to know about kafka compaction, where the records are compacted in case if they have same key.我开始了解 kafka 压缩,如果记录具有相同的密钥,则在其中压缩记录。 This leads to a problem with my initial approach as the key will be same for all the Project Create / Update event, even if they are for different projects.这导致我的初始方法出现问题,因为所有项目创建/更新事件的密钥都是相同的,即使它们用于不同的项目。

In case if I change the key to contain the project identifier also then it is not guaranteed to have all the project create event in single partition which indirectly means that validation operation may have to wait for long running create operation to finish.如果我更改密钥以包含项目标识符,则不能保证所有项目创建事件都在单个分区中,这间接意味着验证操作可能必须等待长时间运行的创建操作完成。

How can I design my partitioning key?如何设计我的分区键?

First of all you do not need to set your topic to work as compacted topic it is up to you to decide if that option is even relevant for your use case, it is configurable with the cleanup.policy topic parameter, secondly two use cases like you suggested on the same topic is not optimal and if you know it up front you might have easier time just setting two topics, having said that you can implement PartitionAssignor that will decide where to send each key, notice that the default assignor won't promise you that the two keys will go to different partitions, it just promises that all records with same key will go to same partition, there is no promise that each key will go to different partitions.首先,您不需要将主题设置为压缩主题,由您决定该选项是否与您的用例相关,它可以使用 cleanup.policy 主题参数进行配置,其次是两个用例,例如您在同一主题上提出的建议不是最佳的,如果您事先知道,您可能会更轻松地设置两个主题,但已经说过您可以实现 PartitionAssignor 来决定将每个密钥发送到哪里,请注意默认分配器不会promise you that the two keys will go to different partitions, it just promises that all records with same key will go to same partition, there is no promise that each key will go to different partitions.

Hope that makes sense, please comment if further explanation is needed.希望这是有道理的,如果需要进一步解释,请发表评论。

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

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