# HG changeset patch # User Goffi # Date 1546590076 -3600 # Node ID 1e2f0856c8455a52e83f0ce19ee8057d9ac842cc # Parent 3ee396b2ecf3ecb456887e0bb60ea51174777e3e memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability diff -r 3ee396b2ecf3 -r 1e2f0856c845 sat/memory/sqlite.py --- a/sat/memory/sqlite.py Fri Jan 04 09:20:32 2019 +0100 +++ b/sat/memory/sqlite.py Fri Jan 04 09:21:16 2019 +0100 @@ -140,16 +140,37 @@ # 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"""