当前位置:网站首页>Undo log details
Undo log details
2022-07-23 10:27:00 【Three three three】
Today I'd like to share with you Undo log Knowledge points of log
1. What is? undo log?
Undo log , Before the database transaction starts ,MYSQL Will record the data before the update to undo log In file . If the transaction rolls back or the database crashes , You can use undo log Log information recorded in the log is returned . At the same time, it can also provide reading under multi version concurrency control (MVCC).( Concrete MVCC See this blog for a detailed explanation of the implementation mechanism )
2.undo log Life cycle
undo log produce : Generate before the transaction starts
undo log The destruction : When the transaction is committed ,undo log It can't be deleted immediately , But put it in the list to be cleaned up , from purge The thread determines whether it is being used by other transactions undo Version information before the last transaction of the table in Section , Decide if you can clean up undo log The log space of .
Be careful : undo log Will also produce redo log,undo log We also need to achieve durable protection .
3. uodo log The role of logs
First of all, briefly undolog and redo log The difference between
undo log It's a logical log , Realize the atomicity of transactions
undo log Records are transactions [ Prior to the start ] Data status of , Record the value before update
undo log Realize the atomicity of transactions ( Provide rollback )
redo log It's a physical log , Achieve transaction persistence
undo log Records are transactions [ After completion ] Data status of , What is recorded is the updated value
undo log Achieve transaction persistence ( Ensure data integrity )
1.undo log Logging can realize the rollback of transactions
When we update the data , Not only will it record redo log, And record undo log, If the transaction is rolled back for some reason , So at this point MySQL You have to roll back (rollback) operation , utilize undo log Restore the data to the state before the transaction started .
If we execute the following deletion statement :
delete from book where id = 1;
So at this time undo log Will generate a contrary insert sentence 【 Reverse operation statement 】, When transaction rollback is required , Directly implement this article sql, The data can be completely restored to the data before modification , So as to achieve the purpose of transaction rollback .
Another example is that we execute a update sentence :
update book set name = " three countries " where id = 1; --- Before the change name= Journey to the west
here undo log It's going to record the opposite update sentence , as follows :
update book set name = " Journey to the west " where id = 1;
If the modification is abnormal , have access to undo log Log to implement rollback operation , To ensure the consistency of transactions .
2.undo log Realize multi version concurrency control MVCC
Concrete MVCC See this blog for a detailed explanation of the implementation mechanism
4. uodo log How it works

As shown in the figure above :
When a transaction A Carry out a update operation , take id=1 Modified into id=2. First of all, it will change buffer pool Cache data in , At the same time, the old data will be backed up to undo log buffer in , What is recorded is the restore operation sql sentence . At this point, if the transaction B To query the modified data , But the business A Not yet submitted , The transaction B It will start from undo log buffer in , Query transaction A Modify the previous data , That is to say id=1. here undo log buffer Will persist data to undo log In the log ( Plate dropping operation ).undo After log persistence , Will actually write data to disk , That is to write ibd In the file of . Finally, the transaction submission will be executed .
5. uodo log The storage mechanism of
The specific parameter storage form is shown in the above figure
6. uodo log Configuration parameters for
innodb_max_undo_log_size: undo The maximum number of log files , Default 1GB, Initialization size 10M
innodb_undo_log_truncate: Identify whether auto shrink is on undo log Operation of table space
innodb_undo_tablespaces: Set the number of independent tablespaces , The default is 0, Flag does not open independent tablespaces ,undo The log is kept in ibdata1 in
innodb_undo_directory: undo Directory location of log storage
innodb_undo_logs: Number of rollback Default 128
边栏推荐
- Use reflection to modify the member variable whose modifier is final
- SSH超市进销存管理系统
- Self organization is the two-way rush of managers and members
- Kingbasees SQL language reference manual of Jincang database (8. Function (III))
- 使用MindStudio的X2MindSpore工具进行训练脚本转换
- 金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(二))
- c# 字节数组和类相互转换
- Evidence based design of RF circuits
- Illustration and text demonstrate the movable range of the applet movable view
- ARP Spoofing protection of network security
猜你喜欢

Network communication principle and IP address allocation principle. The seven layers of the network are physical layer, data link layer, network layer, transmission layer, session layer, presentation

redis伪集群一键部署脚本---亲测可用

浏览安全怎么提升?教你设置安全浏览器信任站点

How to add an operator in ONEFLOW

ARP Spoofing protection of network security

宇视NVR设备接入EasyCVR平台,离线后无法上线该如何解决?

31-spark的算子使用及调度流程

IDEA 集成 Sonar 完整流程

Illustration and text demonstrate the movable range of the applet movable view

Special training - linked list
随机推荐
RTC 性能自动化工具在内存优化场景下的实践
隐适美invisAlign口扫转诊方式(导出口扫数据+线上问诊)
1. Assignment statement
Redis token record user login design solution?
[c #] IEnumerable enumerable type interface analysis yield
LeetCode每日一题(1946. Largest Number After Mutating Substring)
Bosch Bosch EDI project case
22. Notes on the use of combobox in WPF
两个海量数据的同构表,如何查询数据差异
One of the series of composition principle analysis, the design principle of composition
Use and implementation of enumeration classes
大专码农和 985 程序员有什么区别?
ssm框架外卖订餐系统
How to improve browsing security? Teach you to set up a secure browser trust site
金仓数据库 KingbaseES SQL 语言参考手册 (4. 伪列)
Normal form and anti normal form
C語言——幾道C語言經典習題
EasyCVR平台升级到最新版本v2.5.0,如何同步mysql数据库?
使用MindStudio的X2MindSpore工具进行训练脚本转换
C language file operation
