错误:复制同步失败,副本ID不匹配,期望<replica_id>但得到<replica_id>
Error: Replication sync failed, replica id mismatch, expected <replica_id> but got <replica_id>
ID: redis/sync-replica-id-mismatch
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 6.2.0 | active | — | — | — |
| 7.0.0 | active | — | — | — |
| 7.2.0 | active | — | — | — |
| 7.4.0 | active | — | — | — |
根因分析
在部分重新同步期间,副本缓存的master复制ID与当前master的复制ID不匹配,通常是由于master重启或故障转移导致。
English
During partial resynchronization, the replica's cached master replication ID does not match the current master's replication ID, often due to master restart or failover.
官方文档
https://redis.io/docs/management/replication/解决方案
-
在副本上运行 `SLAVEOF NO ONE` 然后 `SLAVEOF <master_ip> <master_port>` 以强制完全重新同步。
-
如果使用Redis Sentinel,触发手动故障转移:`redis-cli -p 26379 SENTINEL failover <mymaster>` 以选举新的master并强制副本使用新的复制ID同步。
-
在集群环境中,确保master健康且复制ID一致后,在副本上使用 `CLUSTER REPLICATE <node-id>`。
无效尝试
常见但无效的做法:
-
75% 失败
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.
-
90% 失败
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.
-
80% 失败
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.