diff options
author | antirez <antirez@gmail.com> | 2015-11-09 17:26:56 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-11-09 17:26:58 +0100 |
commit | 87a12a608512603a56851507b75bb43e55abcca2 (patch) | |
tree | fca6264f7cb9cd46618ea9d0ec9f9d7407029721 | |
parent | b719eedfc6db1aa34cc89e8f771189a344a03e23 (diff) | |
download | redis-87a12a608512603a56851507b75bb43e55abcca2.tar.gz |
Best effort flush of slave buffers before SHUTDOWN.
-rw-r--r-- | src/networking.c | 4 | ||||
-rw-r--r-- | src/server.c | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c index 0ca433787..3b9c77cf1 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1732,7 +1732,9 @@ void asyncCloseClientOnOutputBufferLimitReached(client *c) { } /* Helper function used by freeMemoryIfNeeded() in order to flush slaves - * output buffers without returning control to the event loop. */ + * output buffers without returning control to the event loop. + * This is also called by SHUTDOWN for a best-effort attempt to send + * slaves the latest writes. */ void flushSlavesOutputBuffers(void) { listIter li; listNode *ln; diff --git a/src/server.c b/src/server.c index dbfd2785a..ec0ef64ec 100644 --- a/src/server.c +++ b/src/server.c @@ -2490,6 +2490,7 @@ int prepareForShutdown(int flags) { int nosave = flags & SHUTDOWN_NOSAVE; serverLog(LL_WARNING,"User requested shutdown..."); + /* Kill the saving child if there is a background saving in progress. We want to avoid race conditions, for instance our saving child may overwrite the synchronous saving did by SHUTDOWN. */ @@ -2498,6 +2499,7 @@ int prepareForShutdown(int flags) { kill(server.rdb_child_pid,SIGUSR1); rdbRemoveTempFile(server.rdb_child_pid); } + if (server.aof_state != AOF_OFF) { /* Kill the AOF saving child as the AOF we already have may be longer * but contains the full dataset anyway. */ @@ -2516,6 +2518,8 @@ int prepareForShutdown(int flags) { serverLog(LL_NOTICE,"Calling fsync() on the AOF file."); aof_fsync(server.aof_fd); } + + /* Create a new RDB file before exiting. */ if ((server.saveparamslen > 0 && !nosave) || save) { serverLog(LL_NOTICE,"Saving the final RDB snapshot before exiting."); /* Snapshotting. Perform a SYNC SAVE and exit */ @@ -2529,10 +2533,17 @@ int prepareForShutdown(int flags) { return C_ERR; } } + + /* Remove the pid file if possible and needed. */ if (server.daemonize || server.pidfile) { serverLog(LL_NOTICE,"Removing the pid file."); unlink(server.pidfile); } + + /* Best effort flush of slave output buffers, so that we hopefully + * send them pending writes. */ + flushSlavesOutputBuffers(); + /* Close the listening sockets. Apparently this allows faster restarts. */ closeListeningSockets(1); serverLog(LL_WARNING,"%s is now ready to exit, bye bye...", |