Commit e9965772 authored by Vitaly Arbuzov's avatar Vitaly Arbuzov
Browse files

Use dict selection logic in defrag.c

parent 96b24607
...@@ -679,12 +679,12 @@ void defragKey(redisDb *db, dictEntry *de) { ...@@ -679,12 +679,12 @@ void defragKey(redisDb *db, dictEntry *de) {
/* Try to defrag the key name. */ /* Try to defrag the key name. */
newsds = activeDefragSds(keysds); newsds = activeDefragSds(keysds);
if (newsds) { if (newsds) {
dictSetKey(db->dict, de, newsds); dictSetKey(getDict(db, newsds), de, newsds);
if (dictSize(db->expires)) { if (dictSize(db->expires)) {
/* We can't search in db->expires for that key after we've released /* We can't search in db->expires for that key after we've released
* the pointer it holds, since it won't be able to do the string * the pointer it holds, since it won't be able to do the string
* compare, but we can find the entry using key hash and pointer. */ * compare, but we can find the entry using key hash and pointer. */
uint64_t hash = dictGetHash(db->dict, newsds); uint64_t hash = dictGetHash(getDict(db, newsds), newsds);
dictEntry *expire_de = dictFindEntryByPtrAndHash(db->expires, keysds, hash); dictEntry *expire_de = dictFindEntryByPtrAndHash(db->expires, keysds, hash);
if (expire_de) dictSetKey(db->expires, expire_de, newsds); if (expire_de) dictSetKey(db->expires, expire_de, newsds);
} }
...@@ -693,7 +693,7 @@ void defragKey(redisDb *db, dictEntry *de) { ...@@ -693,7 +693,7 @@ void defragKey(redisDb *db, dictEntry *de) {
/* Try to defrag robj and / or string value. */ /* Try to defrag robj and / or string value. */
ob = dictGetVal(de); ob = dictGetVal(de);
if ((newob = activeDefragStringOb(ob))) { if ((newob = activeDefragStringOb(ob))) {
dictSetVal(db->dict, de, newob); dictSetVal(getDict(db, newsds), de, newob);
ob = newob; ob = newob;
} }
...@@ -851,7 +851,7 @@ int defragLaterStep(redisDb *db, long long endtime) { ...@@ -851,7 +851,7 @@ int defragLaterStep(redisDb *db, long long endtime) {
} }
/* each time we enter this function we need to fetch the key from the dict again (if it still exists) */ /* each time we enter this function we need to fetch the key from the dict again (if it still exists) */
dictEntry *de = dictFind(db->dict, defrag_later_current_key); dictEntry *de = dictFind(getDict(db, defrag_later_current_key), defrag_later_current_key);
key_defragged = server.stat_active_defrag_hits; key_defragged = server.stat_active_defrag_hits;
do { do {
int quit = 0; int quit = 0;
...@@ -1007,7 +1007,8 @@ void activeDefragCycle(void) { ...@@ -1007,7 +1007,8 @@ void activeDefragCycle(void) {
db = &server.db[current_db]; db = &server.db[current_db];
cursor = 0; cursor = 0;
} }
int slot = 0;
dict *d = db->dict[slot];
do { do {
/* before scanning the next bucket, see if we have big keys left from the previous bucket to scan */ /* before scanning the next bucket, see if we have big keys left from the previous bucket to scan */
if (defragLaterStep(db, endtime)) { if (defragLaterStep(db, endtime)) {
...@@ -1017,11 +1018,11 @@ void activeDefragCycle(void) { ...@@ -1017,11 +1018,11 @@ void activeDefragCycle(void) {
/* Scan the keyspace dict unless we're scanning the expire dict. */ /* Scan the keyspace dict unless we're scanning the expire dict. */
if (!expires_cursor) if (!expires_cursor)
cursor = dictScanDefrag(db->dict, cursor, defragScanCallback, cursor = dictScanDefrag(d, cursor, defragScanCallback,
&defragfns, db); &defragfns, db);
if (!cursor) d = dbGetNextUnvisitedSlot(db, &slot);
/* When done scanning the keyspace dict, we scan the expire dict. */ /* When done scanning the keyspace dict, we scan the expire dict. */
if (!cursor) if (!cursor && slot > -1)
expires_cursor = dictScanDefrag(db->expires, expires_cursor, expires_cursor = dictScanDefrag(db->expires, expires_cursor,
scanCallbackCountScanned, scanCallbackCountScanned,
&defragfns, NULL); &defragfns, NULL);
...@@ -1044,7 +1045,7 @@ void activeDefragCycle(void) { ...@@ -1044,7 +1045,7 @@ void activeDefragCycle(void) {
prev_defragged = server.stat_active_defrag_hits; prev_defragged = server.stat_active_defrag_hits;
prev_scanned = server.stat_active_defrag_scanned; prev_scanned = server.stat_active_defrag_scanned;
} }
} while((cursor || expires_cursor) && !quit); } while(((cursor || slot > 0) || expires_cursor) && !quit);
} while(!quit); } while(!quit);
latencyEndMonitor(latency); latencyEndMonitor(latency);
......
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