简体   繁体   English

Kafka 流中的更改日志主题 - 设置或更改分区

[英]changelog topic in Kafka streams - setting or altering partitions

We have a stream processor app that consumes the data from a topic with n partitions ( n > 1 ).我们有一个 stream 处理器应用程序,它使用来自具有 n 个分区 (n > 1) 的主题的数据。

From the fresh start (without the changelog topic), the dev environment always creates a changelog topic with n partitions.从新开始(没有更新日志主题),开发环境总是创建一个包含 n 个分区的更新日志主题。

In the same scenario, on production the number of partitions is always equal to 1 then we have manually changed to n to match the # of partitions of the topic.在相同的场景中,在生产环境中,分区数始终等于 1,然后我们手动更改为 n 以匹配主题的分区数。

I check all the documents try to set the number of partitions for the changelog but I could not find any way to do it.我检查了所有文档,尝试为更改日志设置分区数,但找不到任何方法。 My last option is to check if the changelog topic does not exist then I create it with n partitions.我的最后一个选择是检查更改日志主题是否不存在,然后我使用 n 个分区创建它。

Since the framework creates that topic automatically, are there any way to set the number of partitions for the changelog without creating that topic manually or in code?由于框架会自动创建该主题,是否有任何方法可以设置更改日志的分区数,而无需手动或在代码中创建该主题?

PS: We are using Kafka client version 2.3.1. PS:我们使用的是 Kafka 客户端版本 2.3.1。

Thanks,谢谢,

Austin奥斯汀

I've just looked at the source code to find out the details of this feature and at the time of this writing, it turns out that setting the partitions of the change-logs topic is not allowed .我刚刚查看了源代码以了解此功能的详细信息,在撰写本文时,事实证明设置change-logs主题的分区是不允许的。

Explanation解释

The change-logs topic is classified as an internal topic and there is evidence for this in the following 2 classes ( InternalTopicConfig and InternalTopicManager ): change-logs主题被归类为内部主题,并且在以下 2 个类( InternalTopicConfigInternalTopicManager )中有证据证明这一点:

  1. The source code of the class InternalTopicConfig contains the following method that also says the number of partitions on such internal topics are enforced: class InternalTopicConfig的源代码包含以下方法,该方法还表示强制执行此类内部主题的分区数:

     public void setNumberOfPartitions(final int numberOfPartitions) { if (hasEnforcedNumberOfPartitions()) { throw new UnsupportedOperationException("number of partitions are enforced on topic " + "" + name() + " and can't be altered."); ...
  2. The embedded documentation in the source code of the class InternalTopicManager clearly states this for the makeReady() method. class InternalTopicManager源代码中的嵌入式文档清楚地说明了makeReady()方法。

     /** * Prepares a set of given internal topics. * * If a topic does not exist creates a new topic. * If a topic with the correct number of partitions exists ignores it. * If a topic exists already but has different number of partitions we fail and throw exception requesting user to reset the app before restarting again. * @return the set of topics which had to be newly created */ public Set<String> makeReady(final Map<String, InternalTopicConfig> topics)...

As you can see in the comments, if such a topic exists with correct partition count it will be ignored and if the partition count is incorrect then you'll see errors and the recommendation is to use the application reset tool .正如您在评论中看到的那样,如果存在这样一个分区计数正确的主题,它将被忽略,如果分区计数不正确,那么您将看到错误,建议使用应用程序重置工具

Hope this helps!希望这可以帮助!

Currently we are connecting to SSL enabled MSK topics and as such we dont have write access to create internal topics via the app.目前我们正在连接到 SSL 启用的 MSK 主题,因此我们没有通过应用程序创建内部主题的写入权限。 Hence as a work around we had asked the MSK admins to create changelog topics with the desired name manually so that the app could read it.因此,作为一种解决方法,我们要求 MSK 管理员手动创建具有所需名称的变更日志主题,以便应用程序可以读取它。

Moreover, currently all our User topics are of 3 partitions and the changelog topics created have also 3 partition with the below updated settings.此外,目前我们所有的用户主题都是 3 个分区,创建的变更日志主题也有 3 个分区,并具有以下更新的设置。 These settings would come in handy just in case you are trying to create a changelog topic manually (compaction is enabled to save space):这些设置会派上用场,以防您尝试手动创建更改日志主题(启用压缩以节省空间):

Configs for Changelog变更日志的配置

Moreover changelog topic names would look like this: (your-application-id)-(userDefined property under materializedAs)-changelog此外,变更日志主题名称如下所示: (your-application-id)-(materializedAs 下的 userDefined 属性)-changelog

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

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