我们将 Storm 与 Kafka 和 ZooKeeper 结合使用。我们遇到过这样的情况:我们必须删除一些主题并用不同的名称重新创建它们。除了现在读取新主题名称之外,我们的 Kafka spouts 保持不变。但是现在,当尝试从新主题读取数据时,spouts 使用旧主题分区的偏移量。因此 my-topic-name 分区 0 的尾部位置将为 500,但偏移量将约为 10000。
有没有办法重置偏移位置,使其与主题的尾部匹配?
有多种选择(如 Storm 的KafkaSpout
不提供任何API来定义起始偏移量)。
- If you want to consumer from the tail of the log you should delete old offsets
- depending on you Kafka version
- (0.9之前)你可以操纵ZK(这有点棘手)
- (0.9+) 或者您尝试删除主题中的偏移量
__consumer_offsets
(这也很棘手,可能也会删除您想要保留的其他偏移量)
- 如果没有偏移量,您可以使用自动偏移重置策略“最新”或“最大”(取决于您的 Kafka 版本)重新启动您的 spout
- as an alternative (which I would recommend), you can write a small client application that uses
seek()
to manipulate the offset in the way you need them and commit()
the offsets. This client must use the same group ID as you KafkaSpout
and must subscribe to the same topic(s). Furthermore, you need to make sure that this client application is running a single consumer group member so it get's all partitions assigned.
- 为此,您可以查找日志末尾并提交
- 或者您提交无效的偏移量(如-1)并依赖自动偏移量重置配置“最新”或“最大”(取决于您的Kafka版本)
对于 Kafka Streams,有一个“应用程序重置工具”可以执行类似的操作来操作已提交的偏移量。如果您想了解一些详细信息,可以阅读这篇博文http://www.confluence.io/blog/data-reprocessing-with-kafka-streams-resetting-a-streams-application/ http://www.confluent.io/blog/data-reprocessing-with-kafka-streams-resetting-a-streams-application/
(免责声明:我是这篇文章的作者,它是关于 Kafka Streams 的——尽管如此,底层的偏移量操作思想是相同的)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)