From 89af463124f303b1d681aa4b29623385a1442f94 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 22 Jul 2014 15:29:57 +0200 Subject: [PATCH] CLUSTER RESET: Flush dataset if node is a slave. For non-empty masters, CLUSTER RESET is denied, and the user requires to start to reset a node by explicitly clearing it with FLUSHALL. However CLUSTER RESET when executed with slaves don't have this restrictions since data is just a replica of the master, and with read-only slaves it is also not possible to remove the data set. However the node was turned from slave to master after a reset, without touching the old slave data. This is 99.99% of times not appropriate and forces full resets to follow this path to work with both slave and master nodes: FLUSHALL CLUSTER RESET HARD FLUSHALL Since we need the first flushall for masters, and the second for slaves. This commit changes the behavior so that CLUSTER RESET removes the data set of a slave node during a reset, in the moment it gets turned into a master, so the new pattern is simply: FLUSHALL (that may fail for slaves) CLUSTER RESET --- src/cluster.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cluster.c b/src/cluster.c index dc4540c2..a2d79164 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -481,7 +481,8 @@ void clusterInit(void) { * 3) If the node is a slave, it turns into a master. * 5) Only for hard reset: a new Node ID is generated. * 6) Only for hard reset: currentEpoch and configEpoch are set to 0. - * 7) The new configuration is saved and the cluster state updated. */ + * 7) The new configuration is saved and the cluster state updated. + * 8) If the node was a slave, the whole data set is flushed away. */ void clusterReset(int hard) { dictIterator *di; dictEntry *de; @@ -491,6 +492,7 @@ void clusterReset(int hard) { if (nodeIsSlave(myself)) { clusterSetNodeAsMaster(myself); replicationUnsetMaster(); + emptyDb(NULL); } /* Close slots, reset manual failover state. */