MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / moduleDefragValue

Function moduleDefragValue

src/module.cpp:9389–9422  ·  view source on GitHub ↗

Attempt to defrag a module data type value. Depending on complexity, * the operation may happen immediately or be scheduled for later. * * Returns 1 if the operation has been completed or 0 if it needs to * be scheduled for late defrag. */

Source from the content-addressed store, hash-verified

9387 * be scheduled for late defrag.
9388 */
9389int moduleDefragValue(robj *key, robj *value, long *defragged) {
9390 moduleValue *mv = (moduleValue*)ptrFromObj(value);
9391 moduleType *mt = mv->type;
9392
9393 /* Try to defrag moduleValue itself regardless of whether or not
9394 * defrag callbacks are provided.
9395 */
9396 moduleValue *newmv = (moduleValue*)activeDefragAlloc(mv);
9397 if (newmv) {
9398 (*defragged)++;
9399 value->m_ptr = mv = newmv;
9400 }
9401
9402 if (!mt->defrag)
9403 return 1;
9404
9405 /* Use free_effort to determine complexity of module value, and if
9406 * necessary schedule it for defragLater instead of quick immediate
9407 * defrag.
9408 */
9409 if (mt->free_effort) {
9410 size_t effort = mt->free_effort(key, mv->value);
9411 if (!effort)
9412 effort = SIZE_MAX;
9413 if (effort > cserver.active_defrag_max_scan_fields) {
9414 return 0; /* Defrag later */
9415 }
9416 }
9417
9418 RedisModuleDefragCtx defrag_ctx = { 0, 0, NULL };
9419 mt->defrag(&defrag_ctx, key, &mv->value);
9420 (*defragged) += defrag_ctx.defragged;
9421 return 1;
9422}
9423
9424/* Call registered module API defrag functions */
9425long moduleDefragGlobals(void) {

Callers 1

defragModuleFunction · 0.85

Calls 2

ptrFromObjFunction · 0.85
activeDefragAllocFunction · 0.85

Tested by

no test coverage detected