SHUTDOWN now does the right thing when append only is on, that is, fsync instead to save the snapshot.

This commit is contained in:
antirez
2009-12-18 07:31:44 -05:00
parent fdcaae84d3
commit ac945e2dcf
3 changed files with 25 additions and 15 deletions

32
redis.c
View File

@ -3320,20 +3320,26 @@ static void shutdownCommand(redisClient *c) {
kill(server.bgsavechildpid,SIGKILL);
rdbRemoveTempFile(server.bgsavechildpid);
}
/* SYNC SAVE */
if (rdbSave(server.dbfilename) == REDIS_OK) {
if (server.daemonize)
unlink(server.pidfile);
redisLog(REDIS_WARNING,"%zu bytes used at exit",zmalloc_used_memory());
redisLog(REDIS_WARNING,"Server exit now, bye bye...");
exit(1);
if (server.appendonly) {
/* Append only file: fsync() the AOF and exit */
fsync(server.appendfd);
exit(0);
} else {
/* Ooops.. error saving! The best we can do is to continue operating.
* Note that if there was a background saving process, in the next
* cron() Redis will be notified that the background saving aborted,
* handling special stuff like slaves pending for synchronization... */
redisLog(REDIS_WARNING,"Error trying to save the DB, can't exit");
addReplySds(c,sdsnew("-ERR can't quit, problems saving the DB\r\n"));
/* Snapshotting. Perform a SYNC SAVE and exit */
if (rdbSave(server.dbfilename) == REDIS_OK) {
if (server.daemonize)
unlink(server.pidfile);
redisLog(REDIS_WARNING,"%zu bytes used at exit",zmalloc_used_memory());
redisLog(REDIS_WARNING,"Server exit now, bye bye...");
exit(0);
} else {
/* Ooops.. error saving! The best we can do is to continue operating.
* Note that if there was a background saving process, in the next
* cron() Redis will be notified that the background saving aborted,
* handling special stuff like slaves pending for synchronization... */
redisLog(REDIS_WARNING,"Error trying to save the DB, can't exit");
addReplySds(c,sdsnew("-ERR can't quit, problems saving the DB\r\n"));
}
}
}