当前位置:网站首页>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
边栏推荐
- 下载jar包的好地方
- Getting Started with CefSharp - winform
- CloudCompare & PCL calculate the degree of overlap between two point clouds
- IDEA comment report red solution
- 【HCIP】ISIS
- 遗留系统的自动化策略
- 6. Display comments and replies
- With 7 years of experience, how can functional test engineers improve their abilities step by step?
- 观察者模式
- Detailed explanation of TCP (3)
猜你喜欢
Installation of mysql5.7.37 under CentOS7 [perfect solution]
TCP详解(一)
【C语言】预处理操作
VS QT - ui does not display newly added members (controls) || code is silent
[Android] Room - Alternative to SQLite
LeetCode简单题之找到和最大的长度为 K 的子序列
C#远程调试
[Compilation principle] Design principle and implementation of recursive descent parsing
[Dynamic programming] Maximum sum of consecutive subarrays
Graphical lower_bound & upper_bound
随机推荐
Observer pattern
Day32 LeetCode
IIR滤波器和FIR滤波器
大小端模式
SQALE 是什么
some of my own thoughts
return in try-catch
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
品牌广告投放平台的中台化应用与实践
TCP和UDP详解
Chapter 9 SVM Practice
TCP详解(一)
endian mode
What is SQALE
【HCIP】ISIS
TCP详解(三)
VS QT - ui does not display newly added members (controls) || code is silent
What is distributed and clustered?What is the difference?
The simulation application of common mode inductance is here, full of dry goods for everyone
解析小结—自用