当前位置:网站首页>Wal mechanism of MySQL
Wal mechanism of MySQL
2022-06-13 00:56:00 【-LM-】
MySQL Of WAL Mechanism
WAL Its full name is Write-Ahead Logging, Pre write log system . It mainly refers to MySQL When performing a write operation, it is not immediately updated to the disk , But first record it in the log , Then update to disk at the right time . Logs are mainly divided into undo log、redo log、binlog.
When the contents of memory data page and disk data page are inconsistent , We call this memory page “ Dirty page ”. After memory data is written to disk , Memory and disk data page content is consistent , be called “ Clean pages ”.
MySQL Really use WAL The reason is that : Disk writes are random IO, Comparative consumption performance , So if you write every update operation first log in , Then it becomes a sequential write operation , The actual update operation is performed by the background thread according to log Asynchronous write . So for client End , The delay is reduced . also , Since the sequential write probability is within a disk block , This produces IO The number of times is also greatly reduced . therefore WAL The core of is to transform random writing into sequential writing , Reduced client latency , Improved throughput .
Undo log( Logical log )
undo log revoke , Roll back . When a transaction is rolled back or the database crashes , You can use undo log The impact of undoing uncommitted transactions on the database .
undo log Produce and destroy : Generated before the start of a transaction ; When a transaction is committed , It's not going to be deleted immediately undo log,innodb Will correspond the thing to undo log Put it in the delete list , Later, through the background thread purge thread To recycle .undo log Logical log , Record a process of change . For example, execute a delete sentence ,undo log Will record a insert.
undo log Storage :undo log Manage and record in the way of segments . stay innodb The data file will contain a rollback segment Rollback segment , It contains 1024 individual undo log paragraph .
undo log The role of
- Realize the atomicity of transactions
- Realize multi version concurrency control (MVCC): Before the transaction is committed ,undo log Saved uncommitted previous version data ,undo log The data in can be used as a snapshot of the old version of data for other concurrent transactions to read , It's equivalent to doing A backup .

Redo log
redo log Ensure the atomicity and persistence of transactions , yes InnoDB Engine specific , Records changes to data in transactions . One SQL modify , It will produce a set of redo log Information ( Including a lot of ), This group is the writing redo log The smallest unit of . When the data is written to the disk redo log Information can be released .
Use redo log The benefits of
- It guarantees the data persistence .
- redo log Only changes to the data are recorded , The data is much smaller than a page of data , Greatly reduced IO frequency .
- redo log Is written sequentially , The modified disk is written randomly .
Redo log working principle
redo log It's a product of the persistence of transactions . Prevent at the point of failure , There are dirty pages not written to the table IBD In file , It's restarting MySQL When , according to redo log To redo , So as to achieve the feature of persistence of transaction's non disk data . If you persist directly to disk , Each commit transaction is persisted to disk , This will increase IO frequency , Reduce efficiency . Persist to redo log And on the disk IO operation , But persistent to redo log Is continuous write , The disk is random , So we use redo log More efficient .
Redo Log Write mechanism
Redo log The contents of the file are written to the file in a sequential loop , When full, it goes back to the first file , Write overlay . There are two pointers inside .
write pos Record the current position , Move back as you write , Write to the end of the last file and go back to 0 The beginning of file No .
checkpoint Is the current location to erase , It's also going back and forth , Before erasing a record, update the record to a data file .
write pos and checkpoint The empty part in the middle can be used to record new operations . If the two coincide , The certificate is full , Cannot perform new update operation , You need to erase some records first .
边栏推荐
- [buglist] serial port programming does not read data
- [North Asia server data recovery] data recovery case of Hyper-V service paralysis caused by virtual machine file loss
- Dynamic planning - good article link
- What is the difference between pytorch and tensorflow?
- [JS component] create a custom horizontal and vertical scroll bar following the steam style
- Liu Hui and introduction to nine chapter arithmetic and island arithmetic
- @Disallowcurrentexecution prevents quartz scheduled tasks from executing in parallel
- Arduino uses esp8266+ lighting technology + Xiaoai audio to realize voice control switch
- Aof persistence
- Arduino controls tb6600 driver +42 stepper motor
猜你喜欢

什么是 Meebits?一个简短的解释

What is pytorch? Explain the basic concepts of pytorch

How many rounds of deep learning training? How many iterations?

高阶极点对于波形的影响

Deep learning model pruning

How to determine whether T is a value type in a generic type or a reference class- How to determine whether T is a value type or reference class in generic?

Opencv desaturation

Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing

Download nail live playback through packet capturing

How to solve the duplication problem when MySQL inserts data in batches?
随机推荐
Arduino interrupt
Kotlin coroutine suspend function suspend keyword
【北亚服务器数据恢复】虚拟机文件丢失导致Hyper-V服务瘫痪的数据恢复案例
[North Asia server data recovery] data recovery case of Hyper-V service paralysis caused by virtual machine file loss
Canvas airplane game
Cards are unpredictable
Undirected graph -- computing the degree of a node in compressed storage
What is the difference between pytorch and tensorflow?
[JS] battle chess
Mongodb array operation
三栏简约typecho主题Lanstar/蓝星typecho主题
Traditional machine learning classification model predicts the rise and fall of stock prices
.net core 抛异常对性能影响的求证之路
[backtrader source code analysis 7] analysis of the functions for calculating mean value, variance and standard deviation in mathsupport in backtrader (with low gold content)
Maybe we can figure out the essence of the Internet after the dust falls
Build your own PE manually from winpe of ADK
Druid reports an error connection holder is null
深度学习训练多少轮?迭代多少次?
刘徽与《九章算术》《海岛算经》简介
[JS component] simulation framework