Sync RPC module from oslo, fixing reconnect failures
This change syncs the following patches from oslo-incubator RPC: - I67923cb024bbd143edc8edccf35b9b400df31eb3 - Ia148baa6e1ec632789ac3621c85173c2c16f3918 RabbitMQ: advance thru the list of brokers on reconnect In RabbitMQ implementation, when using multiple rabbit_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. 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. Partial-Bug: #1261631 Change-Id: Ie9c4de2c094a5d420acca5e4a49ee6a36279ed87
This commit is contained in:
parent
92e54f73e6
commit
af1eb64f65
|
@ -462,6 +462,9 @@ class Connection(object):
|
|||
|
||||
self.params_list = params_list
|
||||
|
||||
brokers_count = len(self.params_list)
|
||||
self.next_broker_indices = itertools.cycle(range(brokers_count))
|
||||
|
||||
self.memory_transport = self.conf.fake_rabbit
|
||||
|
||||
self.connection = None
|
||||
|
@ -543,7 +546,7 @@ class Connection(object):
|
|||
|
||||
attempt = 0
|
||||
while True:
|
||||
params = self.params_list[attempt % len(self.params_list)]
|
||||
params = self.params_list[next(self.next_broker_indices)]
|
||||
attempt += 1
|
||||
try:
|
||||
self._connect(params)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
@ -504,8 +508,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)
|
||||
|
|
Loading…
Reference in New Issue