简体   繁体   English

卡夫卡主题分区

[英]Kafka Topic Partition

Kafka Topic Partition offset position always start from 0 or random value and How to ensure the consumer record is the first record in the partition ? Kafka Topic分区偏移量位置始终从0或随机值开始,如何确保使用者记录是分区中的第一条记录? Is there any way to find out ? 有什么办法找出来吗? If any please let me know. 如果有的话请告诉我。 Thanks. 谢谢。

Yes and no. 是的,没有。

When you start a new topic, the offset start at zero. 当您开始一个新主题时,偏移量从零开始。 Depending on the Kafka version you are using, the offsets are 根据您使用的Kafka版本,偏移量为

  • logical – and incremented message by message (since 0.8.0: https://issues.apache.org/jira/browse/KAFKA-506 ) – or 逻辑 -并逐条消息递增消息(自0.8.0: https ://issues.apache.org/jira/browse/KAFKA-506开始)-或
  • physical – ie, the offset is increased by the number of bytes for each message. 物理的 -即,偏移量增加了每个消息的字节数。

Furthermore, old log entries are cleared by configurable conditions: 此外,可以通过可配置的条件清除旧的日志条目:

Thus, the first offset might not be zero if old messages got deleted. 因此,如果删除旧消息,则第一个偏移量可能不会为零 Furthermore, if you turn on log-compaction, some offsets might be missing. 此外,如果打开对数压缩,则可能会缺少一些偏移量。

In any case, you can always seek to any offset safely, as Kafka can figure out if the offset is valid or not. 无论如何,您总是可以安全地寻找任何偏移量,因为Kafka可以找出偏移量是否有效。 For an invalid offset, is automatically advances to the next valid offset. 对于无效的偏移量,会自动前进到下一个有效的偏移量。 Thus, if you seek to offset zero, you will always get the oldest message that is stored. 因此,如果您寻求偏移零,则将始终获得存储的最旧消息。

Yes , Kafka offset starts from 0 and ends with byte length of the complete record and then next record picks the offset from there onward. 是的 ,Kafka偏移量从0开始,以完整记录的字节长度结束,然后下一条记录从此处开始选择偏移量。

As Kafka is distributed so we can not assure that Consumer will get the data in ordered way. 由于Kafka是分布式的,因此我们不能保证Consumer将以有序方式获取数据。

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

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