This commit is contained in:
moticless 2024-04-18 11:07:51 +03:00
parent 676188a776
commit f0c2bf9329
5 changed files with 10 additions and 66 deletions

View File

@ -932,7 +932,7 @@ void scanCallback(void *privdata, const dictEntry *de) {
list *keys = data->keys;
robj *o = data->o;
sds val = NULL;
void *key = NULL; /* (o->type == OBJ_HASH) ? hfield : sds */
void *key = NULL; /* if OBJ_HASH then key is of type `hfield`. Otherwise, `sds` */
data->sampled++;
/* o and typename can not have values at the same time. */

View File

@ -181,14 +181,14 @@ static void _dictReset(dict *d, int htidx)
}
/* Create a new hash table */
dict *dictCreate(dictType *type) {
size_t metasize = type->dictMetadataBytes ? type->dictMetadataBytes(NULL)
: 0;
dict *d = zmalloc(sizeof(*d) + metasize);
dict *dictCreate(dictType *type)
{
size_t metasize = type->dictMetadataBytes ? type->dictMetadataBytes(NULL) : 0;
dict *d = zmalloc(sizeof(*d)+metasize);
if (metasize > 0) {
memset(dictMetadata(d), 0, metasize);
}
_dictInit(d, type);
_dictInit(d,type);
return d;
}
@ -318,7 +318,7 @@ static void rehashEntriesInBucketAtIndex(dict *d, uint64_t idx) {
void *key = dictGetKey(de);
/* Get the index in the new hash table */
if (d->ht_size_exp[1] > d->ht_size_exp[0]) {
h = dictHashKey(d, key, 1) & DICTHT_SIZE_MASK(d->ht_size_exp[1]);
h = dictHashKey(d, key, 1) & DICTHT_SIZE_MASK(d->ht_size_exp[1]);
} else {
/* We're shrinking the table. The tables sizes are powers of
* two, so we simply mask the bucket index in the larger table

View File

@ -157,7 +157,7 @@ static inline void activeExpireHashFieldCycle(int type) {
redisDb *db = server.db + currentDb;
/* If db is empty, move to next db and return */
if(ebIsEmpty(db->hexpires)) {
if (ebIsEmpty(db->hexpires)) {
activeExpirySequence = 0;
currentDb = (currentDb + 1) % server.dbnum;
return;
@ -165,7 +165,7 @@ static inline void activeExpireHashFieldCycle(int type) {
/* If running for a while and didn't manage to active-expire all expired fields of
* currentDb (i.e. activeExpirySequence becomes significant) then adjust maxToExpire */
if ((activeExpirySequence > EXPIRED_FIELDS_TH) && (type == ACTIVE_EXPIRE_CYCLE_SLOW) ) {
if ((activeExpirySequence > EXPIRED_FIELDS_TH) && (type == ACTIVE_EXPIRE_CYCLE_SLOW)) {
/* maxToExpire is multiplied by a factor between 1 and 32, proportional to
* the number of times activeExpirySequence exceeded EXPIRED_FIELDS_TH */
uint64_t factor = activeExpirySequence / EXPIRED_FIELDS_TH;

View File

@ -951,62 +951,6 @@ int64_t hashTypeGetMinExpire(robj *o) {
return ebGetMetaExpTime(expireMeta);
}
/* Delete all expired fields in a hash */
void hashTypeDeleteExpiredFields(client *c, robj *hashObj) {
redisDb *db = c->db;
if (hashObj->encoding == OBJ_ENCODING_LISTPACK) {
return; /* TODO */
}
serverAssert(hashObj->encoding == OBJ_ENCODING_HT);
dict *d = hashObj->ptr;
if (!isDictWithMetaHFE(d))
return;
dictExpireMetadata *dictExpireMeta = (dictExpireMetadata *) dictMetadata(d);
/* If HFE metadata is marked as trash, return */
if (dictExpireMeta->expireMeta.trash)
return;
/* If time of next hash-field to expire is greater than current time, return */
if (ebGetExpireTime(&hashExpireBucketsType, hashObj) >= (uint64_t)commandTimeSnapshot() )
return;
/* Remove expired fields as part of lazy-expire */
ExpireInfo info = {
.maxToExpire = UINT64_MAX,
.onExpireItem = onFieldExpire,
.ctx = hashObj,
.now = commandTimeSnapshot(),
.itemsExpired = 0};
ebExpire(&dictExpireMeta->hfe, &hashFieldExpireBucketsType, &info);
/* If hash has no more fields to expire, remove it from HFE DB */
if (info.nextExpireTime == 0) {
/* Take care to remove hash from global HFE DS before deleting it */
ebRemove(&c->db->hexpires, &hashExpireBucketsType, hashObj);
if (hashTypeLength(hashObj, 0) == 0) {
robj *key = createStringObject(dictExpireMeta->key, sdslen(dictExpireMeta->key));
dbDelete(db, key);
//notifyKeyspaceEvent(NOTIFY_HASH,"xxxxxxxxx",c->argv[1],c->db->id);
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key, db->id);
server.dirty++;
signalModifiedKey(NULL, &server.db[0], key);
decrRefCount(key);
}
} else {
/* Update hash expiry based on next time of hash-field to expire in "global" HFE */
ebRemove(&c->db->hexpires, &hashExpireBucketsType, hashObj);
ebAdd(&c->db->hexpires, &hashExpireBucketsType, hashObj, info.nextExpireTime);
}
}
uint64_t hashTypeRemoveFromExpires(ebuckets *hexpires, robj *o) {
if (o->encoding == OBJ_ENCODING_LISTPACK)
return EB_EXPIRE_TIME_INVALID; /* not supported yet */

View File

@ -169,7 +169,7 @@ proc test_scan {type} {
# make sure that passive expiration is triggered by the scan
r debug set-active-expire 0
populate 1000
populate 1000
r set foo bar
r pexpire foo 1