Skip to content

Commit

Permalink
server.replstate -> server.repl_state
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Dec 21, 2011
1 parent f48cd4b commit 1844f99
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Expand Up @@ -179,7 +179,7 @@ void loadServerConfigFromString(char *config) {
} else if (!strcasecmp(argv[0],"slaveof") && argc == 3) {
server.masterhost = sdsnew(argv[1]);
server.masterport = atoi(argv[2]);
server.replstate = REDIS_REPL_CONNECT;
server.repl_state = REDIS_REPL_CONNECT;
} else if (!strcasecmp(argv[0],"repl-ping-slave-period") && argc == 2) {
server.repl_ping_slave_period = atoi(argv[1]);
if (server.repl_ping_slave_period <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/networking.c
Expand Up @@ -519,7 +519,7 @@ void freeClient(redisClient *c) {
/* Case 2: we lost the connection with the master. */
if (c->flags & REDIS_MASTER) {
server.master = NULL;
server.replstate = REDIS_REPL_CONNECT;
server.repl_state = REDIS_REPL_CONNECT;
server.repl_down_since = time(NULL);
/* Since we lost the connection with the master, we should also
* close the connection with all our slaves if we have any, so
Expand Down
12 changes: 6 additions & 6 deletions src/redis.c
Expand Up @@ -923,7 +923,7 @@ void initServerConfig() {
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;
Expand Down Expand Up @@ -1254,7 +1254,7 @@ int processCommand(redisClient *c) {

/* 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)
{
Expand Down Expand Up @@ -1592,14 +1592,14 @@ sds genRedisInfoString(char *section) {
"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"
Expand All @@ -1608,7 +1608,7 @@ sds genRedisInfoString(char *section) {
);
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/redis.h
Expand Up @@ -588,7 +588,7 @@ struct redisServer {
int repl_timeout; /* Timeout after N seconds of master idle */
redisClient *master; /* Client that is master for this slave */
int repl_syncio_timeout; /* Timeout for synchronous I/O calls */
int replstate; /* Replication status if the instance is a slave */
int repl_state; /* Replication status if the instance is a slave */
off_t repl_transfer_left; /* Bytes left reading .rdb */
int repl_transfer_s; /* Slave -> Master SYNC socket */
int repl_transfer_fd; /* Slave -> Master SYNC temp file descriptor */
Expand Down
38 changes: 19 additions & 19 deletions src/replication.c
Expand Up @@ -89,7 +89,7 @@ void syncCommand(redisClient *c) {

/* 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;
}
Expand Down Expand Up @@ -265,14 +265,14 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {

/* 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 */
Expand Down Expand Up @@ -356,7 +356,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
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
Expand Down Expand Up @@ -392,7 +392,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {

/* 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;
}
Expand Down Expand Up @@ -454,15 +454,15 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
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);
server.repl_transfer_tmpfile = zstrdup(tmpfile);
return;

error:
server.replstate = REDIS_REPL_CONNECT;
server.repl_state = REDIS_REPL_CONNECT;
close(fd);
return;
}
Expand All @@ -487,7 +487,7 @@ int connectWithMaster(void) {

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;
}

Expand All @@ -496,11 +496,11 @@ int connectWithMaster(void) {
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) {
Expand All @@ -510,21 +510,21 @@ 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 {
sdsfree(server.masterhost);
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);
}
Expand All @@ -535,31 +535,31 @@ void slaveofCommand(redisClient *c) {

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...");
undoConnectWithMaster();
}

/* 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...");
replicationAbortSyncTransfer();
}

/* 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...");
freeClient(server.master);
}

/* 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");
Expand Down

0 comments on commit 1844f99

Please sign in to comment.