Ensure clean shutdown with multiple threads
This commit is contained in:
parent
84b37edfcf
commit
f60bb34994
@ -2656,13 +2656,15 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
|
||||
bool fActiveClient = false;
|
||||
while ((ln = listNext(&li)) && !fActiveClient) {
|
||||
client *c = (client*)listNodeValue(ln);
|
||||
if (c->flags & (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED | CLIENT_MONITOR))
|
||||
if (c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN)
|
||||
continue;
|
||||
fActiveClient = true;
|
||||
}
|
||||
if (!fActiveClient) {
|
||||
serverLog(LL_WARNING, "All active clients have disconnected while a soft shutdown is pending. Shutting down now.");
|
||||
throw ShutdownException();
|
||||
if (prepareForShutdown(SHUTDOWN_NOFLAGS) == C_OK) {
|
||||
serverLog(LL_WARNING, "All active clients have disconnected while a soft shutdown is pending. Shutting down now.");
|
||||
throw ShutdownException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5315,7 +5317,7 @@ void pingCommand(client *c) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_pserver->soft_shutdown) {
|
||||
if (g_pserver->soft_shutdown && !(c->flags & CLIENT_IGNORE_SOFT_SHUTDOWN)) {
|
||||
addReplyError(c, "-SHUTDOWN PENDING");
|
||||
return;
|
||||
}
|
||||
|
@ -508,6 +508,7 @@ extern int configOOMScoreAdjValuesDefaults[CONFIG_OOM_COUNT];
|
||||
#define CLIENT_PREVENT_AOF_PROP (1<<19) /* Don't propagate to AOF. */
|
||||
#define CLIENT_PREVENT_REPL_PROP (1<<20) /* Don't propagate to slaves. */
|
||||
#define CLIENT_PREVENT_PROP (CLIENT_PREVENT_AOF_PROP|CLIENT_PREVENT_REPL_PROP)
|
||||
#define CLIENT_IGNORE_SOFT_SHUTDOWN (CLIENT_MASTER | CLIENT_SLAVE | CLIENT_BLOCKED | CLIENT_MONITOR)
|
||||
#define CLIENT_PENDING_WRITE (1<<21) /* Client has output to send but a write
|
||||
handler is yet not installed. */
|
||||
#define CLIENT_REPLY_OFF (1<<22) /* Don't send replies to client. */
|
||||
|
@ -23,7 +23,7 @@ start_server {tags {"soft_shutdown"} } {
|
||||
}
|
||||
|
||||
start_server {tags {"soft_shutdown"} } {
|
||||
test {soft shutdown prevents allows commands to execute while waiting} {
|
||||
test {soft shutdown allows commands to execute while waiting} {
|
||||
assert_equal [r shutdown soft] "OK"
|
||||
r set test val
|
||||
assert_equal [r get test] {val}
|
||||
|
Loading…
x
Reference in New Issue
Block a user