Propagation properties and isolation levels for transactions

Source: Internet
Author: User
Tags commit rollback
1 propagation properties of a transaction (propagation)

1) REQUIRED, this is the default property
Support A current transaction, create a new one if none exists.
If there is a transaction, the current transaction is supported. If there is no transaction, a new transaction is opened.
When set to this level, a logical transaction domain is created for each called method. If the previous method has already created a transaction, the following method supports the current transaction, and if no transaction is currently in place, the transaction is re-established.
As shown in the figure:

2) MANDATORY
Support A is current transaction, and throw an exception if none exists. The existing transaction is supported and throws an exception if there is no current transaction.

3) Never
Execute non-transactionally, throw an exception if a transaction exists.
Executes in a non-transactional manner, throwing an exception if a transaction is currently present.

4) not_supported
Execute non-transactionally, suspend the current transaction if one exists.
Executes the operation in a non-transactional manner, suspending the current transaction if a transaction is currently present.

5) Requires_new
Create a new transaction, suspend the current transaction if one exists.
Creates a new transaction, suspending the current transaction if the transaction currently exists.
As shown in the figure:

6) SUPPORTS
Support A current transaction, execute non-transactionally if none exists.
Supports the current transaction and is executed in a non-transactional manner if no transaction is currently in use.

7) NESTED
Execute within a nested transaction if a current transaction exists, behave like propagation_required else.
Supports the current transaction, adds a new savepoint point, synchronously commits or rolls back with the current transaction.
Nested transactions A very important concept is that the inner transaction relies on the outer layer. When the outer transaction fails, the actions of the inner layer are rolled back. The failure of the inner transaction operation does not cause the rollback of the outer transaction.

8) The difference between propagation_nested and propagation_requires_new
They are very similar, like a nested transaction, which opens a new transaction if there is no active transaction. With Propagation_requires_new, the inner transaction and the outer transaction are like two separate transactions, and once the inner transaction commits, the outer transaction cannot roll it back. Two transactions do not affect each other. Two transactions are not a true nested transaction. It also requires the support of the JTA transaction manager.
When using propagation_nested, the rollback of the outer transaction can cause a rollback of the inner transaction. The exception of the inner transaction does not cause the rollback of the outer transaction, which is a true nested transaction.

Isolation level for 2 transactions (isolation levels)

1) First explain the three situations caused by transaction concurrency

I. Dirty Reads Dirty Reading
One transaction is updating the data, but the update has not yet been committed, and the other transaction is also manipulating the set of data and reading the data that was not committed by the previous transaction, and the previous transaction, if the operation failed, was rolled back, and the last transaction read the error data, which resulted in dirty reads.
Ii. non-repeatable Reads non-repeatable reading
A transaction reads the same data multiple times, and when the transaction is not finished, another transaction also operates on the data, and the second transaction updates the data between the first transaction two reads, and then the first transaction is read two times before the data is different, which results in non-repeatable reads.
Iii. Phantom Reads Phantom Reading
The first data is querying data that matches a certain condition, and another transaction inserts a qualifying data, and the first transaction finds data that is not in the previous query when the second query meets the same criteria, as if the illusion is a phantom read.
Iv. the difference between non-repetition and phantom reading
Non-repeating reads refer to the same query occurring more than once in the same transaction, where a non-repeating read occurs each time a different result set is returned due to modifications or deletions made by other committed transactions. (A transaction rereads data It has previously read and finds that another committed transaction have modified or deleted th E data. )
Phantom reading refers to the fact that the same query occurs more than once in the same transaction, and the phantom reads occur each time a different result set is returned because of an insert operation done by another commit. (A transaction reexecutes a query returning a set of rows that satisfies a search condition and finds that another Committ Ed transaction had inserted additional rows that satisfy the condition. )
On the surface, the difference is that non-repeating reads can see the changes and deletions that other transactions commit, while the Phantom can see the insertions that other transactions commit.

2) Default (default)
This is a Platfromtransactionmanager default isolation level that uses the default transaction isolation level of the database. The other four are relative to the JDBC isolation level

3) read_uncommitted (read not submitted)
This is the lowest isolation level for transactions, which allows another transaction to see the uncommitted data for this transaction. This isolation level produces dirty reads, non-repeatable reads, and Phantom reads.

4) read_committed (read submitted)
Ensure that a transaction modified data is committed before it can be read by another transaction. Another transaction cannot read uncommitted data for the transaction. This level of transaction isolation avoids dirty reads, but non-repeatable reads and phantom reads can occur.

5) Repeatable_read (repeatable reading)
This level of transaction isolation prevents dirty reads and cannot be read repeatedly. However, Phantom reads may occur. It guarantees non-repeatable reads in addition to ensuring that one transaction cannot read uncommitted data from another transaction.

6) SERIALIZABLE (serialization)
This is the most cost-effective, but most reliable, transaction isolation level. Transactions are processed for sequential execution. In addition to preventing dirty reading, non-repeatable reading, but also avoids phantom reading.

7) Isolation level resolves issues caused by transaction parallelism
Dirty reads non-repeatable reads Phantom reads
Serializable not going to be
Repeatable READ will not be
READ COMMITTED will not be
Read UNCOMMITTED will be

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.