From 610e88841a7e5265fef587e8d67d413889526c7a Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 4 Jan 2019 09:21:16 +0100 Subject: [PATCH] memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability --- sat/memory/sqlite.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/sat/memory/sqlite.py b/sat/memory/sqlite.py index 09916801..05da8933 100644 --- a/sat/memory/sqlite.py +++ b/sat/memory/sqlite.py @@ -140,16 +140,37 @@ class ConnectionPool(adbapi.ConnectionPool): # Sqlite integration, probably with high level library retry -= 1 if retry == 0: - log.error(_(u'too many db tries, we abandon! Error message: {msg}').format( - msg = e)) + log.error(_(u'too many db tries, we abandon! Error message: {msg}') + .format(msg = e)) raise e - log.warning(_(u'exception while running query, retrying ({try_}): {msg}').format( + log.warning( + _(u'exception while running query, retrying ({try_}): {msg}').format( try_ = 6 - retry, msg = e)) kw['query_retry'] = retry return self._runQuery(trans, *args, **kw) return trans.fetchall() + def _runInteraction(self, interaction, *args, **kw): + # sometimes interaction may fail while committing in _runInteraction + # and it may be due to a db lock. So we work around it in a similar way + # as for _runQuery but with only 3 tries + retry = kw.pop('interaction_retry', 4) + try: + return adbapi.ConnectionPool._runInteraction(self, interaction, *args, **kw) + except Exception as e: + retry -= 1 + if retry == 0: + log.error( + _(u'too many interaction tries, we abandon! Error message: {msg}') + .format(msg = e)) + raise e + log.warning( + _(u'exception while running interaction, retrying ({try_}): {msg}') + .format(try_ = 4 - retry, msg = e)) + kw['interaction_retry'] = retry + return self._runInteraction(interaction, *args, **kw) + class SqliteStorage(object): """This class manage storage with Sqlite database"""