Skip to content

Commit

Permalink
Discard removeKeysizesHist(), addKeysizesHist()
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Oct 29, 2024
1 parent 25c393e commit b206687
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 46 deletions.
41 changes: 6 additions & 35 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,6 @@ void updateKeysizesHist(redisDb *db, int didx, uint32_t type, uint64_t oldLen, u
}
}

/* Remove key statistic from keysizes histogram */
void removeKeysizesHist(redisDb *db, int didx, robj *val) {
uint64_t len;
switch (val->type)
{
case OBJ_STRING: len = stringObjectLen(val); break;
case OBJ_LIST: len = listTypeLength(val); break;
case OBJ_HASH: len = hashTypeLength(val, 0); break;
case OBJ_SET: len = setTypeSize(val); break;
case OBJ_ZSET: len = zsetLength(val); break;
default: return;
}
updateKeysizesHist(db, didx, val->type, len, 0);
}

/* Add key statistic to keysizes histogram */
void addKeysizesHist(redisDb *db, int didx, robj *val) {
uint64_t len;
switch (val->type)
{
case OBJ_STRING: len = stringObjectLen(val); break;
case OBJ_LIST: len = listTypeLength(val); break;
case OBJ_HASH: len = hashTypeLength(val, 0); break;
case OBJ_SET: len = setTypeSize(val); break;
case OBJ_ZSET: len = zsetLength(val); break;
default: return;
}
updateKeysizesHist(db, didx, val->type, 0, len);
}

/* Lookup a key for read or write operations, or return NULL if the key is not
* found in the specified DB. This function implements the functionality of
* lookupKeyRead(), lookupKeyWrite() and their ...WithFlags() variants.
Expand Down Expand Up @@ -278,7 +248,7 @@ static dictEntry *dbAddInternal(redisDb *db, robj *key, robj *val, int update_if
kvstoreDictSetVal(db->keys, slot, de, val);
signalKeyAsReady(db, key, val->type);
notifyKeyspaceEvent(NOTIFY_NEW,"new",key,db->id);
addKeysizesHist(db, slot, val);
updateKeysizesHist(db, slot, val->type, 0, getObjectLength(val)); /* add hist */
return de;
}

Expand Down Expand Up @@ -324,7 +294,7 @@ int dbAddRDBLoad(redisDb *db, sds key, robj *val) {
int slot = getKeySlot(key);
dictEntry *de = kvstoreDictAddRaw(db->keys, slot, key, NULL);
if (de == NULL) return 0;
addKeysizesHist(db, slot, val);
updateKeysizesHist(db, slot, val->type, 0, getObjectLength(val)); /* add hist */
initObjectLRUOrLFU(val);
kvstoreDictSetVal(db->keys, slot, de, val);
return 1;
Expand All @@ -349,7 +319,7 @@ static void dbSetValue(redisDb *db, robj *key, robj *val, int overwrite, dictEnt
robj *old = dictGetVal(de);

/* Remove old key from keysizes histogram */
removeKeysizesHist(db, slot, old);
updateKeysizesHist(db, slot, old->type, getObjectLength(old), 0); /* remove hist */

val->lru = old->lru;

Expand All @@ -370,7 +340,7 @@ static void dbSetValue(redisDb *db, robj *key, robj *val, int overwrite, dictEnt
kvstoreDictSetVal(db->keys, slot, de, val);

/* Add new key to keysizes histogram */
addKeysizesHist(db, slot, val);
updateKeysizesHist(db, slot, val->type, 0, getObjectLength(val));

/* if hash with HFEs, take care to remove from global HFE DS */
if (old->type == OBJ_HASH)
Expand Down Expand Up @@ -486,7 +456,8 @@ int dbGenericDelete(redisDb *db, robj *key, int async, int flags) {
if (de) {
robj *val = dictGetVal(de);

removeKeysizesHist(db, slot, val);
/* remove key from histogram */
updateKeysizesHist(db, slot, val->type, getObjectLength(val), 0);

/* If hash object with expiry on fields, remove it from HFE DS of DB */
if (val->type == OBJ_HASH)
Expand Down
10 changes: 1 addition & 9 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4171,15 +4171,7 @@ int RM_KeyType(RedisModuleKey *key) {
* If the key pointer is NULL or the key is empty, zero is returned. */
size_t RM_ValueLength(RedisModuleKey *key) {
if (key == NULL || key->value == NULL) return 0;
switch(key->value->type) {
case OBJ_STRING: return stringObjectLen(key->value);
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, 0); /* OPEN: To subtract expired fields? */
case OBJ_STREAM: return streamLength(key->value);
default: return 0;
}
return getObjectLength(key->value);
}

/* If the key is open for writing, remove it, and setup the key to
Expand Down
12 changes: 12 additions & 0 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,18 @@ robj *tryObjectEncoding(robj *o) {
return tryObjectEncodingEx(o, 1);
}

size_t getObjectLength(robj *o) {
switch(o->type) {
case OBJ_STRING: return stringObjectLen(o);
case OBJ_LIST: return listTypeLength(o);
case OBJ_SET: return setTypeSize(o);
case OBJ_ZSET: return zsetLength(o);
case OBJ_HASH: return hashTypeLength(o, 0);
case OBJ_STREAM: return streamLength(o);
default: return 0;
}
}

/* Get a decoded version of an encoded object (returned as a new object).
* If the object is already raw-encoded just increment the ref count. */
robj *getDecodedObject(robj *o) {
Expand Down
3 changes: 1 addition & 2 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,7 @@ int isSdsRepresentableAsLongLong(sds s, long long *llval);
int isObjectRepresentableAsLongLong(robj *o, long long *llongval);
robj *tryObjectEncoding(robj *o);
robj *tryObjectEncodingEx(robj *o, int try_trim);
size_t getObjectLength(robj *o);
robj *getDecodedObject(robj *o);
size_t stringObjectLen(robj *o);
robj *createStringObjectFromLongLong(long long value);
Expand Down Expand Up @@ -3361,8 +3362,6 @@ int setModuleNumericConfig(ModuleConfig *config, long long val, const char **err

/* db.c -- Keyspace access API */
void updateKeysizesHist(redisDb *db, int didx, uint32_t type, uint64_t oldLen, uint64_t newLen);
void removeKeysizesHist(redisDb *db, int didx, robj *val);
void addKeysizesHist(redisDb *db, int didx, robj *val);
int removeExpire(redisDb *db, robj *key);
void deleteExpiredKeyAndPropagate(redisDb *db, robj *keyobj);
void propagateDeletion(redisDb *db, robj *key, int lazy);
Expand Down

0 comments on commit b206687

Please sign in to comment.