mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 16:48:27 -05:00
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.
This commit is contained in:
parent
e9629e148b
commit
adcfb77b5b
12
src/object.c
12
src/object.c
@ -754,15 +754,15 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
|
|||||||
asize = sizeof(*o)+(ziplistBlobLen(o->ptr));
|
asize = sizeof(*o)+(ziplistBlobLen(o->ptr));
|
||||||
} else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
|
} else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
|
||||||
d = ((zset*)o->ptr)->dict;
|
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));
|
asize = sizeof(*o)+sizeof(zset)+(sizeof(struct dictEntry*)*dictSlots(d));
|
||||||
while((de = dictNext(di)) != NULL && samples < sample_size) {
|
while(znode != NULL && samples < sample_size) {
|
||||||
ele = dictGetKey(de);
|
elesize += sdsAllocSize(znode->ele);
|
||||||
elesize += sdsAllocSize(ele);
|
elesize += sizeof(struct dictEntry) + zmalloc_size(znode);
|
||||||
elesize += sizeof(struct dictEntry) + sizeof(zskiplistNode);
|
|
||||||
samples++;
|
samples++;
|
||||||
|
znode = znode->level[0].forward;
|
||||||
}
|
}
|
||||||
dictReleaseIterator(di);
|
|
||||||
if (samples) asize += (double)elesize/samples*dictSize(d);
|
if (samples) asize += (double)elesize/samples*dictSize(d);
|
||||||
} else {
|
} else {
|
||||||
serverPanic("Unknown sorted set encoding");
|
serverPanic("Unknown sorted set encoding");
|
||||||
|
Loading…
Reference in New Issue
Block a user