kafka消费报Out of order offsets

天阳 发表于: 2021-11-24   最后更新时间: 2021-11-24 10:17:33   1,138 游览

停掉消费者和生产者清空Kafka数据和zookeeper数据,双副本模式下18分区的数据多次会出现数据情况1的错误,查看状态数据如模式2,但是在三副本模式下重复上述操作则没有这种情况,而且看集群副本状态也正常。

双副本模式下看到Kafka的server.log的日志,有如数据情况3的报错

情况1

PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG
18         4294925441      4266388068      -28537373  
18         500             4266387988      4266387488

情况2

PartitionCount: 30      ReplicationFactor: 2    Configs:
Partition: 0    Leader: 0       Replicas: 0,1   Isr: 0
Partition: 1    Leader: 1       Replicas: 1,0   Isr: 1
Partition: 2    Leader: 0       Replicas: 0,1   Isr: 0
Partition: 3    Leader: 0       Replicas: 0,2   Isr: 0
Partition: 4    Leader: 1       Replicas: 1,0   Isr: 1
Partition: 5    Leader: 2       Replicas: 2,1   Isr: 2,1
Partition: 6    Leader: 0       Replicas: 0,1   Isr: 0
Partition: 7    Leader: 1       Replicas: 1,2   Isr: 1
Partition: 8    Leader: 2       Replicas: 2,0   Isr: 2,0
Partition: 9    Leader: 0       Replicas: 0,2   Isr: 0
Partition: 10   Leader: 1       Replicas: 1,0   Isr: 1
Partition: 11   Leader: 2       Replicas: 2,1   Isr: 2,1
Partition: 12   Leader: 0       Replicas: 0,1   Isr: 0
Partition: 13   Leader: 1       Replicas: 1,2   Isr: 1
Partition: 14   Leader: 2       Replicas: 2,0   Isr: 2,0
Partition: 15   Leader: 0       Replicas: 0,2   Isr: 0
Partition: 16   Leader: 1       Replicas: 1,0   Isr: 1
Partition: 17   Leader: 2       Replicas: 2,1   Isr: 2,1
Partition: 18   Leader: 0       Replicas: 0,1   Isr: 0
Partition: 19   Leader: 1       Replicas: 1,2   Isr: 1
Partition: 20   Leader: 2       Replicas: 2,0   Isr: 2,0
Partition: 21   Leader: 0       Replicas: 0,2   Isr: 0
Partition: 22   Leader: 1       Replicas: 1,0   Isr: 1
Partition: 23   Leader: 2       Replicas: 2,1   Isr: 2,1
Partition: 24   Leader: 0       Replicas: 0,1   Isr: 0
Partition: 25   Leader: 1       Replicas: 1,2   Isr: 1
Partition: 26   Leader: 2       Replicas: 2,0   Isr: 2,0
Partition: 27   Leader: 0       Replicas: 0,2   Isr: 0
Partition: 28   Leader: 1       Replicas: 1,0   Isr: 1
Partition: 29   Leader: 2       Replicas: 2,1   Isr: 2,1

情况3

[2021-11-23 18:17:53,925] ERROR [ReplicaFetcher replicaId=1, leaderId=3, fetcherId=1] Unexpected error occurred while processing data for partition __consumer_offsets-46 at offset 5 (kafka.server.ReplicaFetcherThread)
kafka.common.OffsetsOutOfOrderException: Out of order offsets found in append to __consumer_offsets-46: List(4272827160, 4271343398, 4271343399, 4271343400)
        at kafka.log.Log.$anonfun$append$2(Log.scala:1161)
        at kafka.log.Log.append(Log.scala:2404)
        at kafka.log.Log.appendAsFollower(Log.scala:1071)
        at kafka.cluster.Partition.doAppendRecordsToFollowerOrFutureReplica(Partition.scala:1034)
        at kafka.cluster.Partition.appendRecordsToFollowerOrFutureReplica(Partition.scala:1041)
        at kafka.server.ReplicaFetcherThread.processPartitionData(ReplicaFetcherThread.scala:172)
        at kafka.server.AbstractFetcherThread.$anonfun$processFetchRequest$7(AbstractFetcherThread.scala:333)
        at kafka.server.AbstractFetcherThread.$anonfun$processFetchRequest$6(AbstractFetcherThread.scala:321)
        at kafka.server.AbstractFetcherThread.$anonfun$processFetchRequest$6$adapted(AbstractFetcherThread.scala:320)
        at kafka.utils.Implicits$MapExtensionMethods$.$anonfun$forKeyValue$1(Implicits.scala:62)
        at scala.collection.compat.MapExtensionMethods$.$anonfun$foreachEntry$1(PackageShared.scala:431)
        at scala.collection.Iterator.foreach(Iterator.scala:943)
        at scala.collection.Iterator.foreach$(Iterator.scala:943)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
        at scala.collection.IterableLike.foreach(IterableLike.scala:74)
        at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
        at kafka.server.AbstractFetcherThread.$anonfun$processFetchRequest$5(AbstractFetcherThread.scala:320)
        at kafka.server.AbstractFetcherThread.processFetchRequest(AbstractFetcherThread.scala:320)
        at kafka.server.AbstractFetcherThread.$anonfun$maybeFetch$3(AbstractFetcherThread.scala:136)
        at kafka.server.AbstractFetcherThread.maybeFetch(AbstractFetcherThread.scala:135)
        at kafka.server.AbstractFetcherThread.doWork(AbstractFetcherThread.scala:118)
        at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:96)
发表于 2021-11-24
添加评论

负数 = 过期的消息。

我不太清楚你怎么操作的,但是看你上面offset副本很多是单的,肯定会出顺序的问题的:

"Leader":该节点负责该分区的所有的读和写,每个节点的leader都是随机选择的。
"Replicas":备份的节点列表,无论该节点是否是leader或者目前是否还活着,只是显示。
"Isr":“同步备份”的节点列表,也就是活着的节点并且正在同步leader的数据。

参考来自:kafka集群安装搭建

大佬,为什么会出现消费过期的消息,我已经将生产者与消费者都停掉了,并且清空了kafka与zookeeper的数据并重启,并且设置的过期时间为7天

半兽人 -> 天阳 2年前

你看,你不告诉我怎么清理的,我怎么知道你的问题?

天阳 -> 半兽人 2年前

大佬,kafka和zookeeper的数据清理是直接物理删除重置的,kafka的配置在下面,跟问题出现情况唯一不一致的配置是默认副本数

半兽人 -> 天阳 2年前

zk的日志怎么删的?删之前,确保都停干净了吗。

天阳 -> 半兽人 2年前

大佬,zookeeper的数据目录时直接删除的,启动后我进zookeeper看了的里面只有一个zookeeper的目录其他都已经没有了,kafka的日志里面有这样一条信息

[2021-11-24 14:37:25,869] INFO [ProducerStateManager partition=__consumer_offsets-23] Writing producer snapshot at offset 4260796999 (kafka.log.ProducerStateManager)

半兽人 -> 天阳 2年前

这还有脏数据啊,或者某些节点还连着这个zk的。
你把zk端口改掉,或者netstat -unltpa|grep 2181

天阳 -> 半兽人 2年前

大佬这个问题时因为有脏数据导致的吗,但是同样的情况我在使用三副本模式下发现就没有出现这个情况就很奇怪,甚至我在启用三副本时都没有关闭生产者的程序只是将消费端的程序暂停了,重启kafka后再次将消费者进程启动的

半兽人 -> 天阳 2年前

你启动好集群,查看一下不就知道了么

天阳 -> 半兽人 2年前

大佬你是说kafka集群吗,就是将生产者与消费端都关闭启动kafka集群查看里面有没有数据吗

天阳 -> 半兽人 2年前

大佬如果生产运行期间出现这种情况有办法修复吗

半兽人 -> 天阳 2年前

对的,一个干净的集群不会莫名其妙产生数据的

天阳 -> 半兽人 2年前

大佬其实还有一个问题点在于如果集群数据不干净,为什么相同的操作在三副本模式下数据就暂时没出现异常的情况,大约运行了块两周了吧,但是我在清除换回双副本,问他立马出现了

无名 -> 天阳 1年前

你好,请问这个问题修复了么,另外能稳定复现不

半兽人 -> 无名 1年前

很久没有消费,数据过期了,就会出现负的offset。

我们kafka的版本时2.7.1

你的答案

查看kafka相关的其他问题或提一个您自己的问题