From aa79af76fc7778c3d19c473d68cfdc877f6d9b69 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 17 Jan 2014 18:22:35 +0100 Subject: [PATCH] Cluster: allow CLUSTER REPLICATE to switch master. The code was doing checks for slaves that should be done only when the instance is currently a master. Switching a slave from a master to another one should just work. --- src/cluster.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index ee95f3759..dfc115981 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2912,10 +2912,12 @@ void clusterCommand(redisClient *c) { return; } - /* We should have no assigned slots to accept to replicate some - * other node. */ - if (server.cluster->myself->numslots != 0 || - dictSize(server.db[0].dict) != 0) + /* If the instance is currently a master, it should have no assigned + * slots nor keys to accept to replicate some other node. + * Slaves can switch to another master without issues. */ + if (server.cluster->myself->flags & REDIS_NODE_MASTER && + (server.cluster->myself->numslots != 0 || + dictSize(server.db[0].dict) != 0)) { addReplyError(c,"To set a master the node must be empty and without assigned slots."); return;