Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Optimize dictFind call in db module: genericSetKey #216

Draft
wants to merge 1 commit into
base: 6.0-memkind_alloc_by_size
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
dictFreeVal(db->dict, &auxentry);
}

static int removeExpireOptim(redisDb *db, robj *key) {
/* An expire may only be removed if there is a corresponding entry in the
* main dict. Otherwise, the key will never be freed. */
return dictDelete(db->expires,key->ptr) == DICT_OK;
}

/* High level Set operation. This function can be used in order to set
* a key, whatever it was existing or not, to a new object.
*
Expand All @@ -242,13 +248,41 @@ void dbOverwrite(redisDb *db, robj *key, robj *val) {
* The client 'c' argument may be set to NULL if the operation is performed
* in a context where there is no clear client performing the operation. */
void genericSetKey(client *c, redisDb *db, robj *key, robj *val, int keepttl, int signal) {
if (lookupKeyWrite(db,key) == NULL) {
expireIfNeeded(db,key);
robj *old = NULL;
dictEntry *de = dictFind(db->dict, key->ptr);
if (de) {
old= dictGetVal(de);

/* Update the access time for the ageing algorithm.
* Don't do it if we have a saving child, as this will trigger
* a copy on write madness. */
if (!hasActiveChildProcess()) {
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
updateLFU(val);
} else {
val->lru = LRU_CLOCK();
}
}
}
if (old == NULL) {
dbAdd(db,key,val);
} else {
dbOverwrite(db,key,val);
dictEntry auxentry = *de;
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
val->lru = old->lru;
}
dictSetVal(db->dict, de, val);

if (server.lazyfree_lazy_server_del) {
freeObjAsync(old);
dictSetVal(db->dict, &auxentry, NULL);
}

dictFreeVal(db->dict, &auxentry);
}
incrRefCount(val);
if (!keepttl) removeExpire(db,key);
if (!keepttl) removeExpireOptim(db,key);
if (signal) signalModifiedKey(c,db,key);
}

Expand Down