# 错误：故障转移期间等待副本确认超时

- **ID:** `redis/redis-timeout-while-waiting-for-replica-ack`
- **领域:** redis
- **类别:** runtime_error
- **错误码:** `ERR`
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

在Redis哨兵或集群故障转移期间，主节点等待副本确认数据同步，但网络延迟或副本滞后导致超时过期。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| redis 6.2 | active | — | — |
| redis 7.0 | active | — | — |
| redis 7.2 | active | — | — |

## 解决方案

1. ```
   Check replica lag with `INFO replication` and reduce it by ensuring replicas have sufficient resources (CPU, network). If lag is high, temporarily increase `repl-timeout` in redis.conf: `repl-timeout 120`.
   ```
2. ```
   Use `CLUSTER FAILOVER FORCE` on a replica that is synced within acceptable lag to trigger a forced failover without waiting for all replicas.
   ```
3. ```
   Optimize network between master and replicas: use dedicated links or lower latency paths. Monitor with `redis-cli --latency` to identify bottlenecks.
   ```

## 无效尝试

- **Increasing the timeout in redis.conf to 300 seconds** — Higher timeout may mask underlying issues like replica lag or network problems; failover can still fail if replicas are too far behind. (65% 失败率)
- **Manually promoting a replica to master without waiting** — Forcing promotion can cause data loss if the replica is not fully synchronized; the new master may miss recent writes. (90% 失败率)
- **Disabling replication checks altogether** — Turning off replication checks compromises data consistency and can lead to split-brain scenarios. (95% 失败率)
