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

Function defragKey

src/defrag.cpp:838–906  ·  view source on GitHub ↗

for each key we scan in the main dict, this function will attempt to defrag * all the various pointers it has. Returns a stat of how many pointers were * moved. */

Source from the content-addressed store, hash-verified

836 * all the various pointers it has. Returns a stat of how many pointers were
837 * moved. */
838long defragKey(redisDb *db, dictEntry *de) {
839 sds keysds = (sds)dictGetKey(de);
840 robj *newob, *ob;
841 unsigned char *newzl;
842 long defragged = 0;
843 sds newsds;
844
845 ob = (robj*)dictGetVal(de);
846
847 /* Try to defrag the key name. */
848 newsds = activeDefragSds(keysds);
849 if (newsds) {
850 defragged++, de->key = newsds;
851 }
852
853 if ((newob = activeDefragStringOb(ob, &defragged))) {
854 de->v.val = newob;
855 ob = newob;
856 }
857
858 if (ob->type == OBJ_STRING) {
859 /* Already handled in activeDefragStringOb. */
860 } else if (ob->type == OBJ_LIST) {
861 if (ob->encoding == OBJ_ENCODING_QUICKLIST) {
862 defragged += defragQuicklist(db, de);
863 } else if (ob->encoding == OBJ_ENCODING_ZIPLIST) {
864 if ((newzl = (unsigned char*)activeDefragAlloc(ptrFromObj(ob))))
865 defragged++, ob->m_ptr = newzl;
866 } else {
867 serverPanic("Unknown list encoding");
868 }
869 } else if (ob->type == OBJ_SET) {
870 if (ob->encoding == OBJ_ENCODING_HT) {
871 defragged += defragSet(db, de);
872 } else if (ob->encoding == OBJ_ENCODING_INTSET) {
873 intset *newis, *is = (intset*)ptrFromObj(ob);
874 if ((newis = (intset*)activeDefragAlloc(is)))
875 defragged++, ob->m_ptr = newis;
876 } else {
877 serverPanic("Unknown set encoding");
878 }
879 } else if (ob->type == OBJ_ZSET) {
880 if (ob->encoding == OBJ_ENCODING_ZIPLIST) {
881 if ((newzl = (unsigned char*)activeDefragAlloc(ptrFromObj(ob))))
882 defragged++, ob->m_ptr = newzl;
883 } else if (ob->encoding == OBJ_ENCODING_SKIPLIST) {
884 defragged += defragZsetSkiplist(db, de);
885 } else {
886 serverPanic("Unknown sorted set encoding");
887 }
888 } else if (ob->type == OBJ_HASH) {
889 if (ob->encoding == OBJ_ENCODING_ZIPLIST) {
890 if ((newzl = (unsigned char*)activeDefragAlloc(ptrFromObj(ob))))
891 defragged++, ob->m_ptr = newzl;
892 } else if (ob->encoding == OBJ_ENCODING_HT) {
893 defragged += defragHash(db, de);
894 } else {
895 serverPanic("Unknown hash encoding");

Callers 1

defragScanCallbackFunction · 0.85

Calls 10

activeDefragSdsFunction · 0.85
activeDefragStringObFunction · 0.85
defragQuicklistFunction · 0.85
activeDefragAllocFunction · 0.85
ptrFromObjFunction · 0.85
defragSetFunction · 0.85
defragZsetSkiplistFunction · 0.85
defragHashFunction · 0.85
defragStreamFunction · 0.85
defragModuleFunction · 0.85

Tested by

no test coverage detected