Skip to content

Commit

Permalink
PR fixes; hscan skip expired; OPEN: hrand can return expired
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Apr 2, 2024
1 parent dcf23aa commit 702c6eb
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ int rewriteHashObject(rio *r, robj *key, robj *o) {
long long count = 0, items = hashTypeLength(o, 0);

hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != C_ERR) {
while (hashTypeNext(hi, 0) != C_ERR) {
if (count == 0) {
int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
AOF_REWRITE_ITEMS_PER_CMD : items;
Expand Down
5 changes: 5 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ void scanCallback(void *privdata, const dictEntry *de) {
} else if (o->type == OBJ_HASH) {
key = keyStr;
val = dictGetVal(de);

/* If field is expired, then ignore */
if (hfieldIsExpired(key))
return;

} else if (o->type == OBJ_ZSET) {
char buf[MAX_LONG_DOUBLE_CHARS];
int len = ld2string(buf, sizeof(buf), *(double *)dictGetVal(de), LD_STR_AUTO);
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void xorObjectDigest(redisDb *db, robj *keyobj, unsigned char *digest, robj *o)
}
} else if (o->type == OBJ_HASH) {
hashTypeIterator *hi = hashTypeInitIterator(o);
while (hashTypeNext(hi) != C_ERR) {
while (hashTypeNext(hi, 0) != C_ERR) {
unsigned char eledigest[20];
sds sdsele;

Expand Down
11 changes: 10 additions & 1 deletion src/ebuckets.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ int ebSingleSegExpire(FirstSegHdr *firstSegHdr,
mIter->trash = 1;
ExpireAction act = info->onExpireItem(iter, info->ctx);

/* if (act == ACT_REMOVE_EXP_ITEM)
* then don't touch the item. Assume it got deleted */

/* If indicated to stop then break (cb didn't delete the item) */
if (act == ACT_STOP_ACTIVE_EXP) {
mIter->trash = 0;
Expand Down Expand Up @@ -460,6 +463,9 @@ static int ebSegExpire(FirstSegHdr *firstSegHdr,
mIter->trash = 1;
ExpireAction act = info->onExpireItem(toDelete, info->ctx);

/* if (act == ACT_REMOVE_EXP_ITEM)
* then don't touch the item. Assume it got deleted */

/* If indicated to stop then break (callback didn't delete the item) */
if (act == ACT_STOP_ACTIVE_EXP) {
mIter->trash = 0;
Expand Down Expand Up @@ -692,6 +698,9 @@ static int ebListExpire(ebuckets *eb,
metaItem->trash = 1;
ExpireAction act = info->onExpireItem(item, info->ctx);

/* if (act == ACT_REMOVE_EXP_ITEM)
* then don't touch the item. Assume it got deleted */

/* If indicated to stop then break (cb didn't delete the item) */
if (act == ACT_STOP_ACTIVE_EXP) {
metaItem->trash = 0;
Expand Down Expand Up @@ -737,7 +746,7 @@ static void ebValidateList(eItem head, EbucketsType *type) {
assert(mIter->numItems > 0 && mIter->numItems <= EB_LIST_MAX_ITEMS);
assert(mIter->firstItemBucket == 1);
} else {
/* Verify that expire time of previous item is smaller */
/* Verify that expire time of previous item is smaller or equal */
assert(ebGetMetaExpTime(mIterPrev) <= ebGetMetaExpTime(mIter));
assert(mIter->numItems == 0);
assert(mIter->firstItemBucket == 0);
Expand Down
2 changes: 1 addition & 1 deletion src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4168,7 +4168,7 @@ size_t RM_ValueLength(RedisModuleKey *key) {
case OBJ_LIST: return listTypeLength(key->value);
case OBJ_SET: return setTypeSize(key->value);
case OBJ_ZSET: return zsetLength(key->value);
case OBJ_HASH: return hashTypeLength(key->value, 1);
case OBJ_HASH: return hashTypeLength(key->value, 0); /* OPEN: To substract expired fields? */
case OBJ_STREAM: return streamLength(key->value);
default: return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3155,22 +3155,23 @@ void hashTypeRename(robj *o, sds newName);
int hashTypeIsEmpty(const robj *o);
hashTypeIterator *hashTypeInitIterator(robj *subject);
void hashTypeReleaseIterator(hashTypeIterator *hi);
int hashTypeNext(hashTypeIterator *hi);
int hashTypeNext(hashTypeIterator *hi, int skipExpiredFields);
void hashTypeCurrentFromListpack(hashTypeIterator *hi, int what,
unsigned char **vstr,
unsigned int *vlen,
long long *vll);
void hashTypeCurrentFromHashTable(hashTypeIterator *hi, int what, char **str,
size_t *len, uint64_t *expireTime);
void hashTypeCurrentObject(hashTypeIterator *hi, int what, unsigned char **vstr,
unsigned int *vlen, long long *vll);
unsigned int *vlen, long long *vll, uint64_t *expireTime);
sds hashTypeCurrentObjectNewSds(hashTypeIterator *hi, int what);
hfield hashTypeCurrentObjectNewHfield(hashTypeIterator *hi);
robj *hashTypeGetValueObject(robj *o, sds field);
int hashTypeSet(redisDb *db, robj *o, sds field, sds value, int flags);
robj *hashTypeDup(robj *o, sds newkey, uint64_t *minHashExpire);
uint64_t hashTypeRemoveFromExpires(ebuckets *hexpires, robj *o);
void hashTypeAddToExpires(redisDb *db, robj *keyObj, robj *hashObj, uint64_t expireTime);
int64_t hashTypeGetMinExpire(robj *keyObj);

/* Hash-Field data type (of t_hash.c) */
hfield hfieldNew(const void *field, size_t fieldlen, int withExpireMeta);
Expand Down
Loading

0 comments on commit 702c6eb

Please sign in to comment.