Reputation: 8798
I have the following Redis/Sentinel configuration:
A
+ N
slavesM
sentinels watching A
, named masterA
masterA
, then query and modify A
Now say A
is outdated and I want to replace it by a new Redis master called B
(with minimum down time / data loss.). In the end of the operation, I want this:
B
+ N
slavesB
I could proceed as follows:
B
, named masterB
A
become a slave of B
From there, I am stuck because the client application still asks for masterA
when talking to the sentinels. I have two questions:
B
becomes known as masterA
for the sentinels, and therefore for the client application as well?Upvotes: 1
Views: 1893
Reputation: 144
One way of achieving your aim is to follow the age old solution of "adding another level of indirection".
A particularly effective method is to have your clients talk to a TCP proxy (e.g. HAProxy) and have it pass the traffic to the current master.
To keep the TCP proxy is sync you can do something similar to http://blog.haproxy.com/2014/01/02/haproxy-advanced-redis-health-check/ which makes HAProxy Sentinel aware.
The major plus for this solution is that it makes your clients very simple - they only connect to one place and the traffic is always forwarded to the correct Redis instance.
One issue with this solution is that HAProxy's configuration DSL does not have the ability to deal with the period when a Redis server restarts and announces itself initially as a master before the sentinels make it a slave. This will lead to missed writes and inconsistent state which depending on you application could be fine or maybe not.
To deal with this I have started to develop a "smarter" daemon to keep HAProxy in sync with the current master. My solution is at https://github.com/mdevilliers/redishappy.
Upvotes: 1