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

Method erase

src/StorageCache.cpp:85–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85bool StorageCache::erase(sds key)
86{
87 unsigned long long when = 0;
88 m_spstorage->retrieve(key, sdslen(key), [&when](const char *, size_t, const void * data, size_t cbdata) {
89 auto e = deserializeExpire((const char *)data, cbdata, nullptr);
90 if (e != nullptr)
91 when = e->when();
92 });
93 bool result = m_spstorage->erase(key, sdslen(key));
94 std::unique_lock<fastlock> ul(m_lock);
95 if (result)
96 {
97 if (m_pdict != nullptr)
98 {
99 uint64_t hash = dictSdsHash(key);
100 dictEntry *de = dictFind(m_pdict, reinterpret_cast<void*>(hash));
101 serverAssert(de != nullptr);
102 de->v.s64--;
103 serverAssert(de->v.s64 >= 0);
104 if (de->v.s64 == 0) {
105 dictDelete(m_pdict, reinterpret_cast<void*>(hash));
106 } else {
107 m_collisionCount--;
108 }
109 }
110 if (when != 0) {
111 m_spstorage->removeExpire(key, sdslen(key), when);
112 }
113 }
114 return result;
115}
116
117void StorageCache::insert(sds key, const void *data, size_t cbdata, bool fOverwrite)
118{

Callers 15

syncDeleteMethod · 0.45
removeSubkeyExpireMethod · 0.45
endEpochMethod · 0.45
flushDataMethod · 0.45
expireSubKeyMethod · 0.45
popfrontExpireEntryMethod · 0.45
clearwaitMethod · 0.45
unlinkClientFunction · 0.45
processInputBufferFunction · 0.45
processClientsFunction · 0.45
free_random_memoryMethod · 0.45

Calls 8

sdslenFunction · 0.85
deserializeExpireFunction · 0.85
dictSdsHashFunction · 0.70
dictFindFunction · 0.70
dictDeleteFunction · 0.70
retrieveMethod · 0.45
whenMethod · 0.45
removeExpireMethod · 0.45

Tested by 6

free_random_memoryMethod · 0.36
getMetricsMethod · 0.36
StripTrailingSpacesFunction · 0.36
ReleaseMethod · 0.36
OnThreadExitMethod · 0.36