chore: Track db_slice table memory instantly (#3375)

We update table_memory upon each deletion and insertion of an element.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-07-24 14:13:08 +03:00 committed by GitHub
parent f73c7d0e42
commit 03b3f86aed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 7 deletions

View file

@ -715,9 +715,10 @@ void EngineShard::CacheStats() {
DbTable* table = db_slice.GetDBTable(i);
if (table) {
entries += table->prime.size();
table_memory += (table->prime.mem_usage() + table->expire.mem_usage());
table_memory += table->table_memory();
}
}
DCHECK_EQ(table_memory, db_slice.table_memory());
size_t obj_memory = table_memory <= used_mem ? used_mem - table_memory : 0;
size_t bytes_per_obj = entries > 0 ? obj_memory / entries : 0;