博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

kafka一个broker挂掉无法写入

Posted on 2019-09-10 15:01  来碗酸梅汤  阅读(3827)  评论(0编辑  收藏  举报

Kafka日志:

broker 133 received LeaderAndIsrRequest with correlation id 1 from controller 132 epoch 35 fro partition [__consumer_offsets,13] but cannot become follower since the new leader -1 is unavailable

 

this server is not the leader for that topic-partition

 

对于broker 133 received LeaderAndIsrRequest with correlation id 1 from controller 132 epoch 35 fro partition [__consumer_offsets,13] but cannot become follower since the new leader -1 is unavailable

错误是因为

 

因其中一个broker挂掉无法获取leaderbrokerid

3broker中的其中一个挂掉,是可以将数据写入另外两个broker的。至于没有写入另外两个broker报错org.apache.kafka.common.errors.NotLeaderForPartition可能是因为可能我们的producer端的代码里没加 reties 参数,默认就发送一次,遇到leader选举时,找不到leader就会发送失败,造成程序停止

解决办法

producer端加上参数 reties=3, 重试发送三次(默认100ms重试一次 由 retry.backoff.ms控制);
如果还需要保证消息发送的有序性,记得加上参数 max.in.flight.requests.per.connection = 1 限制客户端在单个连接上能够发送的未响应请求的个数,设置此值是1表示kafka broker在响应请求之前client不能再向同一个broker发送请求。(注意:设置此参数是为了满足必须顺序消费的场景,比如binlog数据)