From 10cf0be88f9ef2c9a2b3a9705cd3da15e055098a Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 26 Aug 2024 16:42:50 +0200 Subject: [PATCH] my_myql: Handle deadlocks in mysql_stmt_execute We've seen deadlocks when mxqkill races with job completion. Handle deadlocks errors in mysql_stmt_execute. This is possible, because we don't start multi-statement transactions. --- mx_mysql.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mx_mysql.c b/mx_mysql.c index ca983b0..2894ca7 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -262,14 +262,13 @@ static int mx__mysql_stmt_bind_result(struct mx_mysql_stmt *stmt) static int mx__mysql_stmt_execute(struct mx_mysql_stmt *stmt) { - int res; - assert(stmt); assert(stmt->stmt); - res = mysql_stmt_execute(stmt->stmt); - if (res == 0) - return 0; + do { + if (mysql_stmt_execute(stmt->stmt) == 0) + return 0; + } while (mysql_stmt_errno(stmt->stmt) == ER_LOCK_DEADLOCK); mx_mysql_save_error(mysql_stmt_error(stmt->stmt));