Replication: publish the slave_repl_offset when disconnected from master.

When a slave was disconnected from its master the replication offset was
reported as -1. Now it is reported as the replication offset of the
previous master, so that failover can be performed using this value in
order to try to select a slave with more processed data from a set of
slaves of the old master.
This commit is contained in:
antirez 2013-12-11 15:23:10 +01:00
parent 0a89d9a0b1
commit a5ec247f13

View File

@ -2522,6 +2522,13 @@ sds genRedisInfoString(char *section) {
"role:%s\r\n",
server.masterhost == NULL ? "master" : "slave");
if (server.masterhost) {
long long slave_repl_offset = 1;
if (server.master)
slave_repl_offset = server.master->reploff;
else if (server.cached_master)
slave_repl_offset = server.cached_master->reploff;
info = sdscatprintf(info,
"master_host:%s\r\n"
"master_port:%d\r\n"
@ -2536,7 +2543,7 @@ sds genRedisInfoString(char *section) {
server.master ?
((int)(server.unixtime-server.master->lastinteraction)) : -1,
server.repl_state == REDIS_REPL_TRANSFER,
server.master ? server.master->reploff : -1
slave_repl_offset
);
if (server.repl_state == REDIS_REPL_TRANSFER) {