Commit 724376a0 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Backport patch: object swappability for encoded sorted sets

parent 476f044d
...@@ -368,7 +368,6 @@ double computeObjectSwappability(robj *o) { ...@@ -368,7 +368,6 @@ double computeObjectSwappability(robj *o) {
listNode *ln; listNode *ln;
dict *d; dict *d;
struct dictEntry *de; struct dictEntry *de;
int z;
if (minage <= 0) return 0; if (minage <= 0) return 0;
switch(o->type) { switch(o->type) {
...@@ -395,23 +394,34 @@ double computeObjectSwappability(robj *o) { ...@@ -395,23 +394,34 @@ double computeObjectSwappability(robj *o) {
} }
break; break;
case REDIS_SET: case REDIS_SET:
case REDIS_ZSET: if (o->encoding == REDIS_ENCODING_INTSET) {
z = (o->type == REDIS_ZSET);
d = z ? ((zset*)o->ptr)->dict : o->ptr;
if (!z && o->encoding == REDIS_ENCODING_INTSET) {
intset *is = o->ptr; intset *is = o->ptr;
asize = sizeof(*is)+is->encoding*is->length; asize = sizeof(*is)+is->encoding*is->length;
} else { } else {
d = o->ptr;
asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d)); asize = sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
if (z) asize += sizeof(zset)-sizeof(dict);
if (dictSize(d)) { if (dictSize(d)) {
de = dictGetRandomKey(d); de = dictGetRandomKey(d);
ele = dictGetEntryKey(de); ele = dictGetEntryKey(de);
elesize = (ele->encoding == REDIS_ENCODING_RAW) ? elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o); (sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
asize += (sizeof(struct dictEntry)+elesize)*dictSize(d); asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
if (z) asize += sizeof(zskiplistNode)*dictSize(d); }
}
break;
case REDIS_ZSET:
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
asize = sizeof(*o)+(ziplistSize(o->ptr) / 2);
} else {
d = ((zset*)o->ptr)->dict;
asize = sizeof(zset)+(sizeof(struct dictEntry*)*dictSlots(d));
if (dictSize(d)) {
de = dictGetRandomKey(d);
ele = dictGetEntryKey(de);
elesize = (ele->encoding == REDIS_ENCODING_RAW) ?
(sizeof(*o)+sdslen(ele->ptr)) : sizeof(*o);
asize += (sizeof(struct dictEntry)+elesize)*dictSize(d);
asize += sizeof(zskiplistNode)*dictSize(d);
} }
} }
break; break;
......
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