summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-11-24 15:36:04 +0000
committerGerrit Code Review <review@openstack.org>2016-11-24 15:36:04 +0000
commitfbfb0812e37ee3080ad2f13f955baf446135da37 (patch)
treea57c11cab07715443a1e0f0f3db495c7a1b8fb22
parentea8fad47a57b1c8784a0a7c1fc435c4e38200863 (diff)
parent9ea5f18bb84d9eddac633e2dad7362e2e55c182e (diff)
downloadoslo-messaging-fbfb0812e37ee3080ad2f13f955baf446135da37.tar.gz
Merge "[sentinel] Move master/slave discovering from __init__"
-rw-r--r--oslo_messaging/_drivers/zmq_driver/matchmaker/zmq_matchmaker_redis.py31
1 files 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 640a19d..1c212e7 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):