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

@ -412,6 +412,10 @@ class DbSlice {
return version_;
}
size_t table_memory() const {
return table_memory_;
}
using ChangeCallback = std::function<void(DbIndex, const ChangeReq&)>;
//! Registers the callback to be called for each change.
@ -575,6 +579,7 @@ class DbSlice {
ssize_t memory_budget_ = SSIZE_MAX;
size_t bytes_per_object_ = 0;
size_t soft_budget_limit_ = 0;
size_t table_memory_ = 0;
mutable SliceEvents events_; // we may change this even for const operations.