暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

记一次Maxwell行数据过大同步异常

天天李拜天DBA 2023-09-19
847

环境:

maxwell:/maxwell-1.40.2

kafka: 2.4.1 (Commit:c57222ae8cd7866b)

MySQL: 8.0.27

数据流:MySQL> Maxwell > Kafka

参数配置:默认配置未做特殊优化

现象

当源端某一行数据过大时,Maxwell会报错倒是数据写入Kafka失败。报错信息

2023-09-11 14:08:19 ERROR MaxwellKafkaProducer - The message is 2292949 bytes when serialized which is larger than 1048576, which is the value of the max.request.size configuration.


分析

报错还是很明显的,源端MySQL的数据单行数据过大,超出了max.request.size
的设置

在Maxwell启动的时候查看日志可以看到初始化的参数

2023-09-11 14:07:37 INFO  Maxwell - Starting Maxwell. maxMemory: 994050048 bufferMemoryUsage: 0.4
2023-09-11 14:07:37 INFO  ProducerConfig - ProducerConfig values:
        acks = 1
        batch.size = 16384
        ....
        key.serializer = class org.apache.kafka.common.serialization.StringSerializer
        linger.ms = 0
        max.block.ms = 60000
        max.in.flight.requests.per.connection = 5
        max.request.size = 1048576
...

所以需要修改一些参数,在网上查了查大部分说的办法修改的是:

Maxwell的配置文件  config.properties添加max.request.size

Kafka配置文件  server.properties 和producer.properties 添加:max.request.size

但是发现在重启kafka和Maxwell后依然无效 重启Maxwell时的日志中初始化 max.request.size
参数值依然为 1048576

结论

先说下我这次的解决方案:

  1. Maxwell 的参数名没有设置对 。应为 kafka.max.request.size
  2. Kafka 应对单独的Topic 进行参数设置(不设置的话 Maxwell会报其他错误):--add-config 'max.message.bytes=20000000

(当然,应该也有其他方案解决,比如将消息压缩)

操作

为了显示出 不修改kafka端topic参数的报警,这里先只修改Maxwell的参数

  • 添加Maxwell 参数 kafka.max.request.size
[root@VM-24-17-centos maxwell]# vim config.properties
kafka.max.request.size = 9292949

  • 重启Maxwell
 ./bin/maxwell --config config.properties --daemon

查看启动日志.发现max.request.size
已完成修改

023-09-18 13:01:01 INFO  ProducerConfig - ProducerConfig values:
        acks = 1
        batch.size = 16384
      ....
        max.request.size = 9292949
        ....

  • 再次插入超限的数据会出现其他报错
  2023-09-18 13:04:17 ERROR MaxwellKafkaProducer - The request included a message larger than the max message size the server will accept.

  • 修改Kafka端参数
修改topic参数
[root@VM-24-17-centos kafka]# ./bin/kafka-configs.sh --zookeeper 10.0.24.17:2181 --alter --entity-type topics --entity-name maxwell --add-config 'max.message.bytes=20000000'
查看修改结果
[root@VM-24-17-centos kafka]#  ./bin/kafka-configs.sh --zookeeper 10.0.24.17:2181  --entity-type topics --entity-name maxwell --describe
Configs for topic 'maxwell' are max.message.bytes=20000000```




  • 再次操作数据库插入数据

发现Maxwell 端没有报错,且kafka 的consumer也消费正常(有报错时是没有数据写到kafka的)


文章转载自天天李拜天DBA,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论