summaryrefslogtreecommitdiff
path: root/openstack/common/rpc/impl_qpid.py
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2014-01-16 18:22:49 +0100
committerIhar Hrachyshka <ihrachys@redhat.com>2014-03-26 14:51:01 +0100
commit7fe95de20ccdfa5aa523ccb8a9ca3afdde5eddbb (patch)
tree10b9d25d8ec4aa04ff01573972a017500cad946e /openstack/common/rpc/impl_qpid.py
parent98fd71eb53f3bfe81061ea1b581d3f4eca76d615 (diff)
downloadoslo-incubator-7fe95de20ccdfa5aa523ccb8a9ca3afdde5eddbb.tar.gz
Qpid: advance thru the list of brokers on reconnect
In Qpid implementation, when using multiple qpid_hosts, we don't want to immediately retry failed connection for the same failed broker. This was not the case in existing implementation though, where we've always attempted to reconnect starting from the first broker in the list of candidates. So if the first broker failed, we initiated reconnect to the same failed broker. This change makes reconnect() implementation to select the next broker in the list. This also means that non-failure reconnect attempts will also switch the current broker. All in all, users should not rely on any particular order to use brokers from the list, so this should not constitute an issue. This is a backport of the following changes from oslo.messaging: * I257c2ad6d7ebead356c0239134340975da6dbc07 (code change) * I32e20c0e747e6489dab4b0358d422b8a9c6b982e (unit test). Change-Id: Ia148baa6e1ec632789ac3621c85173c2c16f3918 Partial-Bug: 1261631
Diffstat (limited to 'openstack/common/rpc/impl_qpid.py')
-rw-r--r--openstack/common/rpc/impl_qpid.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py
index 00c45e82..8b8a86b1 100644
--- a/openstack/common/rpc/impl_qpid.py
+++ b/openstack/common/rpc/impl_qpid.py
@@ -467,6 +467,10 @@ class Connection(object):
self.brokers = params['qpid_hosts']
self.username = params['username']
self.password = params['password']
+
+ brokers_count = len(self.brokers)
+ self.next_broker_indices = itertools.cycle(range(brokers_count))
+
self.connection_create(self.brokers[0])
self.reconnect()
@@ -494,7 +498,6 @@ class Connection(object):
def reconnect(self):
"""Handles reconnecting and re-establishing sessions and queues."""
- attempt = 0
delay = 1
while True:
# Close the session if necessary
@@ -504,8 +507,7 @@ class Connection(object):
except qpid_exceptions.ConnectionError:
pass
- broker = self.brokers[attempt % len(self.brokers)]
- attempt += 1
+ broker = self.brokers[next(self.next_broker_indices)]
try:
self.connection_create(broker)