avoid actively expiring keys in the cron loop if this keys are being swapped or loaded. This avoids a rare race condition

This commit is contained in:
antirez
2010-09-07 13:16:39 +02:00
parent 00a90feb0b
commit 521cdafafe
+11
View File
@@ -1515,10 +1515,21 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
num = REDIS_EXPIRELOOKUPS_PER_CRON;
while (num--) {
dictEntry *de;
robj *key;
time_t t;
if ((de = dictGetRandomKey(db->expires)) == NULL) break;
t = (time_t) dictGetEntryVal(de);
key = dictGetEntryKey(de);
/* Don't expire keys that are in the contest of I/O jobs.
* Otherwise decrRefCount will kill the I/O thread and
* clients waiting for this keys will wait forever.
*
* In general this change will not have any impact on the
* performance of the expiring algorithm but it's much safer. */
if (server.vm_enabled &&
(key->storage == REDIS_VM_SWAPPING ||
key->storage == REDIS_VM_LOADING)) continue;
if (now > t) {
deleteKey(db,dictGetEntryKey(de));
expired++;