feat(server): add oom guard (#1650)

1. add flag maxmemory_ratio
2. When current used memory * maxmemory_ratio > maxmemory_limit denyoom
   commands will return oom error.

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-08-08 23:26:35 +03:00 committed by GitHub
parent 7c99d2d111
commit 116934b008
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 4 deletions

View file

@ -71,6 +71,15 @@ void ServerState::Destroy() {
state_ = nullptr;
}
uint64_t ServerState::GetUsedMemory(uint64_t now_ns) {
static constexpr uint64_t kCacheEveryNs = 1000;
if (now_ns > used_mem_last_update_ + kCacheEveryNs) {
used_mem_last_update_ = now_ns;
used_mem_cached_ = used_mem_current.load(std::memory_order_relaxed);
}
return used_mem_cached_;
}
bool ServerState::AllowInlineScheduling() const {
// We can't allow inline scheduling during a full sync, because then journaling transactions
// will be scheduled before RdbLoader::LoadItemsBuffer is finished. We can't use the regular