From adcfb77b5bf273f5e4fc463edcc91045defb5cd9 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 15 Sep 2016 17:43:13 +0200 Subject: [PATCH] objectComputeSize(): skiplist nodes have different sizes. The size of the node depends on the node level, however it is not stored into the node itself, is an implicit information, so we use zmalloc_size() in order to compute the sorted set size. --- src/object.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/object.c b/src/object.c index 02d023248..cfeba5a43 100644 --- a/src/object.c +++ b/src/object.c @@ -754,15 +754,15 @@ size_t objectComputeSize(robj *o, size_t sample_size) { asize = sizeof(*o)+(ziplistBlobLen(o->ptr)); } else if (o->encoding == OBJ_ENCODING_SKIPLIST) { d = ((zset*)o->ptr)->dict; - di = dictGetIterator(d); + zskiplist *zsl = ((zset*)o->ptr)->zsl; + zskiplistNode *znode = zsl->header->level[0].forward; asize = sizeof(*o)+sizeof(zset)+(sizeof(struct dictEntry*)*dictSlots(d)); - while((de = dictNext(di)) != NULL && samples < sample_size) { - ele = dictGetKey(de); - elesize += sdsAllocSize(ele); - elesize += sizeof(struct dictEntry) + sizeof(zskiplistNode); + while(znode != NULL && samples < sample_size) { + elesize += sdsAllocSize(znode->ele); + elesize += sizeof(struct dictEntry) + zmalloc_size(znode); samples++; + znode = znode->level[0].forward; } - dictReleaseIterator(di); if (samples) asize += (double)elesize/samples*dictSize(d); } else { serverPanic("Unknown sorted set encoding");