]> git.saurik.com Git - redis.git/commitdiff
Fix for a race in BGSAVE that may result in some data not being saved as soon as...
authorantirez <antirez@gmail.com>
Mon, 30 Aug 2010 08:32:32 +0000 (10:32 +0200)
committerantirez <antirez@gmail.com>
Mon, 30 Aug 2010 08:32:32 +0000 (10:32 +0200)
src/rdb.c
src/redis.h

index d8de5f76790e76cc55d823bc14dfe8108a2d84fd..c15fc6f2fee086655551a4d52142d543903c7c00 100644 (file)
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -457,6 +457,7 @@ int rdbSaveBackground(char *filename) {
 
     if (server.bgsavechildpid != -1) return REDIS_ERR;
     if (server.vm_enabled) waitEmptyIOJobsQueue();
+    server.dirty_before_bgsave = server.dirty;
     if ((childpid = fork()) == 0) {
         /* Child */
         if (server.vm_enabled) vmReopenSwapFile();
@@ -913,7 +914,7 @@ void backgroundSaveDoneHandler(int statloc) {
     if (!bysignal && exitcode == 0) {
         redisLog(REDIS_NOTICE,
             "Background saving terminated with success");
-        server.dirty = 0;
+        server.dirty = server.dirty - server.dirty_before_bgsave;
         server.lastsave = time(NULL);
     } else if (!bysignal && exitcode != 0) {
         redisLog(REDIS_WARNING, "Background saving error");
index a4fdcb197de8ff786bedbec8b4530137503cf468..9e27d724854e1788199286f83e9437c81b7df954 100644 (file)
@@ -335,6 +335,7 @@ struct redisServer {
     int fd;
     redisDb *db;
     long long dirty;            /* changes to DB from the last save */
+    long long dirty_before_bgsave; /* used to restore dirty on failed BGSAVE */
     list *clients;
     list *slaves, *monitors;
     char neterr[ANET_ERR_LEN];