From: antirez Date: Mon, 30 Aug 2010 08:32:32 +0000 (+0200) Subject: Fix for a race in BGSAVE that may result in some data not being saved as soon as... X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/2f6b31c3bb95443991513e496d8d19656c4a80b5 Fix for a race in BGSAVE that may result in some data not being saved as soon as possible (when the configured saving triggers should fire). Also known as Issue 313, more details there in the google code issue. --- diff --git a/src/rdb.c b/src/rdb.c index d8de5f76..c15fc6f2 100644 --- 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"); diff --git a/src/redis.h b/src/redis.h index a4fdcb19..9e27d724 100644 --- a/src/redis.h +++ b/src/redis.h @@ -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];