当前位置:网站首页>The principle and related problems of acid in MySQL
The principle and related problems of acid in MySQL
2022-07-01 00:22:00 【ordinaryBlog】
Business
The nature of transactions
Atomicity A
The whole database transaction is an inseparable work unit , Only when all database operations in the transaction are executed successfully , Business is a success
Uniformity C
Consistency refers to a transaction that moves a database from one state to the next , The transaction must be in a consistent state before and after execution
Isolation, I
Transaction isolation requires that the read / write objects of each transaction can be separated from the operation objects of other transactions , That is, it is invisible to other transactions before committing
persistence D
Once the transaction is committed, the result is permanent , Even in case of database downtime and other failures, the data can be recovered .
InnoDB How to achieve ACID
Atomicity
InnoDB utilize undo log( Rollback log ) To achieve atomicity of transactions , When the transaction is rolled back, all successfully executed SQL sentence .undo log It records the information before the data is modified, as well as the newly added and deleted data information .
such as :
- When deleting a piece of data , We need to record the information of this data , When rolling back , Add this adjustment information
- When adding a new piece of data , You need to record the primary key of this data , When rolling back , Delete information according to the primary key
- When modifying a piece of data , The old value of this data needs to be recorded , Perform modification during rollback
persistence
InnoDB Take advantage of redo log( Redo log ) To achieve transaction persistence
When a record is updated ,InnoDB Will first write the record to redo log Inside , And update memory ,InnoDB It will be brushed into the disk at the appropriate time . When the database is down and restarted , Will redo log The content in is restored to the database , According to undo log and bin log Content determines whether to roll back data or submit data .
Isolation,
MySQL Through locks and MVCC Mechanism to achieve isolation
Isolation level
Read uncommitted Allow read of uncommitted data changes , Can cause dirty reading 、 Phantom or unrepeatable reading . No lock will be added to the reader . And writing will add exclusive lock , And release after the transaction ends .
Read the submission Allow to read data submitted by concurrent transactions , Can prevent dirty reading , But phantom or unrepeatable reads can still occur . Will pass MVCC Get the current data newest snapshot , No locks , And ignore any locks
Repeatable Multiple reads of the same field are consistent , Unless the data is modified by the transaction itself , Can prevent dirty and unrepeatable read , But phantom reading can still happen . Only in a transaction for the first time ****select It's time to build the version , All subsequent queries are performed on this version , So that Repeatable .
Serialization All reads and writes to the same data become mutually exclusive .
Dirty reading : When a transaction is accessing data and accessing it Read uncommitted data
** It can't be read repeatedly :** Between two reads of data in the first transaction , Due to the modification of the second transaction, the data read by the first transaction is different .
** Fantasy reading :** Unreal reading is similar to nonrepeatable reading , The first transaction reads several rows of data , Then another transaction inserts some data , In the subsequent query, the first transaction will find some more records that do not exist , It's like an illusion , So it's called Unreal reading
The difference between nonrepeatable reading and unreal reading
The point of non repeatable reading is modify , For example, reading a record many times and finding that the values of some columns in it have been modified , The point of fantasy reading is Add or delete , For example, read a record many times and find that the number of records increases or decreases .
MVCC
MVCC It refers to multi version concurrency control ,MVCC When accessing the database concurrently , Through multi version control of data, the blocking of read operation caused by write lock can be avoided , So as to optimize the concurrent blocking problem .
adopt undo log And consistency view , adopt undo log To save multiple versions of data , Save the list of currently active transactions through the consistency view .
For example, a value 1 It is changed into 2、3、4
Transactions started at different times have different views , In view A、B、C in The recorded values can be 1,2,3, That is, a record can have multiple versions in the system , This is multi version concurrency control .
Long transaction hazard
Long transactions mean that there will be a very old transaction view in the system . Since these transactions may access any data in the database at any time , So before this transaction is committed , All possible rollback records in the database must be kept , This can lead to a lot of storage space
Uniformity
- From the database level Database through atomicity 、 Isolation, 、 persistence , To ensure consistency . Atomicity 、 Isolation, 、 Persistence is a means to achieve consistency , Consistency is the ultimate goal
- From the application level , Through the code to determine whether the database data is valid , Then decide whether to roll back or commit the data
边栏推荐
- ABAQUS 2022 software installation package and installation tutorial
- Redis - sentinel mode
- Quick start of wechat applet -- project introduction
- shell 同时执行多任务下载视频
- [designmode] factory pattern
- 2022-2028 global 3D printing ASA consumables industry research and trend analysis report
- What is SRM system and how to standardize the internal procurement process of the company
- ABAQUS 2022 latest edition - perfect realistic simulation solution
- When is it appropriate to replace a virtual machine with a virtual machine?
- CentOS installation starts redis
猜你喜欢

SSM integration process (integration configuration, function module development, interface test)

CentOS install MySQL

女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!

2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report

20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking

Fh6908a negative pole turn off synchronous rectification analog low voltage drop diode control IC chip tsot23-6 ultra low power rectifier 1W power consumption < 100ua static replacement mp6908

2022-2028 global herbal diet tea industry research and trend analysis report

Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)

Development of wireless U-shaped ultrasonic electric toothbrush

2022-2028 global ethylene oxide scrubber industry research and trend analysis report
随机推荐
Teach you how to use Hal library to get started -- become a lighting master
2022-06-30:以下golang代码输出什么?A:0;B:2;C:运行错误。 package main import “fmt“ func main()
Wechat official account development (1) introduction to wechat official account
A detailed explanation of the implementation principle of go Distributed Link Tracking
Vulnerability discovery - App application vulnerability probe type utilization and repair
Basic knowledge of Embedded Network - introduction of mqtt
Combining online and offline, VR panorama is a good way to transform furniture online!
The full technology stack, full scene and full role cloud native series training was launched to help enterprises build a hard core cloud native technology team
2022-2028 global PTFE lined valve industry research and trend analysis report
CentOS install MySQL
New trend of embedded software development: Devops
ABAQUS 2022 software installation package and installation tutorial
Rust book materials - yazhijia Library
2022-2028 global plant peptone industry research and trend analysis report
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
8253A寄存器浅析
Is it safe to open a stock account of Huatai Securities online?
Software engineering best practices - project requirements analysis
Ybtoj exchange game [tree chain splitting, line segment tree merging]