Skip to content

Commit

Permalink
Add Statistics hashes_with_expiry_fields to INFO (#13275)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
moticless committed May 23, 2024
1 parent ae6df30 commit f34f2ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/type/hash-field-expire.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
}
}

0 comments on commit f34f2ad

Please sign in to comment.