# 错误：复制同步失败，副本ID不匹配，期望<replica_id>但得到<replica_id>

- **ID:** `redis/sync-replica-id-mismatch`
- **领域:** redis
- **类别:** runtime_error
- **错误码:** `ERR`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

在部分重新同步期间，副本缓存的master复制ID与当前master的复制ID不匹配，通常是由于master重启或故障转移导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 6.2.0 | active | — | — |
| 7.0.0 | active | — | — |
| 7.2.0 | active | — | — |
| 7.4.0 | active | — | — |

## 解决方案

1. ```
   在副本上运行 `SLAVEOF NO ONE` 然后 `SLAVEOF <master_ip> <master_port>` 以强制完全重新同步。
   ```
2. ```
   如果使用Redis Sentinel，触发手动故障转移：`redis-cli -p 26379 SENTINEL failover <mymaster>` 以选举新的master并强制副本使用新的复制ID同步。
   ```
3. ```
   在集群环境中，确保master健康且复制ID一致后，在副本上使用 `CLUSTER REPLICATE <node-id>`。
   ```

## 无效尝试

- **** — Restarting the replica without clearing its replication backlog or ID cache does not fix the underlying mismatch; the replica will retry with the same stale ID. (75% 失败率)
- **** — Manually setting repl-id using CONFIG SET on the master is risky and may break replication for other replicas; it does not address the root cause of ID divergence. (90% 失败率)
- **** — Increasing repl-backlog-size on the master alone does not resolve a mismatched replication ID; the replica must perform a full sync to reset the ID. (80% 失败率)
