当前位置:网站首页>Implementation principle of acid in MySQL
Implementation principle of acid in MySQL
2022-07-24 09:39:00 【liuyunshengsir】
1. Atomicity (Atomicity)
Atomicity refers to the fact that a transaction is an indivisible unit of work , Either do all of them , Either not .
Realization and utilization of atomicity Innodb Of undo log. undo log Called rollback log , Is the key to atomicity , When the transaction is rolled back, all successfully executed sql sentence , He needs to record the corresponding log information you want to roll back .
for example
(1) When you delete When a piece of data , We need to record the information of this data , When rolling back ,insert This old data
(2) When you update When a piece of data , You need to record the old values before , When rolling back , According to the old value update operation
(3) That year insert When a piece of data , You need the primary key of this record , When rolling back , Execute according to the primary key delete operation
undo log Record the information needed for rollback , When the transaction fails or calls rollback, Causes the transaction to be rolled back , You can use undo log The information in rollback the data to what it looked like before the modification .
2. Isolation, (Isolation)
Isolation refers to the concurrent execution of multiple transactions , Operations within a transaction are isolated from other transactions , Transactions that execute concurrently cannot interfere with each other .
The implementation of isolation uses locks and MVCC Mechanism .MVCC, Multi version concurrent control (Multi Version Concurrency Control), A row record data has multiple versions of snapshot data , The snapshot data is in undo log in . If a row read by a transaction is in progress DELELE perhaps UPDATE operation , The read operation does not wait for the lock on the line to release , Instead, read the snapshot version of the row .
Read committed at transaction isolation level (Read Commited) when , One transaction can read the submitted data of another transaction , Is not satisfied with isolation . But when the transaction isolation level is repeatable (Repeateable Read) in , Is to meet the isolation of .
3. persistence (Durability)
Persistence is when a transaction is committed , Its changes to the database should be permanent . Subsequent operations or failures should not have any impact on it .
Implementation and utilization of persistence Innodb Of redo log( Redo log ). As I said before ,Mysql First, load the data on the disk into the memory , Modify data in memory , Swipe it back on the disk . If the machine goes down suddenly , Data in memory will be lost .
3.1 How to solve this problem ?
Simple , Just write the data to disk directly before the transaction is committed .
3.2 What's the problem with this ?
Modify only one byte of a page , Just swipe the entire page into disk , It's a waste of resources . After all, a page 16kb size , You just change a little bit of it , will 16kb The contents of the brush into the disk , It doesn't make sense .
After all, in a business SQL Modification of multiple data pages may be involved , And these data pages may not be adjacent , It's random IO. Obviously the operation is random IO, The speed will be slow .
use redo log Solve the above problems . When data is modified , Not only in memory , Also in the redo log Record this operation . When the transaction is committed , Will redo log Brush the logs (redo log Part of it is in memory , Part of it is on disk ). When the database is down and restarted , Will redo log The content in is restored to the database , According to undo log and binlog Content determines whether to roll back data or submit data .
3.3 use redo log The benefits of ?
redo log Compared with the data page, the efficiency of disk brushing is higher , The specific performance is as follows :
- redo log Small volume , After all, it only records which page has been modified and what , So it's small , Brush the disc quickly .
- redo log It's going all the way to the end , It belongs to order IO. Efficiency is obviously better than randomness IO Come fast .
4. Uniformity (Consistency)
Consistency refers to before and after transaction execution , Data is in a legal state , This state is semantic rather than grammatical . This state is to satisfy a predetermined constraint, which is called a legal state , A little more general , This state is defined by you . Satisfy this state , The data is consistent , Not satisfied with this state , The data is inconsistent !
Mysql How to ensure consistency ?
From the database level , Database through atomicity 、 Isolation, 、 Persistence to ensure consistency . in other words ACID Among the four characteristics ,C( Uniformity ) It is purpose ,A( Atomicity )、I( Isolation, )、D( persistence ) It's the means , To ensure consistency , The means provided by the database . Database must be implemented AID The three major characteristics , It's possible to achieve consistency .
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 .
Pay attention to me and receive my mysql Brain map

边栏推荐
- 2021 robocom world robot developer competition - undergraduate group (Preliminary) problem solution
- 分类与回归的区别
- What are the 6% annualized products?
- 配置系统环境变量的时候误删了Path怎么办?
- Embedded development: Tools - optimizing firmware using DRT
- Spark Learning: implement compact table command
- PHP Basics - PHP super global variables
- 2022 trusted cloud authoritative assessment released: Tianyi cloud has obtained ten certifications and five best practices
- What if path is deleted by mistake when configuring system environment variables?
- [Luogu p5829] [template] mismatch tree (string) (KMP)
猜你喜欢

缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
![[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)](/img/0d/c8042ce5019d7dc5414dde5ebf1e8d.jpg)
[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)

Tang Yudi opencv background modeling

Open source summer interview | learn with problems, Apache dolphin scheduler, Wang Fuzheng

Leetcode skimming: dynamic planning 03 (climb stairs with minimum cost)

ASI-20220222-Implicit PendingIntent

Common evaluation indexes of medical image segmentation

《动手学深度学习》(七) -- 边界框和锚框

What if path is deleted by mistake when configuring system environment variables?

Racecar multi-point navigation experiment based on ROS communication mechanism
随机推荐
Hands on deep learning (VII) -- bounding box and anchor box
(5) Cloud integrated gateway gateway +swagger documentation tool
[200 opencv routines] 236. Principal component analysis of feature extraction (openCV)
Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
IdentityServer4入门
RxJS Beginner Guide
We were tossed all night by a Kong performance bug
Friends come to interview a unicorn company in Beijing at leisure. The interview question is priced at 25K
Li Kou 300 longest increasing subsequence dynamic programming
Dorissql syntax Usage Summary
Spark Learning: using RDD API to implement inverted index
Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro
At the moment of the epidemic, we need to work harder, aoligui
Color recognition of regions of interest in pictures and videos based on OpenCV
[don't bother to strengthen learning] video notes (III) 3. SARS (lambda)
Getting started with web security - open source firewall pfsense installation configuration
Linked list - 24. Exchange nodes in the linked list in pairs
[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)
Jenkins post build script does not execute
How to improve office efficiency through online collaborative documents