From 032c7544f48932757b62e6c08939f564c6286c0c Mon Sep 17 00:00:00 2001 From: Binbin Date: Thu, 22 Aug 2024 11:00:18 +0800 Subject: [PATCH] Avoid to re-establish replication if node is already myself primary in CLUSTER REPLICATE (#884) If n is already myself primary, there is no need to re-establish the replication connection. In the past we allow a replica node to reconnect with its primary via this CLUSTER REPLICATE command, it will use psync. But since #885, we will assume that a full sync is needed in this case, so if we don't do this, the replica will always use full sync. Signed-off-by: Binbin Co-authored-by: Ping Xie --- src/cluster_legacy.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index b1cae7ae9..0fb332cbc 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6564,6 +6564,13 @@ int clusterCommandSpecial(client *c) { return 1; } + /* If `n` is already my primary, there is no need to re-establish the + * replication connection. */ + if (myself->replicaof == n) { + addReply(c, shared.ok); + return 1; + } + /* Set the primary. * If the instance is a primary, it is an empty primary. * If the instance is a replica, it had a totally different replication history.