kafka
protocol_error
ai_generated
true
org.apache.kafka.common.errors.LeaderEpochStaleException: 请求中的领导纪元比当前领导纪元旧
org.apache.kafka.common.errors.LeaderEpochStaleException: The leader epoch in the request is older than the current leader epoch
ID: kafka/leader-epoch-stale
78%修复率
83%置信度
1证据数
2023-04-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Kafka 2.8.0 | active | — | — | — |
| Kafka 3.0.0 | active | — | — | — |
| Kafka 3.4.0 | active | — | — | — |
| Kafka 3.6.0 | active | — | — | — |
根因分析
跟随者或客户端发送了带有过时领导纪元的请求,表明它尚未了解最近的领导选举,导致代理拒绝该请求。
English
A follower or client sent a request with a stale leader epoch, indicating it has not yet learned about a recent leader election, causing the broker to reject the request.
官方文档
https://kafka.apache.org/documentation/#replication_config解决方案
-
Ensure followers can quickly learn about leader changes by reducing the metadata.max.age.ms on the broker: metadata.max.age.ms=5000 # 5 seconds Also check that network connectivity between followers and the controller is stable; monitor controller election logs.
-
If the issue is persistent, manually trigger a preferred leader election to stabilize the leader epoch: kafka-leader-election --bootstrap-server localhost:9092 --election-type preferred --partition 0 --topic my_topic This forces all replicas to acknowledge the current leader.
无效尝试
常见但无效的做法:
-
Restart the follower broker that sent the stale request
75% 失败
Restarting may reset the follower's state, but the underlying replication lag or network issue causing the stale epoch will persist.
-
Increase the replica.fetch.wait.max.ms on the follower
85% 失败
This setting controls how long a follower waits for fetch responses, but does not update the leader epoch; the follower needs to actively learn the new epoch via metadata requests.