Skip to content

implement repl_auto_resync against 2.6 #853

Open
wants to merge 1 commit into from
View
1 .gitignore
@@ -1,4 +1,5 @@
.*.swp
+*~
*.o
*.rdb
*.log
View
5 redis.conf
@@ -196,6 +196,11 @@ slave-read-only yes
#
# repl-timeout 60
+# The following option controls whether a redis slave will automatically
+# try to resync with the master if contact is lost. The default is 'yes'
+#
+# repl-auto-resync no
+
# The slave priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a slave to promote into a
# master if the master is no longer working correctly.
View
8 src/config.c
@@ -230,7 +230,13 @@ void loadServerConfigFromString(char *config) {
err = "repl-timeout must be 1 or greater";
goto loaderr;
}
- } else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
+ } else if (!strcasecmp(argv[0],"repl-auto-resync") && argc == 2) {
+ server.repl_auto_resync = yesnotoi(argv[1]);
+ if (server.repl_auto_resync == -1) {
+ err = "repl-auto-resync must be 'yes' or 'no'";
+ goto loaderr;
+ }
+ } else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
server.masterauth = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"slave-serve-stale-data") && argc == 2) {
if ((server.repl_serve_stale_data = yesnotoi(argv[1])) == -1) {
View
6 src/networking.c
@@ -647,7 +647,11 @@ void freeClient(redisClient *c) {
/* Case 2: we lost the connection with the master. */
if (c->flags & REDIS_MASTER) {
server.master = NULL;
- server.repl_state = REDIS_REPL_CONNECT;
+ if (server.repl_auto_resync) {
+ server.repl_state = REDIS_REPL_CONNECT;
+ } else {
+ server.repl_state = REDIS_REPL_NONE;
+ }
server.repl_down_since = server.unixtime;
/* We lost connection with our master, force our slaves to resync
* with us as well to load the new data set.
View
1 src/redis.c
@@ -1154,6 +1154,7 @@ void initServerConfig() {
server.masterhost = NULL;
server.masterport = 6379;
server.master = NULL;
+ server.repl_auto_resync = 1;
server.repl_state = REDIS_REPL_NONE;
server.repl_syncio_timeout = REDIS_REPL_SYNCIO_TIMEOUT;
server.repl_serve_stale_data = 1;
View
1 src/redis.h
@@ -602,6 +602,7 @@ struct redisServer {
int masterport; /* Port of master */
int repl_ping_slave_period; /* Master pings the slave every N seconds */
int repl_timeout; /* Timeout after N seconds of master idle */
+ int repl_auto_resync; /* Automatically reconnect to master? */
redisClient *master; /* Client that is master for this slave */
int repl_syncio_timeout; /* Timeout for synchronous I/O calls */
int repl_state; /* Replication status if the instance is a slave */
Something went wrong with that request. Please try again.