summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2023-04-04 14:05:52 +0800
committerGitHub <noreply@github.com>2023-04-04 09:05:52 +0300
commitaee8d1ff28a5939d28e13cf9ff92845bc965aba7 (patch)
tree8efe9574cd7b4f7e48f235bb966b70336472260c /src
parenta4a0eab52b351b5f152071dda2a993d90f99d64b (diff)
downloadredis-aee8d1ff28a5939d28e13cf9ff92845bc965aba7.tar.gz
Changed activeExpireCycle server.masterhost check to iAmMaster in beforeSleep (#11997)
In cluster mode, when a node restart as a replica, it doesn't immediately sync with the master, replication is enabled in clusterCron. It means that sometime server.masterhost is NULL and we wrongly judge it in beforeSleep. In this case, we may trigger a fast activeExpireCycle in beforeSleep, but the node's flag is actually a replica, that can lead to data inconsistency. In this PR, we use iAmMaster to replace the `server.masterhost == NULL` This is an overlook in #7001, and more discussion in #11783.
Diffstat (limited to 'src')
-rw-r--r--src/server.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/server.c b/src/server.c
index 951dd387c..059e4c702 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1658,7 +1658,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
/* Run a fast expire cycle (the called function will return
* ASAP if a fast cycle is not needed). */
- if (server.active_expire_enabled && server.masterhost == NULL)
+ if (server.active_expire_enabled && iAmMaster())
activeExpireCycle(ACTIVE_EXPIRE_CYCLE_FAST);
/* Unblock all the clients blocked for synchronous replication