Skip to content

Commit

Permalink
diskstore race condition fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 2, 2011
1 parent 133cf28 commit e37efb0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/dscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ void cacheScheduleIOAddFlag(redisDb *db, robj *key, long flag) {
return;
} else {
long flags = (long) dictGetEntryVal(de);

if (flags & flag) {
redisLog(REDIS_WARNING,"Adding the same flag again: was: %ld, addede: %ld",flags,flag);
redisAssert(!(flags & flag));
}
flags |= flag;
dictGetEntryVal(de) = (void*) flags;
}
Expand Down Expand Up @@ -662,6 +667,8 @@ void cacheCron(void) {

topush = 100-jobs;
if (topush < 0) topush = 0;
if (topush > (signed)listLength(server.cache_io_queue))
topush = listLength(server.cache_io_queue);

while((ln = listFirst(server.cache_io_queue)) != NULL) {
ioop *op = ln->value;
Expand All @@ -675,6 +682,23 @@ void cacheCron(void) {
struct dictEntry *de;
robj *val;

/* Don't add a SAVE job in queue if there is already
* a save in progress for the same key. */
if (op->type == REDIS_IO_SAVE &&
cacheScheduleIOGetFlags(op->db,op->key) & REDIS_IO_SAVEINPROG)
{
/* Move the operation at the end of the list of there
* are other operations. Otherwise break, nothing to do
* here. */
if (listLength(server.cache_io_queue) > 1) {
listDelNode(server.cache_io_queue,ln);
listAddNodeTail(server.cache_io_queue,op);
continue;
} else {
break;
}
}

redisLog(REDIS_DEBUG,"Creating IO %s Job for key %s",
op->type == REDIS_IO_LOAD ? "load" : "save", op->key->ptr);

Expand Down

0 comments on commit e37efb0

Please sign in to comment.