summaryrefslogtreecommitdiff
path: root/src/evict.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-12-12 11:37:15 +0100
committerantirez <antirez@gmail.com>2018-12-12 11:37:15 +0100
commit129f2d2746ca80451d8c84b223b568298020b125 (patch)
tree67da53dc97f62e68488cb3ea4783bb77d990bdab /src/evict.c
parent7ae184bfea90cf3e146ac06af0cc5c04d7628a22 (diff)
downloadredis-129f2d2746ca80451d8c84b223b568298020b125.tar.gz
freeMemoryIfNeeded() small refactoring.
Related to issue #5686 and PR #5689.
Diffstat (limited to 'src/evict.c')
-rw-r--r--src/evict.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/evict.c b/src/evict.c
index 980a91f79..773916ce8 100644
--- a/src/evict.c
+++ b/src/evict.c
@@ -445,14 +445,8 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
* was freed to return back under the limit, the function returns C_ERR. */
int freeMemoryIfNeeded(void) {
/* By default replicas should ignore maxmemory
- * and just be masters exact copies.
- *
- * And don't care about mem if loading. */
- if (server.loading ||
- (server.masterhost && server.repl_slave_ignore_maxmemory))
- {
- return C_OK;
- }
+ * and just be masters exact copies. */
+ if (server.masterhost && server.repl_slave_ignore_maxmemory) return C_OK;
size_t mem_reported, mem_tofree, mem_freed;
mstime_t latency, eviction_latency;
@@ -628,3 +622,14 @@ cant_free:
return C_ERR;
}
+/* This is a wrapper for freeMemoryIfNeeded() that only really calls the
+ * function if right now there are the conditions to do so safely:
+ *
+ * - There must be no script in timeout condition.
+ * - Nor we are loading data right now.
+ *
+ */
+int freeMemoryIfNeededAndSafe(void) {
+ if (server.lua_timedout || server.loading) return C_OK;
+ return freeMemoryIfNeeded();
+}