# org.apache.kafka.common.errors.LeaderEpochStaleException: 请求中的领导纪元比当前领导纪元旧

- **ID:** `kafka/leader-epoch-stale`
- **领域:** kafka
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

跟随者或客户端发送了带有过时领导纪元的请求，表明它尚未了解最近的领导选举，导致代理拒绝该请求。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 2.8.0 | active | — | — |
| Kafka 3.0.0 | active | — | — |
| Kafka 3.4.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |

## 解决方案

1. ```
   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.
   ```
2. ```
   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** — Restarting may reset the follower's state, but the underlying replication lag or network issue causing the stale epoch will persist. (75% 失败率)
- **Increase the replica.fetch.wait.max.ms on the follower** — 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. (85% 失败率)
