MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lazyfreeGetFreeEffort

Function lazyfreeGetFreeEffort

app/redis-6.2.6/src/lazyfree.c:88–139  ·  view source on GitHub ↗

Return the amount of work needed in order to free an object. * The return value is not always the actual number of allocations the * object is composed of, but a number proportional to it. * * For strings the function always returns 1. * * For aggregated objects represented by hash tables or other data structures * the function just returns the number of elements the object is composed of.

Source from the content-addressed store, hash-verified

86 * For lists the function returns the number of elements in the quicklist
87 * representing the list. */
88size_t lazyfreeGetFreeEffort(robj *key, robj *obj) {
89 if (obj->type == OBJ_LIST) {
90 quicklist *ql = obj->ptr;
91 return ql->len;
92 } else if (obj->type == OBJ_SET && obj->encoding == OBJ_ENCODING_HT) {
93 dict *ht = obj->ptr;
94 return dictSize(ht);
95 } else if (obj->type == OBJ_ZSET && obj->encoding == OBJ_ENCODING_SKIPLIST){
96 zset *zs = obj->ptr;
97 return zs->zsl->length;
98 } else if (obj->type == OBJ_HASH && obj->encoding == OBJ_ENCODING_HT) {
99 dict *ht = obj->ptr;
100 return dictSize(ht);
101 } else if (obj->type == OBJ_STREAM) {
102 size_t effort = 0;
103 stream *s = obj->ptr;
104
105 /* Make a best effort estimate to maintain constant runtime. Every macro
106 * node in the Stream is one allocation. */
107 effort += s->rax->numnodes;
108
109 /* Every consumer group is an allocation and so are the entries in its
110 * PEL. We use size of the first group's PEL as an estimate for all
111 * others. */
112 if (s->cgroups && raxSize(s->cgroups)) {
113 raxIterator ri;
114 streamCG *cg;
115 raxStart(&ri,s->cgroups);
116 raxSeek(&ri,"^",NULL,0);
117 /* There must be at least one group so the following should always
118 * work. */
119 serverAssert(raxNext(&ri));
120 cg = ri.data;
121 effort += raxSize(s->cgroups)*(1+raxSize(cg->pel));
122 raxStop(&ri);
123 }
124 return effort;
125 } else if (obj->type == OBJ_MODULE) {
126 moduleValue *mv = obj->ptr;
127 moduleType *mt = mv->type;
128 if (mt->free_effort != NULL) {
129 size_t effort = mt->free_effort(key,mv->value);
130 /* If the module's free_effort returns 0, it will use asynchronous free
131 memory by default */
132 return effort == 0 ? ULONG_MAX : effort;
133 } else {
134 return 1;
135 }
136 } else {
137 return 1; /* Everything else is a single allocation. */
138 }
139}
140
141/* Delete a key, value, and associated expiration entry if any, from the DB.
142 * If there are enough allocations to free the value object may be put into

Callers 2

dbAsyncDeleteFunction · 0.85
freeObjAsyncFunction · 0.85

Calls 5

raxSizeFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
raxStopFunction · 0.85

Tested by

no test coverage detected