api: use sane default in wrap_db_retry()
The current defaults do not make much sense: having max_retries set to 0 completely avoid any retry, which is the whole point of that wrapper. This patch moves the correct default values from the DBAPI object to the wrap_db_retry() function itself. Change-Id: I89c2bd09e69b8b77b716573eb8b889c01f9d0f54
This commit is contained in:
parent
9904a1acd7
commit
8e3b356680
@ -109,9 +109,9 @@ class wrap_db_retry(object):
|
||||
|
||||
@removals.removed_kwarg("retry_on_request",
|
||||
"Retry on request is always enabled")
|
||||
def __init__(self, retry_interval=0, max_retries=0,
|
||||
inc_retry_interval=False,
|
||||
max_retry_interval=0, retry_on_disconnect=False,
|
||||
def __init__(self, retry_interval=1, max_retries=20,
|
||||
inc_retry_interval=True,
|
||||
max_retry_interval=10, retry_on_disconnect=False,
|
||||
retry_on_deadlock=False, retry_on_request=False,
|
||||
exception_checker=lambda exc: False):
|
||||
super(wrap_db_retry, self).__init__()
|
||||
@ -221,10 +221,11 @@ class DBAPI(object):
|
||||
self._load_backend()
|
||||
|
||||
self.use_db_reconnect = kwargs.get('use_db_reconnect', False)
|
||||
self.retry_interval = kwargs.get('retry_interval', 1)
|
||||
self.inc_retry_interval = kwargs.get('inc_retry_interval', True)
|
||||
self.max_retry_interval = kwargs.get('max_retry_interval', 10)
|
||||
self.max_retries = kwargs.get('max_retries', 20)
|
||||
self._wrap_db_kwargs = {k: v for k, v in kwargs.items()
|
||||
if k in ('retry_interval',
|
||||
'inc_retry_interval',
|
||||
'max_retry_interval',
|
||||
'max_retries')}
|
||||
|
||||
def _load_backend(self):
|
||||
with self._lock:
|
||||
@ -256,12 +257,9 @@ class DBAPI(object):
|
||||
|
||||
if retry_on_disconnect or retry_on_deadlock or retry_on_request:
|
||||
attr = wrap_db_retry(
|
||||
retry_interval=self.retry_interval,
|
||||
max_retries=self.max_retries,
|
||||
inc_retry_interval=self.inc_retry_interval,
|
||||
max_retry_interval=self.max_retry_interval,
|
||||
retry_on_disconnect=retry_on_disconnect,
|
||||
retry_on_deadlock=retry_on_deadlock)(attr)
|
||||
retry_on_deadlock=retry_on_deadlock,
|
||||
**self._wrap_db_kwargs)(attr)
|
||||
|
||||
return attr
|
||||
|
||||
|
@ -207,9 +207,9 @@ class DBRetryRequestCase(DBAPITestCase):
|
||||
some_method()
|
||||
|
||||
def test_retry_wrapper_reaches_limit(self):
|
||||
max_retries = 10
|
||||
max_retries = 2
|
||||
|
||||
@api.wrap_db_retry(max_retries=10)
|
||||
@api.wrap_db_retry(max_retries=max_retries)
|
||||
def some_method(res):
|
||||
res['result'] += 1
|
||||
raise exception.RetryRequest(ValueError())
|
||||
|
Loading…
x
Reference in New Issue
Block a user