(A), the concept of transaction

First, what is a transaction?

The concept: the transaction is to a series of actions as a single unit of work, these actions are either completed or not completed all, to ensure the consistency and integrity of data.

Second, the four characteristics of the transaction: referred to as ACID

1, atomicity (atomicity): the transaction is an atomic operation, consisting of a series of operations, the operation to ensure atomicity of transactions either completed or fail.

2, consistency (consistency): Transaction in accordance with the expected entry into force of the business, to ensure data consistency before and after the transaction, such as transfers, and reduce the total number of transactions increased around the same amount.

3, isolation (isolation): no interference between the transaction, to prevent data corruption.

4, permanent (durability): Affairs once submitted, the entry into force of the data is permanent.

Three, four transaction isolation levels: from low to high was the Read Uncommitted, the Read committed, Repeatable the Read, Serializable, four levels can be solved one by one dirty reads, non-repeatable read, phantom read these types of problems.

 

Read uncommitted (read the contents of uncommitted): Transaction lowest isolation level, it makes outside the allowable charge a transaction can see the data that uncommitted transactions. This isolation level will have dirty reads, non-repeatable reads and phantom reads.

Read committed (read submission): to ensure that after a transaction modifies the data submitted in order to be read by another transaction. Another transaction can not read the uncommitted transactions. This isolation level the question arises - non-repeatable read (Nonrepeatable Read): may see different results when we perform non-repeatable read means exactly the same select statement in the same transaction.

The reasons for this may be:

  (1) has a cross new transaction commit, results in a change of data;

  (2) When a database is operating multiple instances, other instances of the same transaction in this example may have a new process during commit.

Repeatable read (can be reread): This transaction isolation levels prevent dirty reads, non-repeatable reads. But the phantom read may occur. This is the default MySQL transaction isolation level, it ensures that the same transaction multiple concurrent instances when data is read, it will see the same data row. Problems may arise at this level - Magic Reading (Phantom Read): When you read a range of data row, another transaction and insert a new row within the range, when the user re-read the range of data rows when, you will find a new "Phantom" line.

Serializable (serializable): This is the most expensive, but the cost of the most reliable transaction isolation level. The transaction is processed as a sequential execution. Sort by forcing it matters, making it impossible to conflict with each other, so as to solve the problem phantom read. In short, it is to add a shared lock on each row of data read. At this level, it could lead to a lot of timeouts and lock contention .

Four, seven kinds of transaction propagation behavior: how to describe the propagation of transaction modified by the propagation of a certain transaction methods are nested into another transaction propagation method.

1, PROPAGATION_REQUIRED : If no transaction creates a new transaction, if the current transaction exists, joined the transaction, the setting is the most common settings.

 

2, PROPAGATION_SUPPORTS : support for the current transaction, if the current transaction exists, joined the transaction, if the transaction does not currently exist, to perform non-transactional. '

 

3, PROPAGATION_MANDATORY : support for the current transaction, if the current transaction exists, joined the transaction, if the transaction does not currently exist, an exception is thrown.

 

4, PROPAGATION_REQUIRES_NEW : create a new transaction, regardless of the current deposit transaction does not exist, creates a new business.

 

5, PROPAGATION_NOT_SUPPORTED : performed in non-transactional mode operation, if the current transaction exists, put the current transaction pending.

 

6, PROPAGATION_NEVER : to perform non-transactional way, if the current transaction exists, an exception is thrown.

 

7, PROPAGATION_NESTED : If the current transaction exists, it is executed within nested transactions. If no transaction with PROPAGATION_REQUIRED similar operation is performed.

Guess you like

Origin www.cnblogs.com/dwxblogs/p/10963906.html