diff options
author | antirez <antirez@gmail.com> | 2013-11-19 16:50:04 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-11-21 15:22:55 +0100 |
commit | 812f76a85027769df9c294cbaa08bf0ac4b4cf39 (patch) | |
tree | 2f23d86a2d38a727778c258fd16a6ff9304e35e9 | |
parent | fc93198ff920945d29625dda88a4509e69feefdf (diff) | |
download | redis-812f76a85027769df9c294cbaa08bf0ac4b4cf39.tar.gz |
Sentinel: distinguish between is-master-down-by-addr requests.
Some are just to know if the master is down, and in this case the runid
in the request is set to "*", others are actually in order to seek for a
vote and get elected. In the latter case the runid is set to the runid
of the instance seeking for the vote.
-rw-r--r-- | src/redis.c | 2 | ||||
-rw-r--r-- | src/sentinel.c | 20 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/redis.c b/src/redis.c index d4ff261ff..60195ab8c 100644 --- a/src/redis.c +++ b/src/redis.c @@ -3011,6 +3011,8 @@ int main(int argc, char **argv) { redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port); if (server.sofd > 0) redisLog(REDIS_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket); + } else { + redisLog(REDIS_WARNING,"Sentinel runid is %s", server.runid); } /* Warning the user about suspicious maxmemory setting. */ diff --git a/src/sentinel.c b/src/sentinel.c index d73114856..5a30db7be 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2361,8 +2361,9 @@ void sentinelCommand(redisClient *c) { (ri->flags & SRI_MASTER)) isdown = 1; - /* Vote for the master (or fetch the previous vote) */ - if (ri && ri->flags & SRI_MASTER) { + /* Vote for the master (or fetch the previous vote) if the request + * includes a runid, otherwise the sender is not seeking for a vote. */ + if (ri && ri->flags & SRI_MASTER && strcasecmp(c->argv[5]->ptr,"*")) { leader = sentinelVoteLeader(ri,(uint64_t)req_epoch, c->argv[5]->ptr, &leader_epoch); @@ -2372,7 +2373,7 @@ void sentinelCommand(redisClient *c) { * down state, leader, vote epoch. */ addReplyMultiBulkLen(c,3); addReply(c, isdown ? shared.cone : shared.czero); - addReplyBulkCString(c, leader ? leader : "?"); + addReplyBulkCString(c, leader ? leader : "*"); addReplyLongLong(c, (long long)leader_epoch); if (leader) sdsfree(leader); } else if (!strcasecmp(c->argv[1]->ptr,"reset")) { @@ -2607,9 +2608,13 @@ void sentinelReceiveIsMasterDownReply(redisAsyncContext *c, void *reply, void *p } else { ri->flags &= ~SRI_MASTER_DOWN; } - sdsfree(ri->leader); - ri->leader = sdsnew(r->element[1]->str); - ri->leader_epoch = r->element[2]->integer; + if (strcmp(r->element[1]->str,"*")) { + /* If the runid in the reply is not "*" the Sentinel actually + * replied with a vote. */ + sdsfree(ri->leader); + ri->leader = sdsnew(r->element[1]->str); + ri->leader_epoch = r->element[2]->integer; + } } } @@ -2662,7 +2667,8 @@ void sentinelAskMasterStateToOtherSentinels(sentinelRedisInstance *master, int f "SENTINEL is-master-down-by-addr %s %s %llu %s", master->addr->ip, port, sentinel.current_epoch, - server.runid); + (master->failover_state > SENTINEL_FAILOVER_STATE_NONE) ? + server.runid : "*"); if (retval == REDIS_OK) ri->pending_commands++; } dictReleaseIterator(di); |