首页 > 解决方案 > 为什么副本获取字节数大于允许的最大消息字节数?

问题描述

最近,我们在 Kafka 集群中遇到了一个问题,我们max.message.bytes将主题的值(其复制因子为3)覆盖为大于 的值replica.fetch.max.bytes。我们没有立即看到问题,但是当稍后生成消息 ( replica.fetch.max.bytes< message size < max.message.bytes) 时,我们开始在日志中看到以下错误。

Replication is failing due to a message that is greater than replica.fetch.max.bytes for partition [<topic-name>,1]. This generally occurs when the max.message.bytes has been overridden to exceed this value and a suitably large message has also been sent. To fix this problem increase replica.fetch.max.bytes in your broker config to be equal or larger than your settings for max.message.bytes, both at a broker and topic level

由于我们不想重新启动 Kafka 代理并立即对集群执行滚动升级,因此我们暂时将复制因子降低到1(我知道不是高可用性)。

那么,是否有任何有用的用例可以使此类设置有用?如果是,是什么?此外,有没有更好的解决方案可以尝试缓解这个问题,而不是停止复制?

标签: apache-kafka

解决方案


我的猜测是,由于max.message.bytes是每个主题(因此存储在 ZooKeeper 中并在任何时间点更新),并且replica.fetch.max.bytes是每个代理,因此无法检查或保证主题max.message.bytes是 <= 副本的replica.fetch.max.bytes

我还发现了一张关于这个问题的旧票: https ://issues.apache.org/jira/browse/KAFKA-1844

Kaka Broker 在启动时检查配置的replica.fetch.max.bytes >= message.max.bytes。但是用户可以覆盖每个主题的 message.max.bytes,并且每个主题的 message.max.bytes 不会发生这样的验证。如果用户配置 message.max.bytes > replica.fetch.max.bytes ,关注者将无法获取数据。

同样从关于 的文档中replica.fetch.max.bytes,似乎在某些情况下它仍然可以工作:

这不是一个绝对最大值,如果 fetch 的第一个非空分区中的第一个记录批大于此值,仍将返回记录批以确保可以进行进度。代理接受的最大记录批量大小通过 message.max.bytes(代理配置)或 max.message.bytes(主题配置)定义。

所以总而言之,这似乎没有意义,并且是一个已知问题。


推荐阅读