# org.apache.kafka.common.errors.ReplicaNotAvailableException: 分区 my_topic-0 的副本在代理 2 上不可用

- **ID:** `kafka/replica-not-available-on-fetch`
- **领域:** kafka
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

跟随者副本未完全跟上领导者，无法提供获取请求，通常是由于复制延迟或副本离线。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| kafka_2.13-3.4.0 | active | — | — |
| kafka_2.13-3.5.1 | active | — | — |
| kafka_2.13-3.6.0 | active | — | — |

## 解决方案

1. ```
   Check the replication lag using `kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group my-group --describe` and verify the replica is in sync. If lag is high, increase `replica.fetch.max.bytes` and `num.replica.fetchers` on the broker.
   ```
2. ```
   Restart the broker hosting the unavailable replica (broker 2) to force re-sync with the leader. Example: `systemctl restart kafka` on broker 2.
   ```
3. ```
   If the replica is permanently stuck, reassign the partition to a different broker using `kafka-reassign-partitions.sh` with a custom reassignment JSON.
   ```

## 无效尝试

- **** — This reduces durability but does not make the replica available; the follower still lags and cannot serve fetches. (85% 失败率)
- **** — This controls fetch size, not lag; the replica is not available due to being out of sync, not due to fetch limits. (80% 失败率)
- **** — This removes the replica entirely, causing data loss and requiring re-replication, which may make it even less available. (95% 失败率)
