Dirty Read | non-repeatability | Understanding of Magic reading and five types of transaction isolation levels defined by spring

Source: Internet
Author: User

The different transaction isolation levels in 5 are defined in spring.

1. Isolation_default (This configuration is normally used in both cases)

This is a Platfromtransactionmanager default isolation level that uses the default transaction isolation level of the database.

2. isolation_read_uncommitted

This is the lowest isolation level for transactions, and it allows a transaction to see uncommitted data for that transaction. This isolation level produces dirty reads, non-repeatable reads, and Phantom reads.

(This is not the case with most database default object isolation Levels)

3. isolation_read_committed

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.

What is dirty reading?

For example:

Zhang San's salary was 5000 and transaction a changed his salary to 8000, but transaction a was not yet submitted.

Meanwhile

Transaction B is reading Zhang San's salary and reading to Zhang San's salary is 8000.

Then

Transaction A has an exception and the transaction is rolled back. Zhang San's wages were rolled back to 5000.

At last

Transaction B reads 8000 of the Zhang San payroll data as dirty data, and transaction B does a dirty read.

(This is not the case with most database default object isolation Levels)

4. Isolation_repeatable_read

This level of transaction isolation prevents dirty reads and cannot be read repeatedly. However, Phantom reads may occur.

What is non-repeatable reading?

For example:

In transaction A, the salary read to Zhang San is 5000, the operation is not completed, and the transaction is not committed.

Meanwhile

Transaction B changed the salary of Zhang San to 8000 and submitted the transaction.

Then

In transaction A, the salary of the Zhang San is read again, at which time the salary becomes 8000. The result of two reads in a transaction does not cause a non-repeatable read.

(This is not the case with most database default object isolation Levels)

5. isolation_serializable

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 the phantom reading.

What is Phantom reading?

For example:

The current salary is 5000 employees have 10 people, transaction a read all wages for 5000 of the number of 10 people.

At this time

Transaction B Inserts a record with a salary of 5000.

This is, transaction a reads the employee with a payroll of 5000 again, and records 11 people. This creates a phantom read.

(This is the case with most database default object isolation levels, which will result in table-level locks)

Description: The default object isolation level for Oracle database has been guaranteed to avoid dirty reads and non-repeatable reads. However, it is possible to read the Phantom, avoid the need to add table-level lock, Oracle default row-level lock. It is important to use Isolation_serializable's isolation level carefully in the spring-based thing configuration. This configuration uses table-level locks and has significant performance implications. Typically, there is no special need to configure the object isolation level to use the database default.

Dirty Read | non-repeatability | Understanding of Magic reading and five transaction isolation levels defined by spring

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.