diff --git a/src/cluster.c b/src/cluster.c index 16bc07fd1..ec119717d 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1276,6 +1276,32 @@ void clusterUpdateState(void) { } } +/* This function is called after the node startup in order to verify that data + * loaded from disk is in agreement with the cluster configuration: + * + * 1) If we find keys about hash slots we have no responsibility for, the + * following happens: + * A) If no other node is in charge according to the current cluster + * configuration, we add these slots to our node. + * B) If according to our config other nodes are already in charge for + * this lots, we set the slots as IMPORTING from our point of view + * in order to justify we have those slots, and in order to make + * redis-trib aware of the issue, so that it can try to fix it. + * 2) If we find data in a DB different than DB0 we return REDIS_ERR to + * signal the caller it should quit the server with an error message + * or take other actions. + * + * The function always returns REDIS_OK even if it will try to correct + * the error described in "1". However if data is found in DB different + * from DB0, REDIS_ERR is returned. + * + * The function also uses the logging facility in order to warn the user + * about desynchronizations between the data we have in memory and the + * cluster configuration. */ +int verifyClusterConfigWithData(void) { + return REDIS_OK; +} + /* ----------------------------------------------------------------------------- * CLUSTER command * -------------------------------------------------------------------------- */ diff --git a/src/redis.c b/src/redis.c index e398fa5da..175825cd7 100644 --- a/src/redis.c +++ b/src/redis.c @@ -2741,6 +2741,14 @@ int main(int argc, char **argv) { linuxOvercommitMemoryWarning(); #endif loadDataFromDisk(); + if (server.cluster_enabled) { + if (verifyClusterConfigWithData() == REDIS_ERR) { + redisLog(REDIS_WARNING, + "You can't have keys in a DB different than DB 0 when in " + "Cluster mode. Exiting."); + exit(1); + } + } if (server.ipfd > 0) redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port); if (server.sofd > 0) diff --git a/src/redis.h b/src/redis.h index 4aba5b52b..625eb04e7 100644 --- a/src/redis.h +++ b/src/redis.h @@ -1227,6 +1227,7 @@ int selectDb(redisClient *c, int id); void signalModifiedKey(redisDb *db, robj *key); void signalFlushedDb(int dbid); unsigned int GetKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count); +int verifyClusterConfigWithData(void); /* API to get key arguments from commands */ #define REDIS_GETKEYS_ALL 0