MySQL transaction restart after deadlock

I ran into a dead end in my MySQL. How to configure MySQL to automatically restart a transaction when it encounters a dead end?

+7
source share
4 answers

You cannot do this automatically because a deadlock occurred because two transactions tried to change the same data . If you know that repeating the same statements again is correct, you need to implement this in your application.

However, the presence of such a database will automatically be irresponsible, as there may also be times when your application must first look at a new situation in the database before issuing potentially modified statements, if any.

+6
source

As a rule, you should write your applications so that they are always ready to resell the transaction if it rolls back due to a dead end.

http://dev.mysql.com/doc/refman/5.1/en/innodb-deadlocks.html

The manual indicates that this configuration option does not exist.

+3
source

Restarting a transaction means:

  • (optional) initiate a new database connection descriptor;
  • Execute the first function / line code that initiates a new transaction, and repeats the entire execution path to commit .

Since the database engine cannot know the queries that would be executed after the deadlock occurred, it will not be able to repeat everything for you (not to mention that there may be application logic that could execute different queries based on the recently modified data database )

+3
source

Well, you can't, and that doesn't make sense. It depends on your application to deal with the dead end and how this is done depends a lot on your business logic, for example. catch the exception, wait a few seconds, repeat x times ...

0
source

All Articles