MCPcopy Create free account
hub / github.com/F-Stack/f-stack / defragKey

Function defragKey

app/redis-6.2.6/src/defrag.c:815–888  ·  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

813 * all the various pointers it has. Returns a stat of how many pointers were
814 * moved. */
815long defragKey(redisDb *db, dictEntry *de) {
816 sds keysds = dictGetKey(de);
817 robj *newob, *ob;
818 unsigned char *newzl;
819 long defragged = 0;
820 sds newsds;
821
822 /* Try to defrag the key name. */
823 newsds = activeDefragSds(keysds);
824 if (newsds)
825 defragged++, de->key = newsds;
826 if (dictSize(db->expires)) {
827 /* Dirty code:
828 * I can't search in db->expires for that key after i already released
829 * the pointer it holds it won't be able to do the string compare */
830 uint64_t hash = dictGetHash(db->dict, de->key);
831 replaceSatelliteDictKeyPtrAndOrDefragDictEntry(db->expires, keysds, newsds, hash, &defragged);
832 }
833
834 /* Try to defrag robj and / or string value. */
835 ob = dictGetVal(de);
836 if ((newob = activeDefragStringOb(ob, &defragged))) {
837 de->v.val = newob;
838 ob = newob;
839 }
840
841 if (ob->type == OBJ_STRING) {
842 /* Already handled in activeDefragStringOb. */
843 } else if (ob->type == OBJ_LIST) {
844 if (ob->encoding == OBJ_ENCODING_QUICKLIST) {
845 defragged += defragQuicklist(db, de);
846 } else if (ob->encoding == OBJ_ENCODING_ZIPLIST) {
847 if ((newzl = activeDefragAlloc(ob->ptr)))
848 defragged++, ob->ptr = newzl;
849 } else {
850 serverPanic("Unknown list encoding");
851 }
852 } else if (ob->type == OBJ_SET) {
853 if (ob->encoding == OBJ_ENCODING_HT) {
854 defragged += defragSet(db, de);
855 } else if (ob->encoding == OBJ_ENCODING_INTSET) {
856 intset *newis, *is = ob->ptr;
857 if ((newis = activeDefragAlloc(is)))
858 defragged++, ob->ptr = newis;
859 } else {
860 serverPanic("Unknown set encoding");
861 }
862 } else if (ob->type == OBJ_ZSET) {
863 if (ob->encoding == OBJ_ENCODING_ZIPLIST) {
864 if ((newzl = activeDefragAlloc(ob->ptr)))
865 defragged++, ob->ptr = newzl;
866 } else if (ob->encoding == OBJ_ENCODING_SKIPLIST) {
867 defragged += defragZsetSkiplist(db, de);
868 } else {
869 serverPanic("Unknown sorted set encoding");
870 }
871 } else if (ob->type == OBJ_HASH) {
872 if (ob->encoding == OBJ_ENCODING_ZIPLIST) {

Callers 1

defragScanCallbackFunction · 0.85

Calls 11

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

Tested by

no test coverage detected