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

Function dbAsyncDelete

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

Source from the content-addressed store, hash-verified

144 * will be reclaimed in a different bio.c thread. */
145#define LAZYFREE_THRESHOLD 64
146int dbAsyncDelete(redisDb *db, robj *key) {
147 /* Deleting an entry from the expires dict will not free the sds of
148 * the key, because it is shared with the main dictionary. */
149 if (dictSize(db->expires) > 0) dictDelete(db->expires,key->ptr);
150
151 /* If the value is composed of a few allocations, to free in a lazy way
152 * is actually just slower... So under a certain limit we just free
153 * the object synchronously. */
154 dictEntry *de = dictUnlink(db->dict,key->ptr);
155 if (de) {
156 robj *val = dictGetVal(de);
157
158 /* Tells the module that the key has been unlinked from the database. */
159 moduleNotifyKeyUnlink(key,val);
160
161 size_t free_effort = lazyfreeGetFreeEffort(key,val);
162
163 /* If releasing the object is too much work, do it in the background
164 * by adding the object to the lazy free list.
165 * Note that if the object is shared, to reclaim it now it is not
166 * possible. This rarely happens, however sometimes the implementation
167 * of parts of the Redis core may call incrRefCount() to protect
168 * objects, and then call dbDelete(). In this case we'll fall
169 * through and reach the dictFreeUnlinkedEntry() call, that will be
170 * equivalent to just calling decrRefCount(). */
171 if (free_effort > LAZYFREE_THRESHOLD && val->refcount == 1) {
172 atomicIncr(lazyfree_objects,1);
173 bioCreateLazyFreeJob(lazyfreeFreeObject,1, val);
174 dictSetVal(db->dict,de,NULL);
175 }
176 }
177
178 /* Release the key-val pair, or just the key if we set the val
179 * field to NULL in order to lazy free it later. */
180 if (de) {
181 dictFreeUnlinkedEntry(db->dict,de);
182 if (server.cluster_enabled) slotToKeyDel(key->ptr);
183 return 1;
184 } else {
185 return 0;
186 }
187}
188
189/* Free an object, if the object is huge enough, free it in async way. */
190void freeObjAsync(robj *key, robj *obj) {

Callers 8

expireGenericCommandFunction · 0.85
getexCommandFunction · 0.85
getdelCommandFunction · 0.85
performEvictionsFunction · 0.85
dbDeleteFunction · 0.85
delGenericCommandFunction · 0.85
RM_UnlinkKeyFunction · 0.85

Calls 7

dictUnlinkFunction · 0.85
moduleNotifyKeyUnlinkFunction · 0.85
lazyfreeGetFreeEffortFunction · 0.85
bioCreateLazyFreeJobFunction · 0.85
dictFreeUnlinkedEntryFunction · 0.85
slotToKeyDelFunction · 0.85
dictDeleteFunction · 0.70

Tested by

no test coverage detected