From 9ea5f18bb84d9eddac633e2dad7362e2e55c182e Mon Sep 17 00:00:00 2001 From: Kirill Bespalov Date: Wed, 26 Oct 2016 15:18:21 +0300 Subject: [PATCH] [sentinel] Move master/slave discovering from __init__ Move from __init__ any redis hosts discovering, because at the first few seconds of sentinel starting no master or slave are synced and in this case the constructor of MatchmakerSentinel may thrown MasterNotFoundError or SlaveNotFoundError exception that kills openstack service at the starting (nova/neutron). Change-Id: I3f0e0cb13072e438224675055678fc8cee913961 --- .../matchmaker/zmq_matchmaker_redis.py | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/oslo_messaging/_drivers/zmq_driver/matchmaker/zmq_matchmaker_redis.py b/oslo_messaging/_drivers/zmq_driver/matchmaker/zmq_matchmaker_redis.py index 640a19d72..1c212e761 100644 --- a/oslo_messaging/_drivers/zmq_driver/matchmaker/zmq_matchmaker_redis.py +++ b/oslo_messaging/_drivers/zmq_driver/matchmaker/zmq_matchmaker_redis.py @@ -362,18 +362,33 @@ class MatchmakerSentinel(MatchmakerRedisBase): def __init__(self, conf, *args, **kwargs): super(MatchmakerSentinel, self).__init__(conf, *args, **kwargs) - - self._sentinel_hosts, password, master_group = \ + socket_timeout = self.conf.matchmaker_redis.socket_timeout / 1000. + self._sentinel_hosts, self._password, self._master_group = \ self._extract_sentinel_hosts() - self._sentinel = redis_sentinel.Sentinel( sentinels=self._sentinel_hosts, - socket_timeout=self.conf.matchmaker_redis.socket_timeout / 1000., - password=password - ) + socket_timeout=socket_timeout, + password=self._password) + self._slave = self._master = None - self._redis_master = self._sentinel.master_for(master_group) - self._redis_slave = self._sentinel.slave_for(master_group) + @property + def _redis_master(self): + try: + if not self._master: + self._master = self._sentinel.master_for(self._master_group) + return self._master + except redis_sentinel.MasterNotFoundError: + raise zmq_matchmaker_base.MatchmakerUnavailable() + + @property + def _redis_slave(self): + try: + if not self._slave: + self._slave = self._sentinel.slave_for(self._master_group) + except redis_sentinel.SlaveNotFoundError: + # use the master as slave (temporary) + return self._redis_master + return self._slave def _extract_sentinel_hosts(self):