kafka stream app什么时候清理状态存储?

When does kafka stream app clean it state store?

我有一个 kafka 流应用程序,目前正在加入两个 KStreams 5 分钟 window 并将加入结果写入另一个 topic

由于我在一段时间 window 中加入了两个 topics,因此我的应用程序将具有与其关联的状态。我的印象是我的应用程序中的状态存储每隔 5 分钟 window 就会被修剪一次(因为我的应用程序只关心加入状态的 5 分钟 window 事件)。

我原以为磁盘 space 的利用率是恒定的。但是,似乎并非如此。已经 12 小时了,我没有看到国家商店正在清理。它一直在增长。

所以我现在对此有很多顾虑,

  1. Kafka Streams 应用何时清理其状态?
  2. 如果我在 kafka streams 应用程序集群中的一个应用程序失败,并且我启动了另一台主机并使其加入集群,在重新平衡之后,磁盘中是否有孤立的状态存储用于重新平衡的分区?
  3. 我的理解是只有在定义的window内发生的事件才被加入,那么,为什么kafka需要保留比定义的window期间更早的数据它的国营商店?

如果您需要我提供有关我的流应用程序的任何其他信息,请告诉我。我目前是 运行 kafka-streams 版本 2.2.1,我的经纪人也在同一版本。

When does Kafka Streams app clean up its state?

状态的大小取决于保留期,默认为 1 天。

Atm,无法更改 KStream-KStream 连接的保留期 -- 添加此功能已经在开发中:https://issues.apache.org/jira/browse/KAFKA-8558

If one of my app in the kafka streams app cluster fails, and I boot another host and make it join the cluster, after rebalancing, is there orphaned state store sitting in the disk for the partitions that got rebalanced?

是的。但是,如果在可配置的 (state.cleanup.delay.ms) 时间段后未重新使用该状态,则该状态将被清除(如果您在恢复的主机上重新启动 Kafka Streams)。

My understanding is that the events are joined only if they happen in the defined window, so, why does kafka need to hold on to data that is older than the defined window period in its state store?

拥有比您的 window 大小更长的保留期允许 Kafka Streams 处理乱序数据。请注意,Kafka Streams 使用事件时间语义,而不是处理时间语义。