api: always enable retry_on_request
The current behavior makes by default retry_on_request does not work, which is confusing. Nothing except the developer can raise a RetryRequest, so there can not be any misunderstanding. Having to both enable the switch *and* raise RetryRequest makes it more complicated than it needs to be. This patch simplifies the API by deprecating retry_on_request and retry_on_request() decorator, enabling the exception everywhere wrap_db_retry() is used. Change-Id: I3c53b5c8ba99f460153256fb2e1e6ef01b67f41b
This commit is contained in:
parent
3ac4f3f2d8
commit
663092d675
oslo_db
@ -27,6 +27,7 @@ import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
from debtcollector import removals
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import reflection
|
||||
@ -106,6 +107,8 @@ class wrap_db_retry(object):
|
||||
:type exception_checker: callable
|
||||
"""
|
||||
|
||||
@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,
|
||||
@ -113,15 +116,13 @@ class wrap_db_retry(object):
|
||||
exception_checker=lambda exc: False):
|
||||
super(wrap_db_retry, self).__init__()
|
||||
|
||||
self.db_error = ()
|
||||
self.db_error = (exception.RetryRequest, )
|
||||
# default is that we re-raise anything unexpected
|
||||
self.exception_checker = exception_checker
|
||||
if retry_on_disconnect:
|
||||
self.db_error += (exception.DBConnectionError, )
|
||||
if retry_on_deadlock:
|
||||
self.db_error += (exception.DBDeadlock, )
|
||||
if retry_on_request:
|
||||
self.db_error += (exception.RetryRequest, )
|
||||
self.retry_interval = retry_interval
|
||||
self.max_retries = max_retries
|
||||
self.inc_retry_interval = inc_retry_interval
|
||||
@ -258,8 +259,7 @@ class DBAPI(object):
|
||||
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,
|
||||
retry_on_request=retry_on_request)(attr)
|
||||
retry_on_deadlock=retry_on_deadlock)(attr)
|
||||
|
||||
return attr
|
||||
|
||||
|
@ -200,7 +200,7 @@ class DBReconnectTestCase(DBAPITestCase):
|
||||
|
||||
class DBRetryRequestCase(DBAPITestCase):
|
||||
def test_retry_wrapper_succeeds(self):
|
||||
@api.wrap_db_retry(max_retries=10, retry_on_request=True)
|
||||
@api.wrap_db_retry(max_retries=10)
|
||||
def some_method():
|
||||
pass
|
||||
|
||||
@ -209,7 +209,7 @@ class DBRetryRequestCase(DBAPITestCase):
|
||||
def test_retry_wrapper_reaches_limit(self):
|
||||
max_retries = 10
|
||||
|
||||
@api.wrap_db_retry(max_retries=10, retry_on_request=True)
|
||||
@api.wrap_db_retry(max_retries=10)
|
||||
def some_method(res):
|
||||
res['result'] += 1
|
||||
raise exception.RetryRequest(ValueError())
|
||||
@ -223,7 +223,7 @@ class DBRetryRequestCase(DBAPITestCase):
|
||||
def exception_checker(exc):
|
||||
return isinstance(exc, ValueError) and exc.args[0] < 5
|
||||
|
||||
@api.wrap_db_retry(max_retries=10, retry_on_request=True,
|
||||
@api.wrap_db_retry(max_retries=10,
|
||||
exception_checker=exception_checker)
|
||||
def some_method(res):
|
||||
res['result'] += 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user