Skip to content

Commit

Permalink
Avoid to re-establish replication if node is already myself primary i…
Browse files Browse the repository at this point in the history
…n CLUSTER REPLICATE (valkey-io#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 valkey-io#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 <[email protected]>
Co-authored-by: Ping Xie <[email protected]>
  • Loading branch information
enjoy-binbin and PingXie authored Aug 22, 2024
1 parent 39f8bcb commit 08aaeea
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 08aaeea

Please sign in to comment.