当前位置:网站首页>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
边栏推荐
猜你喜欢

Use of QML

华为分布式存储FusionStorage知识点总结【面试篇】

What is distributed and clustered?What is the difference?

C# remote debugging

Recursive query single table - single table tree structure - (self-use)

LeetCode简单题之找到和最大的长度为 K 的子序列

SIP Protocol Standard and Implementation Mechanism

STM32 problem collection

【Exception】The field file exceeds its maximum permitted size of 1048576 bytes.

With 7 years of experience, how can functional test engineers improve their abilities step by step?
随机推荐
False positives and false negatives in testing are equally worthy of repeated corrections
10. Redis implements likes (Set) and obtains the total number of likes
[Android] Room - Alternative to SQLite
Automation strategies for legacy systems
LeetCode中等题之分数加减运算
The distance value between two arrays of LeetCode simple questions
Is interprofessional examination difficult?Low success rate of "going ashore"?Please accept this practical guide!
数据库实现分布式锁
Select the smoke test case, and make the first pass for the product package entering QA
WebSocket Session is null
Key Technologies of Interface Testing
Ambiguous method call.both
Difference between unallocated blocks and unused blocks in database files
【动态规划】连续子数组的最大和
C primer plus study notes - 8, structure
点云DBSCAN聚类(MATLAB,非内置函数)
Several common errors when using MP
【C语言】预处理操作
some of my own thoughts
原子操作 CAS