Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement repl_auto_resync against 2.6 #853

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.*.swp
*~
*.o
*.rdb
*.log
Expand Down
5 changes: 5 additions & 0 deletions redis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down