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

Method addEntry

src/evict.cpp:497–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

495 }
496
497 ssize_t addEntry(dict *d, dictEntry *de) {
498 ssize_t cbFreedNow = 0;
499 ssize_t cb = sizeof(dictEntry);
500 cb += sdsAllocSize((sds)dictGetKey(de));
501 robj *o = (robj*)dictGetVal(de);
502 switch (o->type) {
503 case OBJ_STRING:
504 cb += getStringObjectSdsUsedMemory(o)+sizeof(robj);
505 break;
506
507 default:
508 // If we don't know about it we can't accurately track the memory so free now
509 cbFreedNow = zmalloc_used_memory();
510 decrRefCount(o);
511 cbFreedNow -= zmalloc_used_memory();
512 de->v.val = nullptr;
513 }
514
515 auto itr = std::lower_bound(vecdictvecde.begin(), vecdictvecde.end(), d,
516 [](const std::pair<dict*, std::vector<dictEntry*>> &a, dict *d) -> bool {
517 return a.first < d;
518 }
519 );
520 if (itr == vecdictvecde.end() || itr->first != d) {
521 itr = vecdictvecde.insert(itr, std::make_pair(d, std::vector<dictEntry*>()));
522 __atomic_fetch_add(&d->refcount, 1, __ATOMIC_ACQ_REL);
523 }
524 serverAssert(itr->first == d);
525 itr->second.push_back(de);
526 m_cb += cb;
527 return cb + cbFreedNow;
528 }
529
530 size_t memory_queued() { return m_cb; }
531};

Callers 1

performEvictionsFunction · 0.80

Calls 7

sdsAllocSizeFunction · 0.85
zmalloc_used_memoryFunction · 0.85
decrRefCountFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected