From 87fc0184154eaa8a0bd8426f3fbddd33c71dea04 Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 19 Feb 2021 05:17:41 +0000 Subject: [PATCH] Implement maxstorage config Former-commit-id: 79e07859dfec14edf2a39646013e1a82db033d4f --- src/config.cpp | 1 + src/evict.cpp | 5 +++++ src/server.h | 1 + 3 files changed, 7 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index a5efb2f10..ca9181788 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2619,6 +2619,7 @@ standardConfig configs[] = { /* Unsigned Long Long configs */ createULongLongConfig("maxmemory", NULL, MODIFIABLE_CONFIG, 0, LLONG_MAX, g_pserver->maxmemory, 0, MEMORY_CONFIG, NULL, updateMaxmemory), + createULongLongConfig("maxstorage", NULL, MODIFIABLE_CONFIG, 0, LLONG_MAX, g_pserver->maxstorage, 0, MEMORY_CONFIG, NULL, NULL), /* Size_t configs */ createSizeTConfig("hash-max-ziplist-entries", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, g_pserver->hash_max_ziplist_entries, 512, INTEGER_CONFIG, NULL, NULL), diff --git a/src/evict.cpp b/src/evict.cpp index d4b0c1f12..31cadeae5 100644 --- a/src/evict.cpp +++ b/src/evict.cpp @@ -500,6 +500,9 @@ int freeMemoryIfNeeded(bool fQuickCycle, bool fPreSnapshot) { int ckeysFailed = 0; int keys_freed = 0; + if (g_pserver->maxstorage && g_pserver->m_pstorageFactory != nullptr && g_pserver->m_pstorageFactory->totalDiskspaceUsed() >= g_pserver->maxstorage) + goto cant_free_storage; + /* When clients are paused the dataset should be static not just from the * POV of clients not being able to write, but also from the POV of * expires and evictions of keys not being performed. */ @@ -726,8 +729,10 @@ cant_free: latencyEndMonitor(lazyfree_latency); latencyAddSampleIfNeeded("eviction-lazyfree",lazyfree_latency); } + latencyEndMonitor(latency); latencyAddSampleIfNeeded("eviction-cycle",latency); +cant_free_storage: return result; } diff --git a/src/server.h b/src/server.h index 941770450..6fa6807c7 100644 --- a/src/server.h +++ b/src/server.h @@ -2230,6 +2230,7 @@ struct redisServer { /* Limits */ unsigned int maxclients; /* Max number of simultaneous clients */ unsigned long long maxmemory; /* Max number of memory bytes to use */ + unsigned long long maxstorage; /* Max number of bytes to use in a storage provider */ int maxmemory_policy; /* Policy for key eviction */ int maxmemory_samples; /* Precision of random sampling */ int lfu_log_factor; /* LFU logarithmic counter factor. */