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

Method syncDelete

src/db.cpp:470–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470bool redisDbPersistentData::syncDelete(robj *key)
471{
472 /* Deleting an entry from the expires dict will not free the sds of
473 * the key, because it is shared with the main dictionary. */
474
475 auto itr = find(szFromObj(key));
476 if (itr != nullptr && itr.val()->FExpires())
477 removeExpire(key, itr);
478
479 robj_sharedptr val(itr.val());
480 bool fDeleted = false;
481 if (m_spstorage != nullptr)
482 fDeleted = m_spstorage->erase(szFromObj(key));
483 fDeleted = (dictDelete(m_pdict,ptrFromObj(key)) == DICT_OK) || fDeleted;
484
485 if (fDeleted) {
486 /* Tells the module that the key has been unlinked from the database. */
487 moduleNotifyKeyUnlink(key,val); // MODULE Compat Note: We should be giving the actual key value here
488
489 dictEntry *de = dictUnlink(m_dictChanged, szFromObj(key));
490 if (de != nullptr)
491 {
492 bool fUpdate = (bool)dictGetVal(de);
493 if (!fUpdate)
494 --m_cnewKeysPending;
495 dictFreeUnlinkedEntry(m_dictChanged, de);
496 }
497
498 if (m_pdbSnapshot != nullptr)
499 {
500 auto itr = m_pdbSnapshot->find_cached_threadsafe(szFromObj(key));
501 if (itr != nullptr)
502 {
503 sds keyTombstone = sdsdupshared(itr.key());
504 uint64_t hash = dictGetHash(m_pdict, keyTombstone);
505 if (dictAdd(m_pdictTombstone, keyTombstone, (void*)hash) != DICT_OK)
506 sdsfree(keyTombstone);
507 }
508 }
509 if (g_pserver->cluster_enabled) slotToKeyDel(szFromObj(key));
510 return 1;
511 } else {
512 return 0;
513 }
514}
515
516/* Delete a key, value, and associated expiration entry if any, from the DB */
517int dbSyncDelete(redisDb *db, robj *key) {

Callers 1

dbSyncDeleteFunction · 0.80

Calls 15

szFromObjFunction · 0.85
removeExpireFunction · 0.85
ptrFromObjFunction · 0.85
moduleNotifyKeyUnlinkFunction · 0.85
dictUnlinkFunction · 0.85
dictFreeUnlinkedEntryFunction · 0.85
sdsdupsharedFunction · 0.85
dictGetHashFunction · 0.85
sdsfreeFunction · 0.85
slotToKeyDelFunction · 0.85
FExpiresMethod · 0.80

Tested by

no test coverage detected