From ac945e2dcf8cf2890c5676cc26cbd6e6d2254b14 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 18 Dec 2009 07:31:44 -0500 Subject: [PATCH] SHUTDOWN now does the right thing when append only is on, that is, fsync instead to save the snapshot. --- TODO | 2 +- redis.c | 32 +++++++++++++++++++------------- test-redis.tcl | 6 +++++- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 6a7eb20a..b65bd486 100644 --- a/TODO +++ b/TODO @@ -75,7 +75,7 @@ it's not a guarantee they'll ever get implemented ;) * Pattern-matching replication. * Don't save empty lists / sets / zsets on disk with snapshotting. * Remove keys when a list / set / zset reaches length of 0. -* Add an option to relax the delete-expiring-keys-on-write semantic *denying* replication and AOF when this is on? Can be handy sometimes, when using Redis for non persistent state. +* Add an option to relax the delete-expiring-keys-on-write semantic *denying* replication and AOF when this is on? Can be handy sometimes, when using Redis for non persistent state, but can create problems. For instance should rename and move also "move" the timeouts? How does this affect other commands? DOCUMENTATION WISHLIST ====================== diff --git a/redis.c b/redis.c index 459b25c4..274dec7a 100644 --- a/redis.c +++ b/redis.c @@ -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")); + } } } diff --git a/test-redis.tcl b/test-redis.tcl index 004dc696..78cc3317 100644 --- a/test-redis.tcl +++ b/test-redis.tcl @@ -1184,7 +1184,11 @@ proc main {server port} { set _ $err } {} - test {ZRANGE and ZREVRANGE} { + test {ZRANGE and ZREVRANGE basics} { + list [$r zrange ztmp 0 -1] [$r zrevrange ztmp 0 -1] + } {{y x z} {z x y}} + + test {ZRANGE and ZREVRANGE stress testing} { list [$r zrange ztmp 0 -1] [$r zrevrange ztmp 0 -1] } {{y x z} {z x y}} -- 2.45.2