api: do not log a traceback if error is not expected
Currently, when using the retry decorator on a function that raises an error on
the last retry, oslo.db always log the following:
ERROR oslo_db.api [-] DB exceeded retry limit.
ERROR oslo_db.api Traceback (most recent call last):
ERROR oslo_db.api File "/usr/local/lib/python2.7/dist-packages/oslo_db/api.py", line 138, in wrapper
ERROR oslo_db.api return f(*args, **kwargs)
ERROR oslo_db.api File "/opt/stack/gnocchi/gnocchi/indexer/sqlalchemy.py", line 686, in list_resources
ERROR oslo_db.api raise indexer.InvalidPagination("Invalid sort keys")
ERROR oslo_db.api InvalidPagination: Invalid pagination: `Invalid sort keys'
Which is wrong, since in this case the `InvalidPagination' is totally unrelated to the retry code.
This patch fixes that by only calling LOG.exception if the last try is really
about an expected retry condition.
Change-Id: Iacc6d3aeac41ddfff76f081428678e2e0688055a
Closes-Bug: #1587637
This commit is contained in:
@@ -139,10 +139,12 @@ class wrap_db_retry(object):
|
||||
return f(*args, **kwargs)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception() as ectxt:
|
||||
expected = self._is_exception_expected(e)
|
||||
if remaining > 0:
|
||||
ectxt.reraise = not self._is_exception_expected(e)
|
||||
ectxt.reraise = not expected
|
||||
else:
|
||||
LOG.exception(_LE('DB exceeded retry limit.'))
|
||||
if expected:
|
||||
LOG.exception(_LE('DB exceeded retry limit.'))
|
||||
# if it's a RetryRequest, we need to unpack it
|
||||
if isinstance(e, exception.RetryRequest):
|
||||
ectxt.type_ = type(e.inner_exc)
|
||||
|
||||
Reference in New Issue
Block a user