[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
This commit is contained in:
parent
587749d856
commit
9ea5f18bb8
@ -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):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user