3

Context:

I have 3 redis nodes, and 3 sentinels. The failover works properly. When I'm taking the master down, another master is elected.

Need:

I need a way to test the behavior, to make sure everything works as expected. I wish I could force the sentinels to select a specific redis node to be the master.

I guess I could do that by taking down the two nodes that should not be the master, but I wish I could just issue a command to one of the sentinels to solve my issue.

tl;dr:

Can I instruct my sentinels to select a specific redis node as master?

aspyct
  • 340
  • 6
  • 19

1 Answers1

2

You can cause a hang on the two Redis-servers you don't want as master and I think (not tested) Sentinel will pick the remaining one. It may take two elections...

Simulating a hang on the Redis servers:

redis-cli DEBUG sleep 30

or

redis-cli DEBUG segfault

Then force a fail over:

SENTINEL failover

Perhaps a better approach is to use the priority option.

From https://redis.io/topics/sentinel

Slaves priority

Redis instances have a configuration parameter called slave-priority. This information is exposed by Redis slave instances in their INFO output, and Sentinel uses it in order to pick a slave among the ones that can be used in order to failover a master:

If the slave priority is set to 0, the slave is never promoted to master. Slaves with a lower priority number are preferred by Sentinel.

For example if there is a slave S1 in the same data center of the current master, and another slave S2 in another data center, it is possible to set S1 with a priority of 10 and S2 with a priority of 100, so that if the master fails and both S1 and S2 are available, S1 will be preferred.

For more information about the way slaves are selected, please check the slave selection and priority section of this documentation.

ETL
  • 6,443
  • 1
  • 26
  • 47
  • This solution is nice (especially the segfault, which I didn't know about), but it still requires taking down the current master. I would love to avoid that. – aspyct Feb 21 '19 at 12:37