Commit 292df99a authored by Vitaly Arbuzov's avatar Vitaly Arbuzov
Browse files

Cache current slot specific dictionary

Add comment

Populate current dictionary in the right place
parent 83103f83
......@@ -244,6 +244,9 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
/* Return slot-specific dictionary for key based on key's hash slot in CME, or 0 in CMD.*/
dict *getDict(redisDb *db, sds key) {
if (db->current_dict) {
return db->current_dict;
}
return db->dict[(server.cluster_enabled ? keyHashSlot(key, (int) sdslen(key)) : 0)];
}
......
......@@ -2593,6 +2593,7 @@ void initServer(void) {
server.db[j].defrag_later = listCreate();
server.db[j].rehashing = listCreate();
server.db[j].dict_count = slotCount;
server.db[j].current_dict = NULL;
listSetFreeMethod(server.db[j].defrag_later,(void (*)(void*))sdsfree);
}
evictionPoolAlloc(); /* Initialize the LRU keys pool. */
......@@ -4098,7 +4099,8 @@ int processCommand(client *c) {
blockPostponeClient(c);
return C_OK;
}
/* Set current dictionary for the command, this optimization helps avoid redundant CRC hash calculations to determine key slot. */
if (c->slot >= 0) c->db->current_dict = c->db->dict[c->slot];
/* Exec the command */
if (c->flags & CLIENT_MULTI &&
c->cmd->proc != execCommand &&
......@@ -4116,7 +4118,7 @@ int processCommand(client *c) {
if (listLength(server.ready_keys))
handleClientsBlockedOnKeys();
}
c->db->current_dict = NULL;
return C_OK;
}
......
......@@ -959,6 +959,7 @@ typedef struct redisDb {
list *defrag_later; /* List of key names to attempt to defrag one by one, gradually. */
list *rehashing; /* List of dictionaries in this DB that are currently rehashing. */
int dict_count; /* Indicates total number of dictionaires owned by this DB, 1 dict per slot in cluster mode. */
dict *current_dict; /* Slot specific dictionary used in the current command, in cluster mode. */
} redisDb;
/* forward declaration for functions ctx */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment