comparison sat/memory/sqlite.py @ 2746:1e2f0856c845

memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability
author Goffi <goffi@goffi.org>
date Fri, 04 Jan 2019 09:21:16 +0100
parents ba74914277cf
children 6487b8855c9a
comparison
equal deleted inserted replaced
2745:3ee396b2ecf3 2746:1e2f0856c845
138 # FIXME: in case of error, we retry a couple of times 138 # FIXME: in case of error, we retry a couple of times
139 # this is a workaround, we need to move to better 139 # this is a workaround, we need to move to better
140 # Sqlite integration, probably with high level library 140 # Sqlite integration, probably with high level library
141 retry -= 1 141 retry -= 1
142 if retry == 0: 142 if retry == 0:
143 log.error(_(u'too many db tries, we abandon! Error message: {msg}').format( 143 log.error(_(u'too many db tries, we abandon! Error message: {msg}')
144 msg = e)) 144 .format(msg = e))
145 raise e 145 raise e
146 log.warning(_(u'exception while running query, retrying ({try_}): {msg}').format( 146 log.warning(
147 _(u'exception while running query, retrying ({try_}): {msg}').format(
147 try_ = 6 - retry, 148 try_ = 6 - retry,
148 msg = e)) 149 msg = e))
149 kw['query_retry'] = retry 150 kw['query_retry'] = retry
150 return self._runQuery(trans, *args, **kw) 151 return self._runQuery(trans, *args, **kw)
151 return trans.fetchall() 152 return trans.fetchall()
153
154 def _runInteraction(self, interaction, *args, **kw):
155 # sometimes interaction may fail while committing in _runInteraction
156 # and it may be due to a db lock. So we work around it in a similar way
157 # as for _runQuery but with only 3 tries
158 retry = kw.pop('interaction_retry', 4)
159 try:
160 return adbapi.ConnectionPool._runInteraction(self, interaction, *args, **kw)
161 except Exception as e:
162 retry -= 1
163 if retry == 0:
164 log.error(
165 _(u'too many interaction tries, we abandon! Error message: {msg}')
166 .format(msg = e))
167 raise e
168 log.warning(
169 _(u'exception while running interaction, retrying ({try_}): {msg}')
170 .format(try_ = 4 - retry, msg = e))
171 kw['interaction_retry'] = retry
172 return self._runInteraction(interaction, *args, **kw)
152 173
153 174
154 class SqliteStorage(object): 175 class SqliteStorage(object):
155 """This class manage storage with Sqlite database""" 176 """This class manage storage with Sqlite database"""
156 177