From 9a3730289f6dba0878d83ddb3e8e5ec323ad6682 Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 1 Jan 2011 21:39:48 +0100 Subject: [PATCH] blocking load fixed with the new design --- src/db.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/db.c b/src/db.c index c985794d..8684bb1a 100644 --- a/src/db.c +++ b/src/db.c @@ -34,12 +34,18 @@ robj *lookupKey(redisDb *db, robj *key) { /* Key not found in the in memory hash table, but if disk store is * enabled we may have this key on disk. If so load it in memory - * in a blocking way. - * - * FIXME: race condition here. If there was an already scheduled - * async loading of this key, what may happen is that the old - * key is loaded in memory if this gets deleted in the meantime. */ + * in a blocking way. */ if (server.ds_enabled && cacheKeyMayExist(db,key)) { + if (cacheScheduleIOGetFlags(db,key) & + (REDIS_IO_SAVE|REDIS_IO_SAVEINPROG)) + { + /* There is a save in progress for this object! + * Wait for it to get out. */ + waitEmptyIOJobsQueue(); + processAllPendingIOJobs(); + redisAssert((cacheScheduleIOGetFlags(db,key) & (REDIS_IO_SAVE|REDIS_IO_SAVEINPROG)) == 0); + } + redisLog(REDIS_DEBUG,"Force loading key %s via lookup", key->ptr); val = dsGet(db,key,&expire); -- 2.47.2