diff options
author | antirez <antirez@gmail.com> | 2018-02-27 10:25:08 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-02-27 10:33:43 +0100 |
commit | 2b974404c0c9c92963c69be06cdd3411445931c6 (patch) | |
tree | b32e75db761878c265bca0b546927f5a4745f0a4 | |
parent | 2500e124e94c257708b53ce00a37e67bd02f81d8 (diff) | |
download | redis-2b974404c0c9c92963c69be06cdd3411445931c6.tar.gz |
Cluster: improve crash-recovery safety after failover auth vote.
Add AE_BARRIER to the writable event loop so that slaves requesting
votes can't be served before we re-enter the event loop in the next
iteration, so clusterBeforeSleep() will fsync to disk in time.
Also add the call to explicitly fsync, given that we modified the last
vote epoch variable.
-rw-r--r-- | src/cluster.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cluster.c b/src/cluster.c index 00fa5d4a2..ee5b67667 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2156,7 +2156,7 @@ void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) { * from event handlers that will do stuff with the same link later. */ void clusterSendMessage(clusterLink *link, unsigned char *msg, size_t msglen) { if (sdslen(link->sndbuf) == 0 && msglen != 0) - aeCreateFileEvent(server.el,link->fd,AE_WRITABLE, + aeCreateFileEvent(server.el,link->fd,AE_WRITABLE|AE_BARRIER, clusterWriteHandler,link); link->sndbuf = sdscatlen(link->sndbuf, msg, msglen); @@ -2691,9 +2691,10 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { } /* We can vote for this slave. */ - clusterSendFailoverAuth(node); server.cluster->lastVoteEpoch = server.cluster->currentEpoch; node->slaveof->voted_time = mstime(); + clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|CLUSTER_TODO_FSYNC_CONFIG); + clusterSendFailoverAuth(node); serverLog(LL_WARNING, "Failover auth granted to %.40s for epoch %llu", node->name, (unsigned long long) server.cluster->currentEpoch); } |