Skip to content

Commit

Permalink
missed updating a few spots
Browse files Browse the repository at this point in the history
Signed-off-by: Rain Valentine <[email protected]>
  • Loading branch information
SoftlyRaining committed Oct 29, 2024
1 parent ee1d6ad commit 36cb9ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/lazyfree.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ size_t lazyfreeGetFreeEffort(robj *key, robj *obj, int dbid) {
if (obj->type == OBJ_LIST && obj->encoding == OBJ_ENCODING_QUICKLIST) {
quicklist *ql = obj->ptr;
return ql->len;
} else if (obj->type == OBJ_SET && obj->encoding == OBJ_ENCODING_HT) {
dict *ht = obj->ptr;
return dictSize(ht);
} else if (obj->type == OBJ_SET && obj->encoding == OBJ_ENCODING_HASHSET) {
hashset *s = obj->ptr;
return hashsetSize(s);
} else if (obj->type == OBJ_ZSET && obj->encoding == OBJ_ENCODING_SKIPLIST) {
zset *zs = obj->ptr;
return zs->zsl->length;
Expand Down
32 changes: 26 additions & 6 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -10995,27 +10995,39 @@ typedef struct {
ValkeyModuleScanKeyCB fn;
} ScanKeyCBData;

static void moduleScanKeyCallback(void *privdata, const dictEntry *de) {
static void moduleScanKeyDictCallback(void *privdata, const dictEntry *de) {
ScanKeyCBData *data = privdata;
sds key = dictGetKey(de);
robj *o = data->key->value;
robj *field = createStringObject(key, sdslen(key));
robj *value = NULL;
if (o->type == OBJ_SET) {
value = NULL;
} else if (o->type == OBJ_HASH) {
if (o->type == OBJ_HASH) {
sds val = dictGetVal(de);
value = createStringObject(val, sdslen(val));
} else if (o->type == OBJ_ZSET) {
double *val = (double *)dictGetVal(de);
value = createStringObjectFromLongDouble(*val, 0);
} else {
serverPanic("unexpected object type");
}

data->fn(data->key, field, value, data->user_data);
decrRefCount(field);
if (value) decrRefCount(value);
}

static void moduleScanKeyHashsetCallback(void *privdata, void *element) {
ScanKeyCBData *data = privdata;
sds key = element;
robj *o = data->key->value;
robj *field = createStringObject(key, sdslen(key));

serverAssert(o->type == OBJ_SET);

data->fn(data->key, field, NULL, data->user_data);
decrRefCount(field);
}

/* Scan api that allows a module to scan the elements in a hash, set or sorted set key
*
* Callback for scan implementation.
Expand Down Expand Up @@ -11070,9 +11082,10 @@ int VM_ScanKey(ValkeyModuleKey *key, ValkeyModuleScanCursor *cursor, ValkeyModul
return 0;
}
dict *ht = NULL;
hashset *s = NULL;
robj *o = key->value;
if (o->type == OBJ_SET) {
if (o->encoding == OBJ_ENCODING_HT) ht = o->ptr;
if (o->encoding == OBJ_ENCODING_HASHSET) s = o->ptr;
} else if (o->type == OBJ_HASH) {
if (o->encoding == OBJ_ENCODING_HT) ht = o->ptr;
} else if (o->type == OBJ_ZSET) {
Expand All @@ -11088,7 +11101,14 @@ int VM_ScanKey(ValkeyModuleKey *key, ValkeyModuleScanCursor *cursor, ValkeyModul
int ret = 1;
if (ht) {
ScanKeyCBData data = {key, privdata, fn};
cursor->cursor = dictScan(ht, cursor->cursor, moduleScanKeyCallback, &data);
cursor->cursor = dictScan(ht, cursor->cursor, moduleScanKeyDictCallback, &data);
if (cursor->cursor == 0) {
cursor->done = 1;
ret = 0;
}
} else if (s) {
ScanKeyCBData data = {key, privdata, fn};
cursor->cursor = hashsetScan(s, cursor->cursor, moduleScanKeyHashsetCallback, &data, 0);
if (cursor->cursor == 0) {
cursor->done = 1;
ret = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
}
o->type = OBJ_SET;
o->encoding = OBJ_ENCODING_INTSET;
if (intsetLen(o->ptr) > server.set_max_intset_entries) setTypeConvert(o, OBJ_ENCODING_HT);
if (intsetLen(o->ptr) > server.set_max_intset_entries) setTypeConvert(o, OBJ_ENCODING_HASHSET);
break;
case RDB_TYPE_SET_LISTPACK:
if (deep_integrity_validation) server.stat_dump_payload_sanitizations++;
Expand All @@ -2368,7 +2368,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
decrRefCount(o);
goto emptykey;
}
if (setTypeSize(o) > server.set_max_listpack_entries) setTypeConvert(o, OBJ_ENCODING_HT);
if (setTypeSize(o) > server.set_max_listpack_entries) setTypeConvert(o, OBJ_ENCODING_HASHSET);
break;
case RDB_TYPE_ZSET_ZIPLIST: {
unsigned char *lp = lpNew(encoded_len);
Expand Down

0 comments on commit 36cb9ca

Please sign in to comment.