From 3130670b978e0d4baa805016386e5ca56af08123 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 27 Jun 2013 12:14:23 +0200 Subject: [PATCH] Allow SHUTDOWN in loading state. --- src/db.c | 6 ++++++ src/redis.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index 64be530e..02f8dd3a 100644 --- a/src/db.c +++ b/src/db.c @@ -362,6 +362,12 @@ void shutdownCommand(redisClient *c) { return; } } + /* SHUTDOWN can be called even while the server is in "loading" state. + * When this happens we need to make sure no attempt is performed to save + * the dataset on shutdown (otherwise it could overwrite the current DB + * with half-read data). */ + if (server.loading) + flags = (flags & ~REDIS_SHUTDOWN_SAVE) | REDIS_SHUTDOWN_NOSAVE; if (prepareForShutdown(flags) == REDIS_OK) exit(0); addReplyError(c,"Errors trying to SHUTDOWN. Check logs."); } diff --git a/src/redis.c b/src/redis.c index cb1943a0..c2397834 100644 --- a/src/redis.c +++ b/src/redis.c @@ -215,7 +215,7 @@ struct redisCommand redisCommandTable[] = { {"save",saveCommand,1,"ars",0,NULL,0,0,0,0,0}, {"bgsave",bgsaveCommand,1,"ar",0,NULL,0,0,0,0,0}, {"bgrewriteaof",bgrewriteaofCommand,1,"ar",0,NULL,0,0,0,0,0}, - {"shutdown",shutdownCommand,-1,"ar",0,NULL,0,0,0,0,0}, + {"shutdown",shutdownCommand,-1,"arl",0,NULL,0,0,0,0,0}, {"lastsave",lastsaveCommand,1,"rR",0,NULL,0,0,0,0,0}, {"type",typeCommand,2,"r",0,NULL,1,1,1,0,0}, {"multi",multiCommand,1,"rs",0,NULL,0,0,0,0,0}, -- GitLab