Source: Internet
What is a transaction
A transaction is a series of rigorous operations in an application, all of which must complete successfully or all changes made in each operation will be undone. That is, transactions are atomic, and a series of operations in a transaction will either all succeed or none will be done.
There are two ways to end a transaction: when all steps in the transaction have been successfully executed, the transaction commits. If one of the steps fails, a rollback occurs to undo all previous actions up to the beginning of the transaction.
The transaction of the ACID
Transactions have four characteristics: Atomicity, Consistency, Isolation and persistence. These four properties are referred to simply as ACID properties.
-
Atomicity. A transaction is the logical unit of work of a database in which all or none of the operations involved are performed.
-
Consistency. The result of the transaction execution must be to change the database from one consistent state to another. Therefore, a database is said to be in a consistent state when it contains only the results of successful transaction commits.If a failure occurs during the operation of the database system and some transactions are interrupted before completion, some of the changes made to the database by these unfinished transactions have been written to the physical database, then the database is in an incorrect state, or inconsistent state.
-
Isolation. The execution of a transaction cannot be interfered with by other transactions. That is, the operations and data used within a transaction are isolated from other concurrent transactions. Concurrent transactions cannot interfere with each other.
-
Sustainable. Also known as permanence, meaning that once a transaction is committed, its changes to the data in the database should be permanent. Subsequent operations or failures should not have any impact on the results of its execution.
Mysql has four isolation levels
Read Uncommitted
Read Committed
Repeatable Read (Repeatable Read)
Serializable
-
Drity Read: a transaction has updated a copy of data, and another transaction has Read the same copy of data. For some reason, the first transaction has rolled back, and the data Read by the second transaction is incorrect.
-
Non-repeatable read: Data inconsistency between two queries of a transaction. This may be because the original data updated by a transaction was inserted between the two queries.
-
Phantom Read: a transaction where the number of pens is inconsistent between two queries. For example, one transaction queries for rows and another transaction inserts new columns. The previous transaction will have unqueried columns in subsequent queries. An error is reported if data is inserted at this time and is inserted by another transaction.
Test Mysql isolation level
Set the isolation level of A to Read uncommitted
Set client A’s transaction isolation level to Read COMMITTED
Set isolation level of A to REPEATable Read
Set the isolation level of A to Serializable
Before I sent a [Meituan] Java post 154 interview questions of the article, did not analyze, next ready to release the analysis in the public account below (weekdays: interview questions analysis +IT interesting picture, weekend: IT interesting picture), use the fragmented time to see the interview questions analysis, continue to improve, quickly scan the two-dimensional code at the end of the article to pay attention to a wave.
, END,
The growth path of programmers
Though the road is long, the journey is sure to come
This article was originally posted on the wechat public account of the same name “The Growth of programmers”, reply to “1024” you know, give a thumbs up.
Reply [520] to receive the best learning method for programmers
Reply to [256] for Java programmer growth plans