Commit 2f6b31c3 authored by antirez's avatar antirez
Browse files

Fix for a race in BGSAVE that may result in some data not being saved as soon...

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.
parent e5f257c2
...@@ -457,6 +457,7 @@ int rdbSaveBackground(char *filename) { ...@@ -457,6 +457,7 @@ int rdbSaveBackground(char *filename) {
if (server.bgsavechildpid != -1) return REDIS_ERR; if (server.bgsavechildpid != -1) return REDIS_ERR;
if (server.vm_enabled) waitEmptyIOJobsQueue(); if (server.vm_enabled) waitEmptyIOJobsQueue();
server.dirty_before_bgsave = server.dirty;
if ((childpid = fork()) == 0) { if ((childpid = fork()) == 0) {
/* Child */ /* Child */
if (server.vm_enabled) vmReopenSwapFile(); if (server.vm_enabled) vmReopenSwapFile();
...@@ -913,7 +914,7 @@ void backgroundSaveDoneHandler(int statloc) { ...@@ -913,7 +914,7 @@ void backgroundSaveDoneHandler(int statloc) {
if (!bysignal && exitcode == 0) { if (!bysignal && exitcode == 0) {
redisLog(REDIS_NOTICE, redisLog(REDIS_NOTICE,
"Background saving terminated with success"); "Background saving terminated with success");
server.dirty = 0; server.dirty = server.dirty - server.dirty_before_bgsave;
server.lastsave = time(NULL); server.lastsave = time(NULL);
} else if (!bysignal && exitcode != 0) { } else if (!bysignal && exitcode != 0) {
redisLog(REDIS_WARNING, "Background saving error"); redisLog(REDIS_WARNING, "Background saving error");
......
...@@ -335,6 +335,7 @@ struct redisServer { ...@@ -335,6 +335,7 @@ struct redisServer {
int fd; int fd;
redisDb *db; redisDb *db;
long long dirty; /* changes to DB from the last save */ 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 *clients;
list *slaves, *monitors; list *slaves, *monitors;
char neterr[ANET_ERR_LEN]; char neterr[ANET_ERR_LEN];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment