当前位置:网站首页>Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
2022-07-31 03:18:00 【Kong Tom】
One.binlog writing mechanism
Execution logic:
- Transaction execution, first write the logto binlog cache,
- write the binlog cache when the transaction is committedinto the binlog file
binlog cache
- The system binlog cache allocates a piece of memory, one per thread
- Parameterbinlog_cache_size is used to control the size of the memory occupied by the binlog cache in a single thread
- If exceeds the size specified by this parameter, it will be temporarily saved to disk
When the transaction commits:
- The executor writes the complete transaction in the binlog cache into the binlog and clears the binlog cache
2. Redo log writing mechanism
Three states of redo log:
- Exist in redo log buffer, physically in MySQL process memory
- Writing on disk (write), but not persistent (fsync), physically in the page cache of the file system
- Persist to disk, corresponding to hard disk
There is a problem:
The log is written to the redo log buffer very quickly, and the write to the page cache is similar, but the speed of persistence to the disk is very slow
innodb_flush_log_at_trx_commit parameter
0 | Indicates that the redo log is left in the redo log buffer every time a transaction is submitted |
1 | Indicates that the redo log will be persisted directly to disk every time a transaction is committed |
2 | Indicates that only the redo log is written to the page cache every time the transaction is committed |
- InnoDB has a background thread that will send redo the log in the log buffer, call write to the page cache of the file system with write, then call fsync to persist to disk
- The redo log of the intermediate process of transaction execution is also directly written in the redo log buffer
- May also be persisted to disk by background threads.
- A redo log of a uncommitted transaction may have been persisted to disk.
Three. Two scenarios where the uncommitted redo log is written to disk:
- When the space occupied by the redo log buffer is about to reach half of innodb_log_buffer_size, the background thread will actively write to the disk
- When a parallel transaction is committed, the redo log buffer of this transaction is persisted to disk by the way
Two-phase commit:
In terms of timing, redo logprepare first, then write binlog and then redo log commit
Group commit mechanism
边栏推荐
猜你喜欢
Multilingual settings of php website (IP address distinguishes domestic and foreign)
[Compilation principle] Lexical analysis program design principle and implementation
SQL injection Less54 (limited number of SQL injection + union injection)
【动态规划】连续子数组的最大和
Chapter 9 SVM实践
How to develop a high-quality test case?
10. Redis implements likes (Set) and obtains the total number of likes
Chapter 9 SVM Practice
The simulation application of common mode inductance is here, full of dry goods for everyone
IDEA comment report red solution
随机推荐
TCP/IP four-layer model
注解用法含义
编译Hudi
Difference between unallocated blocks and unused blocks in database files
Chapter 9 SVM实践
The els block moves the boundary to the right, and accelerates downward.
测试中的误报和漏报同样的值得反复修正
数据库文件中的未分配的块和未使用的块的区别
冒泡排序、选择排序、直接插入排序、二分法查找
【HCIP】ISIS
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
Detailed explanation of TCP and UDP
Atomic operation CAS
Point Cloud DBSCAN Clustering (MATLAB, not built-in function)
自己的一些思考
Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
2022牛客多校联赛第四场 题解
Project (5) - Small target detection tph-yolov5
选好冒烟测试用例,为进入QA的制品包把好第一道关
IDEA comment report red solution