Preliminary study of affairs

1. What is a transaction

A transaction is a unit of concurrency control and a sequence of operations defined by the user. These operations are either performed or not performed, and they are an inseparable unit of work.

2. Characteristics of transactions

①Atomicity: Indicates that the transaction is indivisible, either all succeed or fail
②Consistency: It means that after the transaction is completed, some integrity constraints of the database are required to be satisfied. That is, the transaction either succeeds, or fails, and fails. The previous operation should be rolled back.
③Isolation: It means that a transaction is opened and cannot be affected by other transactions.
④Persistence: It means that the transaction cannot be aborted after it has started. After the transaction is committed, the data should be serialized to the database

3. Transaction isolation level

①read uncommitted: read uncommitted, that is, a transaction can read the data of another uncommitted transaction.
②read committed: read committed, that is, before the modification made by a transaction is not committed, other transactions cannot read the modified data Yes, oracle's default isolation level is read committed
③repeatable read: repeatable read, the structural results of multiple queries of the same transaction are consistent, mysql's default isolation level is repeatable read
④serialzable: serializable, that is, multiple threads ( Transactions) are completely non-concurrent and executed serially. Of course, there will not be any isolation problems. Obviously, the efficiency is also the lowest. Generally, .

4. The transaction does not consider the isolation level, resulting in three read problems and solutions

isolation level
dirty read
non-repeatable read
virtual reading
read uncommitted
Yes
Yes
Yes
read committed
no
Yes
Yes
repeatable read
no
no
Yes
Serializable
no
no
no
5. Propagation characteristics of transactions—
spread behavior significance
PROPAGATION_MANDATORY Indicates that the method must run within a transaction. Throws an exception if no transaction is currently taking place
PROPAGATION_NESTED Indicates that if a transaction is currently in progress, the method should run in a nested transaction. Nested transactions can be committed or rolled back independently of the enclosing transaction. If the encapsulating transaction does not exist, behaves like PROPAGATION_REQUIRES.
PROPAGATION_NEVER Indicates that the current method should not run within a transaction. If a transaction is in progress, an exception will be thrown.
PROPAGATION_NOT_SUPPORTED Indicates that the method should not be run within a transaction. If an existing transaction is in progress, it will be suspended for the duration of this method.
PROPAGATION_SUPPORTS Indicates that the current method does not require a transactional context, but can run within a transaction if it is already running.
PROPAGATION_REQUIRES_NEW Indicates that the current method must run in its own transaction. A new transaction will be started and if there is an existing transaction running, it will be suspended for the duration of this method.
PROPAGATION_REQUIRES Indicates that the current method must run within a transaction. If an existing transaction is in progress, the method will run in that transaction, otherwise a new transaction will be started.

6. How to ensure transaction consistency in SOA

①Two-phase commit

②Compensation mechanism of transaction: Compensation transaction is a way to implement business reverse operation transaction on the business side to ensure the consistency of business data

③ Ali's GTS

For details, see:
Two-Stage
Compensation
GTS

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325927143&siteId=291194637