1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

feat: add oom insertion rejections (#1096)

This commit is contained in:
Roman Gershman 2023-04-16 00:23:09 -07:00 committed by GitHub
parent b345604226
commit 74e94ef9bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

@ -208,7 +208,7 @@ DbStats& DbStats::operator+=(const DbStats& o) {
}
SliceEvents& SliceEvents::operator+=(const SliceEvents& o) {
static_assert(sizeof(SliceEvents) == 72, "You should update this function with new fields");
static_assert(sizeof(SliceEvents) == 80, "You should update this function with new fields");
ADD(evicted_keys);
ADD(hard_evictions);
@ -219,6 +219,7 @@ SliceEvents& SliceEvents::operator+=(const SliceEvents& o) {
ADD(garbage_checked);
ADD(hits);
ADD(misses);
ADD(insertion_rejections);
return *this;
}
@ -372,6 +373,8 @@ tuple<PrimeIterator, ExpireIterator, bool> DbSlice::AddOrFind2(const Context& cn
// If we are over limit in non-cache scenario, just be conservative and throw.
if (!caching_mode_ && evp.mem_budget() < 0) {
VLOG(1) << "AddOrFind2: over limit, budget: " << evp.mem_budget();
events_.insertion_rejections++;
throw bad_alloc();
}
@ -385,6 +388,9 @@ tuple<PrimeIterator, ExpireIterator, bool> DbSlice::AddOrFind2(const Context& cn
try {
tie(it, inserted) = db.prime.Insert(std::move(co_key), PrimeValue{}, evp);
} catch (bad_alloc& e) {
VLOG(1) << "AddOrFind2: bad alloc exception, budget: " << evp.mem_budget();
events_.insertion_rejections++;
throw e;
}

View file

@ -50,6 +50,9 @@ struct SliceEvents {
size_t hits = 0;
size_t misses = 0;
// how many insertions were rejected due to OOM.
size_t insertion_rejections = 0;
SliceEvents& operator+=(const SliceEvents& o);
};

View file

@ -1556,6 +1556,7 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
append("garbage_collected", m.events.garbage_collected);
append("bump_ups", m.events.bumpups);
append("stash_unloaded", m.events.stash_unloaded);
append("oom_rejections", m.events.insertion_rejections);
append("traverse_ttl_sec", m.traverse_ttl_per_sec);
append("delete_ttl_sec", m.delete_ttl_per_sec);
append("keyspace_hits", m.events.hits);