summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-05-15 16:33:13 +0200
committerantirez <antirez@gmail.com>2014-05-20 17:45:50 +0200
commit41a72416039acd775f5dde5656460e2c02498124 (patch)
tree50843c554373bc9edb1b15bd637356dd8ab99a5f
parent5685d15af1d151f9dbe9189c63304cdade1e9fbd (diff)
downloadredis-41a72416039acd775f5dde5656460e2c02498124.tar.gz
Cluster: clear todo_before_sleep flags when executing actions.
Thanks to this change, when there is some code like: clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE|...); ... and later before returning to the event loop ... clusterUpdateState(); The clusterUpdateState() function will clar the flag and will not be repeated in the clusterBeforeSleep() function. This especially important for config save/fsync flags which are slow to execute and not a good idea to repeat without a good reason. This is implemented for all the CLUSTER_TODO flags.
-rw-r--r--src/cluster.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 4b13d36bc..3199f0de7 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -306,6 +306,8 @@ int clusterSaveConfig(int do_fsync) {
struct stat sb;
int fd;
+ server.cluster->todo_before_sleep &= ~CLUSTER_TODO_SAVE_CONFIG;
+
/* Get the nodes description and concatenate our "vars" directive to
* save currentEpoch and lastVoteEpoch. */
ci = clusterGenNodesDescription(REDIS_NODE_HANDSHAKE);
@@ -325,7 +327,10 @@ int clusterSaveConfig(int do_fsync) {
}
}
if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err;
- if (do_fsync) fsync(fd);
+ if (do_fsync) {
+ server.cluster->todo_before_sleep &= ~CLUSTER_TODO_FSYNC_CONFIG;
+ fsync(fd);
+ }
/* Truncate the file if needed to remove the final \n padding that
* is just garbage. */
@@ -2367,6 +2372,8 @@ void clusterHandleSlaveFailover(void) {
int j;
mstime_t auth_timeout, auth_retry_time;
+ server.cluster->todo_before_sleep &= ~CLUSTER_TODO_HANDLE_FAILOVER;
+
/* Compute the failover timeout (the max time we have to send votes
* and wait for replies), and the failover retry time (the time to wait
* before waiting again.
@@ -2944,7 +2951,8 @@ void clusterBeforeSleep(void) {
clusterSaveConfigOrDie(fsync);
}
- /* Reset our flags. */
+ /* Reset our flags (not strictly needed since every single function
+ * called for flags set should be able to clear its flag). */
server.cluster->todo_before_sleep = 0;
}
@@ -3061,6 +3069,8 @@ void clusterUpdateState(void) {
static mstime_t among_minority_time;
static mstime_t first_call_time = 0;
+ server.cluster->todo_before_sleep &= ~CLUSTER_TODO_UPDATE_STATE;
+
/* If this is a master node, wait some time before turning the state
* into OK, since it is not a good idea to rejoin the cluster as a writable
* master, after a reboot, without giving the cluster a chance to