Hello, I just finished the first draft of the proposal. Comments welcomed:
Introduction
===
Sentinel already acts as a configuration device for clients. This
proposal further extends its role as a configuration device for Redis
instances after an instance restart.
This has a number of benefits such as better handling of reboots,
simpler to handle configurations of instances.
Basic operations
===
A new configuration option is added
manage-role-with-sentinels mymaster 192.168.1.1 2679 192.168.1.2 2679 … …
So in the configuration there are two elements: the master group name,
and a number of ip / port pairs that are the entry points to the
Sentinel system, so as usually the list does not need to be
exhaustive, but should contain enough addresses that we'll likely be
able to connect at least with a Sentinel.
As long as we don't have a role, we reply "-NOROLE trying to get a
role via Sentinel".
Note that during the NOROLE state, we reply even to PING with the
-NOROLE error, so the instance is basically down for monitoring
devices (Sentinel itself & so forth).
However we reply to INFO correctly.
How the sentinel advertises itself during that time?
===
When an instance is in NOROLE state, it shows "obtaining" in the INFO
replication section as role, and adds an additional field about the
master group name. Sentinels already monitoring this instance, will
not process the INFO output when the role is as such.
Example of INFO output:
role:obtaining
sentinel-group:mymaster
Startup phase
===
When a Redis instance configured to auto-configure via Sentinel
starts, it asks every instance in the list, one after the other (until
one working is found), what is the role it should use, using the
following command:
SENTINEL GETROLE <groupname> <port>
The Sentinel will obtain the IP address from the socket peer, while
the port is specified directly by the asking instance, so the Sentinel
knows the ip:port pair of the instance to identify the Redis instance.
We handle the following conditions:
1) If the instance is not known, it is assigned as a slave of the
current master.
2) If the instance is known and is a slave, we reply with the master
addr/port coordinates.
3) If the instance is known and is a master, we reply with a port of
zero (and any address) to tell the instance to turn into a master.
4) If we don't have a valid master, we reply -TRYAGAIN
As "master" we always use the elected slave if a failover is in progress.
Also if the current master is in ODOWN or SDOWN state, we always reply
with -TRYAGAIN, with the exception of case "3".
Race conditions handling
===
If a failover is in progress when an instance connects to a Sentinel
to get the role, it may happen that it gets assigned as a slave of the
old master, and there is not enough time for it to be detected and
switched to the new master when slaves are reconfigured.
For this reason, the Sentinel replying to the SENTINEL GETROLE query
with "slave", is in charge of:
1) If the instance is known, to clear the SDOWN state and update the
ping time accordingly.
2) If the instance is not known, to add it to the list of slaves of
the current master.
--
Salvatore 'antirez' Sanfilippo
open source developer - VMware
http://invece.org
Beauty is more important in computing than anywhere else in technology
because software is so complicated. Beauty is the ultimate defence
against complexity.
— David Gelernter