# org.apache.kafka.common.errors.ReplicaNotAvailableException：分区的副本不可用

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

## 根因

请求的分区的跟随者副本离线、未完全同步，或拉取请求指向了不可用的副本。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.8.2 | active | — | — |
| 3.2.3 | active | — | — |
| 3.5.1 | active | — | — |

## 解决方案

1. ```
   Check the broker logs for the specific partition and bring the offline replica online:
# Identify the partition leader
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic my_topic
# Restart the broker hosting the unavailable replica or reassign replicas:
kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file reassign.json --execute
   ```
2. ```
   Set the consumer to read from the leader only by setting client-side rack awareness or using a fetch from the leader (default behavior if replica selector is not configured).
   ```

## 无效尝试

- **** — Restarting the consumer only retries the fetch, but the replica remains unavailable. (95% 失败率)
- **** — Increasing fetch.max.wait.ms only delays the timeout, not the root cause. (85% 失败率)
