From 067647a78315cfa81bf489128afd6f4ae1388603 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 27 Aug 2018 12:09:08 +0200 Subject: [PATCH] Introduce repl_slave_ignore_maxmemory flag internally. Note: this breaks backward compatibility with Redis 4, since now slaves by default are exact copies of masters and do not try to evict keys independently. --- src/evict.c | 4 ++++ src/server.c | 1 + src/server.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/evict.c b/src/evict.c index ecc25dd8..cdb49a55 100644 --- a/src/evict.c +++ b/src/evict.c @@ -444,6 +444,10 @@ 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; + size_t mem_reported, mem_tofree, mem_freed; mstime_t latency, eviction_latency; long long delta; diff --git a/src/server.c b/src/server.c index aeb30cdf..4aa36c28 100644 --- a/src/server.c +++ b/src/server.c @@ -1649,6 +1649,7 @@ void initServerConfig(void) { server.repl_syncio_timeout = CONFIG_REPL_SYNCIO_TIMEOUT; server.repl_serve_stale_data = CONFIG_DEFAULT_SLAVE_SERVE_STALE_DATA; server.repl_slave_ro = CONFIG_DEFAULT_SLAVE_READ_ONLY; + server.repl_slave_ignore_maxmemory = CONFIG_DEFAULT_SLAVE_IGNORE_MAXMEMORY; server.repl_slave_lazy_flush = CONFIG_DEFAULT_SLAVE_LAZY_FLUSH; server.repl_down_since = 0; /* Never connected, repl is down since EVER. */ server.repl_disable_tcp_nodelay = CONFIG_DEFAULT_REPL_DISABLE_TCP_NODELAY; diff --git a/src/server.h b/src/server.h index 2e1f7c9c..4fb8e383 100644 --- a/src/server.h +++ b/src/server.h @@ -131,6 +131,7 @@ typedef long long mstime_t; /* millisecond time type. */ #define CONFIG_DEFAULT_REPL_DISKLESS_SYNC_DELAY 5 #define CONFIG_DEFAULT_SLAVE_SERVE_STALE_DATA 1 #define CONFIG_DEFAULT_SLAVE_READ_ONLY 1 +#define CONFIG_DEFAULT_SLAVE_IGNORE_MAXMEMORY 1 #define CONFIG_DEFAULT_SLAVE_ANNOUNCE_IP NULL #define CONFIG_DEFAULT_SLAVE_ANNOUNCE_PORT 0 #define CONFIG_DEFAULT_REPL_DISABLE_TCP_NODELAY 0 @@ -1157,6 +1158,7 @@ struct redisServer { time_t repl_transfer_lastio; /* Unix time of the latest read, for timeout */ int repl_serve_stale_data; /* Serve stale data when link is down? */ int repl_slave_ro; /* Slave is read only? */ + int repl_slave_ignore_maxmemory; /* If true slaves do not evict. */ time_t repl_down_since; /* Unix time at which link with master went down */ int repl_disable_tcp_nodelay; /* Disable TCP_NODELAY after SYNC? */ int slave_priority; /* Reported in INFO and used by Sentinel. */