Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does transaction suspension work in MySQL?

In the Spring Framework manual they state that for a PROPAGATION_REQUIRES_NEW the current transaction will be suspended.

What does that "suspended transaction"? The timer for the timeout stops counting on the current transaction? What are the actual implication of such suspension?

Thank you,

Asaf

like image 240
Asaf Mesika Avatar asked Nov 25 '09 13:11

Asaf Mesika


People also ask

What happens when you suspend a transaction?

When a transaction is suspended, it waits until it can pick up where it left off. But this means that the things that happen while the transaction is suspended are NOT part of the same atomic unit.

What does it mean to suspend a transaction?

Transactions are often suspended to quickly free up a register for a different task without losing any progress on the current transaction. For example, a store associate starts to process a customer's transaction on a mobile device but must complete it on a register that has a cash drawer.

How does MySQL transactions work?

A transaction is a sequential group of database manipulation operations, which is performed as if it were one single work unit. In other words, a transaction will never be complete unless each individual operation within the group is successful.

Are transactions supported in MySQL?

MySQL supports local transactions (within a given client session) through statements such as SET autocommit , START TRANSACTION , COMMIT , and ROLLBACK . See Section 13.3. 1, “START TRANSACTION, COMMIT, and ROLLBACK Statements”. XA transaction support enables MySQL to participate in distributed transactions as well.


1 Answers

It doesn't mean anything special, a suspended transaction is just a transaction that is temporarily not used for inserts, updates, commit or rollback, because a new transaction should be created due to the specified propagation properties, and only one transaction can be active at the same time.

Basically there are two transaction models: the nested and flat model. In the nested model, if you start a transaction, and you need an other one, the first one remains active, that is, the second one will be nested inside its parent, and so on. On the other hand, in the flat model, the first transaction will be suspended, that is, we won't use it until the new one has been completed.

AFAIK the flat model is used almost exclusively (including Spring and the EJB spec as well), since it's much easier to implement: there is only one active transaction at any given time, so it's easy to decide what to do in case of a rollback, say, because of an exception. More importantly, the underlying database has to support it if you need the nested model, so the flat model is just the common denominator in this case.

like image 184
candiru Avatar answered Sep 18 '22 13:09

candiru