From 4ee011adb5f0d56085ecd3e5d643ab192ef77ce6 Mon Sep 17 00:00:00 2001 From: Tomasz Poradowski Date: Wed, 17 Jun 2020 22:22:49 +0200 Subject: [PATCH] ensure SHUTDOWN_NOSAVE in Sentinel mode - enforcing of SHUTDOWN_NOSAVE flag in one place to make it consitent when running in Sentinel mode --- src/db.c | 8 -------- src/server.c | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/db.c b/src/db.c index dc4a0b63e..19b2c48e4 100644 --- a/src/db.c +++ b/src/db.c @@ -963,14 +963,6 @@ void shutdownCommand(client *c) { return; } } - /* When SHUTDOWN is called while the server is loading a dataset in - * memory 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). - * - * Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */ - if (server.loading || server.sentinel_mode) - flags = (flags & ~SHUTDOWN_SAVE) | SHUTDOWN_NOSAVE; if (prepareForShutdown(flags) == C_OK) exit(0); addReplyError(c,"Errors trying to SHUTDOWN. Check logs."); } diff --git a/src/server.c b/src/server.c index 53dccf875..7c92c9244 100644 --- a/src/server.c +++ b/src/server.c @@ -3680,6 +3680,15 @@ void closeListeningSockets(int unlink_unix_socket) { } int prepareForShutdown(int flags) { + /* When SHUTDOWN is called while the server is loading a dataset in + * memory 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). + * + * Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */ + if (server.loading || server.sentinel_mode) + flags = (flags & ~SHUTDOWN_SAVE) | SHUTDOWN_NOSAVE; + int save = flags & SHUTDOWN_SAVE; int nosave = flags & SHUTDOWN_NOSAVE;