MYSQL of ACID

Atomicity (Atomicity)

Atomicity refers to a transaction is an indivisible unit of work, which operate either do or do not do.

Isolation (Isolation)

Isolation means that when a plurality of transactions concurrently executing operations within a transaction are other transactions are isolated and can not interfere with one another concurrently executing various transactions.

Persistent (Durability)

Persistence refers to transactions once submitted, change its database should be permanent. The next operation or other faults should not have any effect on them.

Consistency (Consistency)

Consistency means before and after transaction execution, data in a legal state, this state is not the syntax on semantics. The state is to meet the predetermined constraint is called a legal state, then plainly, this state is up to you to define. Meet this state, the data is consistent, does not satisfy this condition, the data is inconsistent!

Mysql how to ensure consistency?

From the database level, the database by atomicity, isolation, durability to ensure consistency. That is among the four ACID properties, C (identity) is the goal, A (atomic), I (isolation), D (persistence) is the means, in order to ensure the consistency of the means, provided by the database. AID database must implement three major characteristics, be possible to achieve consistency. From the application level, database data is valid judgment through the code, and then decide to roll back or to submit data.

Mysql how to ensure atomicity?

Innodb use the undo log. undo log called rollback log, is key to achieving atomic, When Rollback can undo all the sql statement has been executed successfully, he needs to record the appropriate log information you want to roll back.

E.g

(1) When you delete a data when you need to record information on this data, the rollback of time, insert this old data
(2) When you update a data of the time, you need to log old before, back roll time, according to the old value to perform the update operation
time (3) then insert a piece of data, it requires a primary key of this record, roll back when the primary key to execute delete operation according to the undo log records the information rollback need, when transaction failed or call rollback, resulting in the need to roll back the transaction, you can use the information in the undo log data is rolled back to what it was before the modification.

Mysql how to ensure durability?

Innodb use of redo log (redo log).
As said before, Mysql is to first load the data on the disk into memory, modify the data in memory, disk painted on the back. If at this time suddenly goes down, data in memory is lost.
how to solve this problem?
Simple, ah, the data is written directly to disk before the transaction is committed on the line ah.
You do have any questions?
Only modify a page in a byte, it is necessary to brush the entire page into the disk, so a waste of resources. After all, a 16kb page size, you just change one little thing, we must be content 16kb brush into the disk, listening and unreasonable.
After all, a single transaction may involve modification of SQL multiple pages of data, and these data pages may not be contiguous, that is, are random IO. Obviously operate random IO, the speed will be slower.
  Using redo log to solve the above problems. As data modification time, not only in memory operations, this operation will be recorded in the redo log in. When the transaction commits, the redo log will log the brush plate (redo log part in memory, on the part of the disk). When the database is down restart, the contents will redo log is restored to the database, and then decide to roll back and undo log data based on content or submit binlog data.
The benefits of using the redo log?
Brush disk redo log page high data efficiency than the brush plate, embodied as
redo log small volume, after which only records what the modified pages, so small size, fast brush disc.
redo log that has to be added at the end, it belongs to the order of IO. Efficiency is clearly coming faster than random IO.

Mysql how to ensure the isolation of?

Use is MVCC locks and mechanisms.
MVCC, i.e., multi-version concurrency control (Multi Version Concurrency Control), a plurality of versions of data rows snapshot data, the snapshot data in the undo log in. If the line is doing a transaction reads DELELE or UPDATE operation, the read operation will not wait for the release of the lock on the line, but read the snapshot version of the row.

  When the reading has been submitted to the transaction isolation level (Read Commited), a transaction can read data from another transaction has been submitted, the isolation is not satisfied. However, when the transaction isolation level is repeatable read (Repeateable Read), the barrier properties are satisfied.

Guess you like

Origin www.cnblogs.com/zhangsanfeng/p/11693449.html