P
P
Pavel Kityan2016-04-21 22:45:18
MySQL
Pavel Kityan, 2016-04-21 22:45:18

What is the correct way to roll back an out-of-procedural transaction in MySQL in case of an error?

Greetings. The situation is this. The client code puts the initial data into the database in several different tables ("raw initial messages of different types"), and then into the table ("main table") of post-processed messages one record ("post-processed message") based on the raw ones. Raw tables have pointers to the id of the main table. And you need a transaction for all this.
At first I wanted to do it in a stored procedure, but according to the business logic, an unlimited number of raw messages of some types is possible. Arrays cannot be passed to MySQL in a procedure, parsing text strings is also not an option.
As a result, I decided to simply make a multi-statement request, which the client code itself forms.
And here it turned out that I cannot roll back the transaction there in case of an error, since handlers can only be declared inside procedures. So?
Moreover, the connection to the mysql server is long-lived (the connection pool of the nodejs module) and auto-rollback does not occur when it breaks.
Does that mean there is only one option? See if an error has returned in the connection, and if so, either break it or execute it with a new "ROLLBACK;" request. At once?
Otherwise, in case of an error, the tables are locked and that's it. Probably there are some timeouts for the transaction, but I haven’t found it yet, and I don’t want to rely on them.
Or not?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question