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

Function slotToKeyUpdateKeyCore

src/db.cpp:2469–2495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2467}
2468
2469void slotToKeyUpdateKeyCore(const char *key, size_t keylen, int add) {
2470 serverAssert(GlobalLocksAcquired());
2471
2472 unsigned int hashslot = keyHashSlot(key,keylen);
2473 g_pserver->cluster->slots_keys_count[hashslot] += add ? 1 : -1;
2474
2475 if (g_pserver->m_pstorageFactory == nullptr) {
2476 unsigned char buf[64];
2477 unsigned char *indexed = buf;
2478
2479 if (keylen+2 > 64) indexed = (unsigned char*)zmalloc(keylen+2, MALLOC_SHARED);
2480 indexed[0] = (hashslot >> 8) & 0xff;
2481 indexed[1] = hashslot & 0xff;
2482 memcpy(indexed+2,key,keylen);
2483 int fModified = false;
2484 if (add) {
2485 fModified = raxInsert(g_pserver->cluster->slots_to_keys,indexed,keylen+2,NULL,NULL);
2486 } else {
2487 fModified = raxRemove(g_pserver->cluster->slots_to_keys,indexed,keylen+2,NULL);
2488 }
2489 // This assert is disabled when a snapshot depth is >0 because prepOverwriteForSnapshot will add in a tombstone,
2490 // this prevents ensure from adding the key to the dictionary which means the caller isn't aware we're already tracking
2491 // the key.
2492 serverAssert(fModified || g_pserver->db[0]->snapshot_depth() > 0);
2493 if (indexed != buf) zfree(indexed);
2494 }
2495}
2496
2497void slotToKeyAdd(sds key) {
2498 slotToKeyUpdateKey(key,1);

Callers 3

slotToKeyUpdateKeyFunction · 0.85

Calls 7

GlobalLocksAcquiredFunction · 0.85
keyHashSlotFunction · 0.85
zmallocFunction · 0.85
raxInsertFunction · 0.85
raxRemoveFunction · 0.85
zfreeFunction · 0.85
snapshot_depthMethod · 0.80

Tested by

no test coverage detected