[API] More transaction fixes

Change-Id: Id39590768baa6ec4770c48c954a301e37faae4f8
This commit is contained in:
Andrew Hutchings
2013-07-10 12:16:53 +01:00
parent a6af7d34fb
commit 08da0c161d
3 changed files with 20 additions and 23 deletions

View File

@@ -54,17 +54,16 @@ def client_job(logger, job_type, host, data, lbid):
if job_type == 'ARCHIVE':
client.send_archive(data)
return
except OperationalError as exc:
except OperationalError:
# Auto retry on galera locking error
if exc.args[0] != 1213:
raise
else:
logger.warning(
"Galera deadlock in gearman, retry {0}".format(x+1)
)
logger.warning(
"Galera deadlock in gearman, retry {0}".format(x+1)
)
except:
logger.exception("Gearman thread unhandled exception")
logger.error("Gearman thread could not talk to DB")
class GearmanClientThread(object):
def __init__(self, logger, host, lbid):

View File

@@ -77,10 +77,10 @@ class LibraController(RestController):
_lookup_result = self._handle_lookup(args)
if _lookup_result:
return _lookup_result
except OperationalError as sqlexc:
except OperationalError:
logger = logging.getLogger(__name__)
# if a galera transaction fails due to locking, retry the call
if sqlexc.args[0] == 1213 and LibraController.routing_calls < 5:
if LibraController.routing_calls < 5:
LibraController.routing_calls += 1
logger.warning("Galera deadlock, retry: {0}".format(
LibraController.routing_calls)

View File

@@ -104,21 +104,12 @@ def wsexpose(*args, **kwargs):
pecan.response.status = result.status_code
result = result.obj
except OperationalError as sqlexc:
except OperationalError:
logger = logging.getLogger(__name__)
if sqlexc.args[0] == 1213:
logger.warning(
"Galera deadlock in gearman, retry {0}".format(x+1)
)
continue
else:
data = wsme.api.format_exception(
sys.exc_info(),
pecan.conf.get('wsme', {}).get('debug', False)
)
e = sys.exc_info()[1]
pecan.response.status = 500
return data
logger.warning(
"Galera deadlock in gearman, retry {0}".format(x+1)
)
continue
except:
data = wsme.api.format_exception(
sys.exc_info(),
@@ -137,6 +128,13 @@ def wsexpose(*args, **kwargs):
datatype=funcdef.return_type,
result=result
)
# After 5 retries of transaction, give up!
data = wsme.api.format_exception(
sys.exc_info(),
pecan.conf.get('wsme', {}).get('debug', False)
)
pecan.response.status = 500
return data
pecan_xml_decorate(callfunction)
pecan_json_decorate(callfunction)