mysql principle of acid

How to guarantee consistency 1.mysql?
PICS mysql to ensure consistent state of the data transaction, the transaction state is clearly consistent with the data we need to control the application layer, such as money transfer, a-10, and b + 5, then the data is certainly not consistent.
Therefore, the first: control logic to the application layer to ensure data consistency.
2. Because of atomicity innodb (a transaction operations either all succeed or all fail), isolation (direct operating transactions are isolated, independently of each other), durability (guarantee transactions submitted some success, will not be lost ), so in order to ensure data consistency.
How to guarantee the atomicity 2.mysql?
Therefore, the name of justice atomic atomic operations, ie either all succeed, or all fail, in fact, mysql in dealing with affairs, will first load data into memory to do if the content OK, will be written to disk while the operation will write the log, that is undo log,
if need to roll back, then only need to check undo log, you can restore the data
it can be interpreted as:
1) when you delete a data when you need to record this information of data, the rollback of time, insert this old data
when 2) when you update a data of the time, you need to log old before, rollback, to perform update operations based on the old value
3) then insert a data when you need the primary key of this record, roll back time, according to the master key to execute delete operation
when the insert, in fact, has been written is true, you can verify the ID found rollback auto_increment has increased; however after the rollback, It rolled back only data, but does not reduce the self-energizing ID.
Summary: undo log dependent atomic achieved, will be executed because each operation in the memory, then the execution result is written to undo log, the equivalent can be restored to the state before the transaction according undolog, ROLLBACK if so, may undolog rollback to ensure atomicity.

How persistent 3.mysql guarantee?
Persistent name suggests is persistent data that the authors modified data should be persisted to the database, because the process of modifying data execution is first performed in memory, so how to ensure that the data in memory will be able to persist to disk, which is the key to how to ensure durability.
mysql when executed in memory, the data will first page (page) memory accessible to the data page is typically 16kb, 16kb not to know that a small cell, after successful execution memory, the corresponding data page will redo log information is written to the data, and then commit the time when, from the redo log persisted to disk, redo log is actually disk + memory storage, so you can ensure sustainability. So when the server downtime is guaranteed redo log is not lost, so you can ensure that the data submitted is not lost.
The benefits of using the redo log?
1. ensures durability, prevent memory loss of data after downtime.
2.redo log is sequential io, io disk page data is random, so the first order of io persisted to the better, when the commit, just to refresh the random io.
3.redo log small volume, after which only records what the modified pages, so small size, fast brush disc.
4.mysql is how to ensure the isolation?
mysql ensure isolation of the first to set the isolation level is greater than readUncommit can, otherwise there is no barrier properties.
Isolation relies on to achieve a lock and mvcc.
For example, two transactions at the same time update, will be used to shoot his locks or table locks to isolation, if it is a write transaction, a read transaction, the other can only read data that has been read transaction commit, the data is not commit can not read, because reading the mvcc read transaction data snapshot, the snapshot data storage and undo log, so undo log data can also be used to provide a snapshot version, thus ensuring isolation.

Reference: https: //blog.csdn.net/fujiandiyi008/article/details/90056284

Published 10 original articles · won praise 0 · Views 145

Guess you like

Origin blog.csdn.net/weixin_37599299/article/details/103411518