Add Statistics hashes_with_expiry_fields to INFO (#13275)

Added hashes_with_expiry_fields.
Optimially it would better to have statistic of that counts all fields
with expiry. But it requires careful logic and computation to follow and
deep dive listpacks and hashes. This statistics is trivial to achieve
and reflected by global HFE DS that has builtin enumeration of all the
hashes that are registered in it.
This commit is contained in:
Moti Cohen 2024-05-23 17:29:45 +03:00 committed by GitHub
parent ae6df30eb1
commit f34f2ade85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 3 deletions

View File

@ -6106,14 +6106,16 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) {
if (sections++) info = sdscat(info,"\r\n");
info = sdscatprintf(info, "# Keyspace\r\n");
for (j = 0; j < server.dbnum; j++) {
long long keys, vkeys;
long long keys, vkeys, hexpires;
keys = kvstoreSize(server.db[j].keys);
vkeys = kvstoreSize(server.db[j].expires);
hexpires = ebGetTotalItems(server.db[j].hexpires, &hashExpireBucketsType);
if (keys || vkeys) {
info = sdscatprintf(info,
"db%d:keys=%lld,expires=%lld,avg_ttl=%lld\r\n",
j, keys, vkeys, server.db[j].avg_ttl);
"db%d:keys=%lld,expires=%lld,avg_ttl=%lld,hashes_with_expiry_fields=%lld\r\n",
j, keys, vkeys, server.db[j].avg_ttl, hexpires);
}
}
}

View File

@ -24,6 +24,19 @@ set S_FIELD_AND_TTL 3
############################### AUX FUNCS ######################################
proc get_hashes_with_expiry_fields {r} {
set input_string [r info keyspace]
set hash_count 0
foreach line [split $input_string \n] {
if {[regexp {hashes_with_expiry_fields=(\d+)} $line -> value]} {
return $value
}
}
return 0
}
proc create_hash {key entries} {
r del $key
foreach entry $entries {
@ -1260,4 +1273,23 @@ start_server {tags {"external:skip needs:debug"}} {
r config set hash-max-listpack-value 64
}
test "Statistics - Hashes with HFEs" {
r config resetstat
r del myhash
r hset myhash f1 v1 f2 v2 f3 v3 f4 v4 f5 v5
r hpexpire myhash 100 1 f1 f2 f3
assert_match [get_hashes_with_expiry_fields r] 1
r hset myhash2 f1 v1 f2 v2 f3 v3 f4 v4 f5 v5
assert_match [get_hashes_with_expiry_fields r] 1
r hpexpire myhash2 100 1 f1 f2 f3
assert_match [get_hashes_with_expiry_fields r] 2
wait_for_condition 50 50 {
[get_hashes_with_expiry_fields r] == 0
} else {
fail "Hash field expiry statistics failed"
}
}
}