summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2018-12-12 00:25:24 +0800
committerzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2018-12-12 00:25:58 +0800
commitb9cd89d1089a488b82517ad8f7899dde10cf7c25 (patch)
treebffb53948a39317036fd9bed15ece0b9e8c6d98e
parent0110e46f6ea654d1d8ef985cf317243f58f5ac70 (diff)
downloadredis-b9cd89d1089a488b82517ad8f7899dde10cf7c25.tar.gz
evict: don't care about mem if loading
When loading data, we call processEventsWhileBlocked to process events and execute commands. But if we are loading AOF it's dangerous, because processCommand would call freeMemoryIfNeeded to evict, and that will break data consistency, see issue #5686.
-rw-r--r--src/evict.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/evict.c b/src/evict.c
index 39deb65a6..980a91f79 100644
--- a/src/evict.c
+++ b/src/evict.c
@@ -444,9 +444,15 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
* Otehrwise if we are over the memory limit, but not enough memory
* was freed to return back under the limit, the function returns C_ERR. */
int freeMemoryIfNeeded(void) {
- /* By default slaves should ignore maxmemory and just be masters excat
- * copies. */
- if (server.masterhost && server.repl_slave_ignore_maxmemory) return C_OK;
+ /* 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;
+ }
size_t mem_reported, mem_tofree, mem_freed;
mstime_t latency, eviction_latency;