Home > Database > Mysql Tutorial > Database - A brief discussion of four transaction isolation levels

Database - A brief discussion of four transaction isolation levels

黄舟
Release: 2017-03-13 16:46:52
Original
1332 people have browsed it

The database provides four transaction isolation levels. Different isolation levels are implemented using different lock classes.

Among the four isolation levels, Serializable is the highest level and Read Uncommited is the lowest. .
The default isolation level of most databases is: Read Commited, such as Sql Server, Oracle.
The default isolation level of a few databases is Repeatable Read, such as MySQL InnoDB storage engine
Even It is the lowest level, and the first type of lost update problem will not occur.
1. Dirty read (the transaction is not committed, read in advance): Dirty read means when a transaction is accessing data and the data is modified , and this modification has not yet been submitted to the database. At this time, another transaction also accesses this data and then uses this data.
2. Non-repeatable reading (inconsistency between two reads): refers to reading the same data multiple times within a transaction. Before this transaction ends, another transaction also accesses the same data. Then, between the two reads of data in the first transaction, due to the modification of the second transaction, the data read twice by the first transaction may be different. In this way, the data read twice within a transaction is different, so it is called non-repeatable read. For example, an editor reads the same document twice, but between reads the author rewrites the document. When the editor reads the document a second time, the document has changed. Raw reads are not repeatable. This problem can be avoided if editors can only read the document after the author has all finished writing.
3. Phantom read: refers to a phenomenon that occurs when transactions are not executed independently. For example, the first transaction modifies the data in a table, and this modification involves all data rows in the table. At the same time, the second transaction also modifies the data in this table. This modification inserts a row of new data into the table. Then, in the future, the user who operates the first transaction will find that there are still unmodified data rows in the table, as if a hallucination has occurred. For example, an editor changes a document submitted by an author, but when production merges their changes into the master copy of the document, it is discovered that the author has added new, unedited material to the document. This problem can be avoided if no one can add new material to the document until the editors and production department have finished working on the original document.
4. The first type of update loss (rollback loss):
When two transactions update the same data source, if the first transaction is submitted and the other transaction is revoked, then the first transaction will be The updates made by the firm were also cancelled. In other words, the latest transaction done by the first transaction is lost.
5. The second type of update loss (coverage loss):
The second type of update loss is a concurrency problem often encountered in practical applications. It is essentially the same type of concurrency problem as non-repeatable read. It is usually considered Considered as a special case of non-repeatable reads: when two or more transactions querythe same record and then each update the row based on the original query results, the second type of lost update will occur. Because each transaction is unaware of the existence of other transactions, the modifications made by the last transaction to the record will overwrite the committed updates made by other transactions to the record...
Supplement: Spring declaration based on metadata Sexual affairs:

Isolation Attributes supports a total of five transaction settings, the details are as follows:

l          DEFAULT 使用数据库设置的隔离级别 ( 默认 ) ,由 DBA 默认的设置来决定隔离级别 . 
l          READ_UNCOMMITTED 会出现脏读、不可重复读、幻读 ( 隔离级别最低,并发性能高 ) 
l          READ_COMMITTED  会出现不可重复读、幻读问题(锁定正在读取的行) 
l          REPEATABLE_READ 会出幻读(锁定所读取的所有行) 
l          SERIALIZABLE 保证所有的情况不会发生(锁表)
Copy after login

The focus of non-repeatable reading is to modify:
The same conditions, the data you have read, read it again and find that the value is different
The focus of phantom reading is to add or delete
Under the same conditions, the number of records read out for the first and second times is different

-------------------------- --------------------------------
Transaction propagation behavior type

Spring in TransactionDefinitionInterface specifies 7 types of transaction propagation behaviors,

They specify how transactions are propagated when transaction methods and nested calls to transaction methods occur:

Table 1 Transaction Propagation Behavior type

Transaction propagation behavior type
Description

PROPAGATION_REQUIRED
If there is no current transaction, create a new transaction. If there is already a transaction, add it to this transaction. This is the most common choice.

PROPAGATION_SUPPORTS
Supports the current transaction. If there is no current transaction, it will be executed in a non-transactional manner.

PROPAGATION_MANDATORY
Use the current transaction. If there is no current transaction, an exception will be thrown.

PROPAGATION_REQUIRES_NEW
Create a new transaction. If a transaction currently exists, suspend the current transaction.

PROPAGATION_NOT_SUPPORTED
Perform operations in a non-transactional manner. If a transaction currently exists, suspend the current transaction.

PROPAGATION_NEVER
Executed in a non-transactional manner, if a transaction currently exists, an exception will be thrown.

PROPAGATION_NESTED
If a transaction currently exists, it will be executed within the nested transaction. If there is no current transaction, perform similar operations to PROPAGATION_REQUIRED.

----------------------------------------------- -------------
Simple means no templates are needed. xhtml is the default, with some modules provided by struts2.
For example, it is possible to add <# to your form. ##form ...>

Mainly to facilitate interface warning and error message processing and page verification
Take a look at struts.properties
or

org/apache/struts2/default.properties
struts.ui.theme=xhtml  
struts.ui.templateDir=template  
struts.ui.templateSuffix=ftl  
你可以在struts.xml中添加
<constant name="struts.ui.theme" value="simple" />来修改这个参数
Copy after login
The last one, as the name suggests, is combined with css to process these contents. If you are a beginner, you don’t need to consider these. If you don’t want these template contents to affect your development, you can change it to simple.

If your page uses css layout and you want to use the enhanced functions of struts2, use css_xhtml to get a better user experience.


The above is the detailed content of Database - A brief discussion of four transaction isolation levels. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template