P粉6499901632023-08-31 15:04:19
I would keep everything in the process: then all the code related to this behavior is in one place. Also: wouldn't the deadlock follow the execution of your CALL statement instead of continuing? If we proceed, then the problem may have been solved and we won't be waiting for anything. Additionally, transactions following a deadlock will only be executed after the deadlock is resolved.
My approach to your code is:
CREATE PROCEDURE manageAccounts() BEGIN DECLARE totalTrys INT DEFAULT 0; DECLARE EXIT HANDLER FOR SQLEXCEPTION GET DIAGNOSTICS CONDITION 1 @err_num = MYSQL_ERRNO; CALL guardi.prod_update_guardi_accounts(); WHILE(@err_num = 1213 AND totalTrys < 4) DO SET totalTrys = totalTrys + 1; SELECT SLEEP(900); CALL guardi.prod_update_guardi_accounts(); END WHILE; END;
You'll have to test this: untested, so typos are not impossible.