Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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. (backported from master)
  • Loading branch information...
commit eaaf62f6a4268d95f63265dc2cc3c3fe8b47689c 1 parent eff09a7
@antirez authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 redis.c
View
4 redis.c
@@ -347,6 +347,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];
@@ -1320,7 +1321,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");
@@ -3790,6 +3791,7 @@ static 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();
Please sign in to comment.
Something went wrong with that request. Please try again.