diff options
author | antirez <antirez@gmail.com> | 2018-12-12 11:37:15 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-12-12 11:37:15 +0100 |
commit | 129f2d2746ca80451d8c84b223b568298020b125 (patch) | |
tree | 67da53dc97f62e68488cb3ea4783bb77d990bdab | |
parent | 7ae184bfea90cf3e146ac06af0cc5c04d7628a22 (diff) | |
download | redis-129f2d2746ca80451d8c84b223b568298020b125.tar.gz |
freeMemoryIfNeeded() small refactoring.
Related to issue #5686 and PR #5689.
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/evict.c | 21 | ||||
-rw-r--r-- | src/server.c | 2 | ||||
-rw-r--r-- | src/server.h | 1 |
4 files changed, 16 insertions, 10 deletions
diff --git a/src/config.c b/src/config.c index 8a2690a0c..9f51bba85 100644 --- a/src/config.c +++ b/src/config.c @@ -1248,7 +1248,7 @@ void configSetCommand(client *c) { if (server.maxmemory < zmalloc_used_memory()) { serverLog(LL_WARNING,"WARNING: the new maxmemory value set via CONFIG SET is smaller than the current memory usage. This will result in key eviction and/or the inability to accept new write commands depending on the maxmemory-policy."); } - freeMemoryIfNeeded(); + freeMemoryIfNeededAndSafe(); } } config_set_memory_field( "proto-max-bulk-len",server.proto_max_bulk_len) { 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(); +} diff --git a/src/server.c b/src/server.c index 28a794551..9371b2bac 100644 --- a/src/server.c +++ b/src/server.c @@ -2613,7 +2613,7 @@ int processCommand(client *c) { * condition, to avoid mixing the propagation of scripts with the * propagation of DELs due to eviction. */ if (server.maxmemory && !server.lua_timedout) { - int out_of_memory = freeMemoryIfNeeded() == C_ERR; + int out_of_memory = freeMemoryIfNeededAndSafe() == C_ERR; /* freeMemoryIfNeeded may flush slave output buffers. This may result * into a slave, that may be the active client, to be freed. */ if (server.current_client == NULL) return C_ERR; diff --git a/src/server.h b/src/server.h index a87fd9759..da4c6d45a 100644 --- a/src/server.h +++ b/src/server.h @@ -1702,6 +1702,7 @@ int zslLexValueLteMax(sds value, zlexrangespec *spec); int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level); size_t freeMemoryGetNotCountedMemory(); int freeMemoryIfNeeded(void); +int freeMemoryIfNeededAndSafe(void); int processCommand(client *c); void setupSignalHandlers(void); struct redisCommand *lookupCommand(sds name); |