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

Method dbOverwriteCore

src/db.cpp:318–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318void redisDb::dbOverwriteCore(redisDb::iter itr, sds keySds, robj *val, bool fUpdateMvcc, bool fRemoveExpire)
319{
320 robj *old = itr.val();
321 redisObjectStack keyO;
322 initStaticStringObject(keyO, keySds);
323 robj *key = &keyO;
324
325 if (old->FExpires()) {
326 if (fRemoveExpire) {
327 ::removeExpire(this, key);
328 }
329 else {
330 if (val->getrefcount(std::memory_order_relaxed) == OBJ_SHARED_REFCOUNT)
331 val = dupStringObject(val);
332 ::updateExpire(this, itr.key(), old, val);
333 }
334 }
335
336 if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) {
337 val->lru = old->lru;
338 }
339 if (fUpdateMvcc) {
340 if (val->getrefcount(std::memory_order_relaxed) == OBJ_SHARED_REFCOUNT)
341 val = dupStringObject(val);
342 setMvccTstamp(val, getMvccTstamp());
343 }
344
345 /* Although the key is not really deleted from the database, we regard
346 overwrite as two steps of unlink+add, so we still need to call the unlink
347 callback of the module. */
348 moduleNotifyKeyUnlink(key,old);
349
350 if (g_pserver->lazyfree_lazy_server_del)
351 freeObjAsync(key, itr.val());
352 else
353 decrRefCount(itr.val());
354
355 updateValue(itr, val);
356}
357
358/* Overwrite an existing key with a new value. Incrementing the reference
359 * count of the new value is up to the caller.

Callers 2

dbOverwriteFunction · 0.80
dbMergeFunction · 0.80

Calls 12

removeExpireFunction · 0.85
dupStringObjectFunction · 0.85
updateExpireFunction · 0.85
setMvccTstampFunction · 0.85
getMvccTstampFunction · 0.85
moduleNotifyKeyUnlinkFunction · 0.85
freeObjAsyncFunction · 0.85
decrRefCountFunction · 0.85
FExpiresMethod · 0.80
getrefcountMethod · 0.80
valMethod · 0.45
keyMethod · 0.45

Tested by

no test coverage detected