server.masterhost = NULL;
server.masterport = 6379;
server.master = NULL;
- server.replstate = REDIS_REPL_NONE;
+ server.repl_state = REDIS_REPL_NONE;
server.repl_syncio_timeout = REDIS_REPL_SYNCIO_TIMEOUT;
server.repl_serve_stale_data = 1;
server.repl_down_since = -1;
/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
* we are a slave with a broken link with master. */
- if (server.masterhost && server.replstate != REDIS_REPL_CONNECTED &&
+ if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED &&
server.repl_serve_stale_data == 0 &&
c->cmd->proc != infoCommand && c->cmd->proc != slaveofCommand)
{
"master_sync_in_progress:%d\r\n"
,server.masterhost,
server.masterport,
- (server.replstate == REDIS_REPL_CONNECTED) ?
+ (server.repl_state == REDIS_REPL_CONNECTED) ?
"up" : "down",
server.master ?
((int)(time(NULL)-server.master->lastinteraction)) : -1,
- server.replstate == REDIS_REPL_TRANSFER
+ server.repl_state == REDIS_REPL_TRANSFER
);
- if (server.replstate == REDIS_REPL_TRANSFER) {
+ if (server.repl_state == REDIS_REPL_TRANSFER) {
info = sdscatprintf(info,
"master_sync_left_bytes:%ld\r\n"
"master_sync_last_io_seconds_ago:%d\r\n"
);
}
- if (server.replstate != REDIS_REPL_CONNECTED) {
+ if (server.repl_state != REDIS_REPL_CONNECTED) {
info = sdscatprintf(info,
"master_link_down_since_seconds:%ld\r\n",
(long)time(NULL)-server.repl_down_since);
/* Refuse SYNC requests if we are a slave but the link with our master
* is not ok... */
- if (server.masterhost && server.replstate != REDIS_REPL_CONNECTED) {
+ if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED) {
addReplyError(c,"Can't SYNC while not connected with my master");
return;
}
/* Abort the async download of the bulk dataset while SYNC-ing with master */
void replicationAbortSyncTransfer(void) {
- redisAssert(server.replstate == REDIS_REPL_TRANSFER);
+ redisAssert(server.repl_state == REDIS_REPL_TRANSFER);
aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
close(server.repl_transfer_s);
close(server.repl_transfer_fd);
unlink(server.repl_transfer_tmpfile);
zfree(server.repl_transfer_tmpfile);
- server.replstate = REDIS_REPL_CONNECT;
+ server.repl_state = REDIS_REPL_CONNECT;
}
/* Asynchronously read the SYNC payload we receive from a master */
server.master = createClient(server.repl_transfer_s);
server.master->flags |= REDIS_MASTER;
server.master->authenticated = 1;
- server.replstate = REDIS_REPL_CONNECTED;
+ server.repl_state = REDIS_REPL_CONNECTED;
redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Finished with success");
/* Restart the AOF subsystem now that we finished the sync. This
* will trigger an AOF rewrite, and when done will start appending
/* If this event fired after the user turned the instance into a master
* with SLAVEOF NO ONE we must just return ASAP. */
- if (server.replstate == REDIS_REPL_NONE) {
+ if (server.repl_state == REDIS_REPL_NONE) {
close(fd);
return;
}
goto error;
}
- server.replstate = REDIS_REPL_TRANSFER;
+ server.repl_state = REDIS_REPL_TRANSFER;
server.repl_transfer_left = -1;
server.repl_transfer_fd = dfd;
server.repl_transfer_lastio = time(NULL);
return;
error:
- server.replstate = REDIS_REPL_CONNECT;
+ server.repl_state = REDIS_REPL_CONNECT;
close(fd);
return;
}
server.repl_transfer_lastio = time(NULL);
server.repl_transfer_s = fd;
- server.replstate = REDIS_REPL_CONNECTING;
+ server.repl_state = REDIS_REPL_CONNECTING;
return REDIS_OK;
}
void undoConnectWithMaster(void) {
int fd = server.repl_transfer_s;
- redisAssert(server.replstate == REDIS_REPL_CONNECTING);
+ redisAssert(server.repl_state == REDIS_REPL_CONNECTING);
aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE);
close(fd);
server.repl_transfer_s = -1;
- server.replstate = REDIS_REPL_CONNECT;
+ server.repl_state = REDIS_REPL_CONNECT;
}
void slaveofCommand(redisClient *c) {
sdsfree(server.masterhost);
server.masterhost = NULL;
if (server.master) freeClient(server.master);
- if (server.replstate == REDIS_REPL_TRANSFER)
+ if (server.repl_state == REDIS_REPL_TRANSFER)
replicationAbortSyncTransfer();
- else if (server.replstate == REDIS_REPL_CONNECTING)
+ else if (server.repl_state == REDIS_REPL_CONNECTING)
undoConnectWithMaster();
- server.replstate = REDIS_REPL_NONE;
+ server.repl_state = REDIS_REPL_NONE;
redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)");
}
} else {
server.masterhost = sdsdup(c->argv[1]->ptr);
server.masterport = atoi(c->argv[2]->ptr);
if (server.master) freeClient(server.master);
- if (server.replstate == REDIS_REPL_TRANSFER)
+ if (server.repl_state == REDIS_REPL_TRANSFER)
replicationAbortSyncTransfer();
- server.replstate = REDIS_REPL_CONNECT;
+ server.repl_state = REDIS_REPL_CONNECT;
redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)",
server.masterhost, server.masterport);
}
void replicationCron(void) {
/* Non blocking connection timeout? */
- if (server.masterhost && server.replstate == REDIS_REPL_CONNECTING &&
+ if (server.masterhost && server.repl_state == REDIS_REPL_CONNECTING &&
(time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
{
redisLog(REDIS_WARNING,"Timeout connecting to the MASTER...");
}
/* Bulk transfer I/O timeout? */
- if (server.masterhost && server.replstate == REDIS_REPL_TRANSFER &&
+ if (server.masterhost && server.repl_state == REDIS_REPL_TRANSFER &&
(time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
{
redisLog(REDIS_WARNING,"Timeout receiving bulk data from MASTER...");
}
/* Timed out master when we are an already connected slave? */
- if (server.masterhost && server.replstate == REDIS_REPL_CONNECTED &&
+ if (server.masterhost && server.repl_state == REDIS_REPL_CONNECTED &&
(time(NULL)-server.master->lastinteraction) > server.repl_timeout)
{
redisLog(REDIS_WARNING,"MASTER time out: no data nor PING received...");
}
/* Check if we should connect to a MASTER */
- if (server.replstate == REDIS_REPL_CONNECT) {
+ if (server.repl_state == REDIS_REPL_CONNECT) {
redisLog(REDIS_NOTICE,"Connecting to MASTER...");
if (connectWithMaster() == REDIS_OK) {
redisLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started");