The propagation of transaction isolation levels and locking mechanism

Transaction isolation level:

read_uncommitted
This is the lowest transaction isolation level, which many outside do not 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
guarantee a transaction modifies the data submitted in order to be read by another transaction. Another transaction can not read the uncommitted transactions. This transaction isolation level to avoid dirty read occurs, but may appear non-repeatable reads and phantom reads.

repeatable_read
This transaction isolation level prevents dirty reads, non-repeatable reads. But the phantom read may occur. In addition to ensuring that a transaction can not read data from another uncommitted transaction, but also to avoid the following situation to ensure the production (non-repeatable read).

serializable
This is the most expensive, but the cost of the most reliable transaction isolation level. The transaction is processed as a sequential execution. In addition to prevent dirty reads, non-repeatable read, but also avoids the phantom read.

MySQL's default mode: repeatable read.

Seven kinds of communication behavior: we use when SSH development projects, we usually set the transaction in the Service layer, then when we call a method Service layer, it can ensure that all of our database this method of execution the update operation remains in a transaction, the transaction layer on the inside of these methods invoked either all succeed, or all fail. Then the propagation characteristics of the transaction is also from here talking of.   If you are in this method your Service layer, in addition to calling a method Dao layer, but also call this class of other methods of Service, then call other methods Service when this transaction is how the provisions it I must ensure that I was out in my method of using this method with my own method in the same transaction, or if the guarantee consistency of things. The propagation characteristics of the transaction is to solve this problem, "the transaction is the spread of" In most cases we have to configure only one of them for a variety of propagation characteristics in Spring: PROPGATION_REQUIRED: this means is that when the CI I call the method when the service layer open a transaction (specific call that one way to begin to create a transaction, depending on your configuration aop), then when calling the other methods of service layer inside, if the current method produces transaction by transaction on the current method of generating, if not, create a new business.
 

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

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.

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.

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

PROPAGATION_NOT_SUPPORTED : performing an operation to a non-transactional way, if the current transaction exists, put the current transaction pending.

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

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

Lock mechanism
locks the computer is coordinating multiple processes or threads mechanism concurrent access to a resource. In the database, in addition to traditional computing resources (such as CPU, RAM, I / O, etc.) than contention, but also a data shared by many users for funding

source. How to ensure the consistency of concurrent data access, availability is a problem that must be solved for all database lock conflicts is an important factor affecting the performance of concurrent access to the database. From this perspective, the lock on the database

For particularly important, but also more complicated. In this chapter we focus on the features of MySQL locking mechanism, a common locking problems, as well as some of the ways to solve the problem MySQL lock or suggestions.

Mysql to use a lot of this locking mechanism, such as row locks, table locks, etc., read lock, write lock, are locked before doing the first operation. These locks are collectively referred to as pessimistic locking (Pessimistic Lock).

Guess you like

Origin www.cnblogs.com/dabrk/p/11791590.html