Retry on deadlock
This commit is contained in:
parent
0bfa78b39b
commit
49d6aa1394
|
@ -159,10 +159,20 @@ class LoggingTransaction(object):
|
||||||
|
|
||||||
start = time.time() * 1000
|
start = time.time() * 1000
|
||||||
|
|
||||||
|
try:
|
||||||
|
i = 0
|
||||||
|
N = 5
|
||||||
|
while True:
|
||||||
try:
|
try:
|
||||||
return self.txn.execute(
|
return self.txn.execute(
|
||||||
sql, *args, **kwargs
|
sql, *args, **kwargs
|
||||||
)
|
)
|
||||||
|
except self.database_engine.module.DatabaseError as e:
|
||||||
|
if self.database_engine.is_deadlock(e) and i < N:
|
||||||
|
i += 1
|
||||||
|
logger.warn("[SQL DEADLOCK] {%s}", self.name)
|
||||||
|
continue
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug("[SQL FAIL] {%s} %s", self.name, e)
|
logger.debug("[SQL FAIL] {%s} %s", self.name, e)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -40,3 +40,8 @@ class MariaEngine(object):
|
||||||
)
|
)
|
||||||
db_conn.commit()
|
db_conn.commit()
|
||||||
prepare_database(db_conn, self)
|
prepare_database(db_conn, self)
|
||||||
|
|
||||||
|
def is_deadlock(self, error):
|
||||||
|
if isinstance(error, self.module.InternalError):
|
||||||
|
return error.sqlstate == 40001 and error.errno == 1213
|
||||||
|
return False
|
||||||
|
|
|
@ -32,3 +32,6 @@ class Sqlite3Engine(object):
|
||||||
def prepare_database(self, db_conn):
|
def prepare_database(self, db_conn):
|
||||||
prepare_sqlite3_database(db_conn)
|
prepare_sqlite3_database(db_conn)
|
||||||
prepare_database(db_conn, self)
|
prepare_database(db_conn, self)
|
||||||
|
|
||||||
|
def is_deadlock(self, error):
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue