当前位置:网站首页>MySQL InnoDB Architecture Principle
MySQL InnoDB Architecture Principle
2022-07-05 21:09:00 【A little dog】
MySQL InnoDB Framework principle
1. Architecture analysis
InnoDB It is mainly divided into : Structure in memory and Structure on disk
The memory structure is mainly : Buffer Pool (change Buffer 、adaptive hash index) log buffer
The disk structure is divided into : Tablespaces and redo logs
Table space :InnoDB The data dictionary 、 Double write buffer 、 Modify cache 、Undo journal .
Redo log : What's stored is Log buffer Data flushed to disk .
(.idb、.frm、undo.log、( Double write buffer (doublewrite buffer), Failure recovery mechanism (crash recovery))、 Locking mechanism 、Redo.log、)
2. InnoDB The structure in memory
Buffer Pool、(Change Buuffer、Adaptive Hash Index Occupied memory belongs to Buffer Pool)、Log Buffer
2.1 Buffer Pool
Mysql The server 80% Of memory will be allocated to Buffer Pool.
InnoDB The minimum unit of data management in is page , Default per page 16KB.
Through a page linked list , Less pages accessed will pass through the cache pool LRU The algorithm is eliminated .
Realization LRU Linked list
But different from the normal linked list , The buffer pool chain table is divided into 2 part ,New sublist( Default occupation 5/8 The cache pool ) and Old sublist( Default occupation 3/8) The cache pool ( adopt innodb_old_blocks_pct modify , The default value is 37)
The newly read page will be added Old sublist, And if the Old sublist If you visit the page in times , Will move to New sublist The head of .
2.1.1 The page list is not full , Add a new page
2.1.2 Old sublist Page in Be visited here
2.1.3 The page list is full , Add a new page , Trigger LRU Algorithm
2.2 Change Buffer
To reduce nonclustered indexes ( Secondary indexes ), Each modification is written directly to disk , There will be a lot of frequent IO.
Change buffer take Not unique The operation of the auxiliary index page is cached . If the secondary index page is already in the cache , It can be modified directly ( There is no need to IO), If not , Save the changes to Change Buffer, So as to merge and write disk files regularly, such as .idb.
2.3 Adaptive Hash Index
Although database record storage is not used hash surface , However, adaptive hash index is used for page lookup in memory (AHI) The general time complexity is O(1), As a way to reduce query data ( Indexes ) Page method .
2.4 LogBuffer
Log Buffer yes Redo log (Redo log) Buffer in memory , The default is 16M
2.4.1 Log first strategy (Redo log The role of )
InnoDB The log first strategy is used , Before persisting data files , Ensure that transactions are recorded as Redo log Written to disk .
Problem description : After logging to the database , The corresponding transaction can be returned to the user , Indicates that the transaction is complete . actually , The data may only be modified in memory , Did not brush to disk . If the program is abnormal or fails , The data in memory will disappear .
solve the problem : InnoDB At this point through Redo log To ensure data consistency . Obviously, it is not realistic to record all redo logs . The checkpoint mechanism is introduced , Ensure that the log has been written to disk , The next reply starts from the checkpoint .
2.4.2 Recover data from downtime ( from Redo Log and Log Buffer)
When data is modified , Will write memory space first , And then write Log Buffer, Will be log buffer The log of changes recorded in is written to the physical disk redo log In file .
However, the downtime data is written into memory , But it is not stored in the physical storage structure . At this time, the checkpoint mechanism will be used checkPoint, take redo log The data in the file is loaded into redo log buffer In the memory . Let's talk about the latest data writing mysql Disk data file , To update the data .
3. InnoDB Physical disk structure
3.1 Table space
3.1.1 InnoDB The data dictionary
After creating a database and a table , You can see test Database directory .
db.opt file : Saved data test Default character set
t.frm file : Save the data dictionary information of the table
t.idb file : Table data and index ( initialization 96K, The default page is 16K)
3.1.2 Undo journal ( To achieve atomicity Transaction commit rollback , Realization MVCC)
MySQL Of MVCC( Multi version concurrency control ) rely on Undo Log Realization .Mysql Table space file of t.ibd The latest value of the stored record . Each record has a rollback pointer ( See the picture above Roll Ptr), Point to the last entry in the record Undo Record , And each one Undo The record will point to the previous one Undo Record .
Undo Log During the execution of a transaction , Transactions are persisted only after they are committed , If the transaction is rolled back Undo Log It will also delete .
3.1.3 Double write cache (Double-Write Buffer)
When InnoDB After the record is updated , Because the log first strategy will go first Log Buffer Write data in memory , And then write to disk Redo log in .
Then, before writing to the physical table disk, it will enter the double write cache , At this time, if the writing process fails ( For example, the machine power down or the operating system crashes ).
3.1.3.1 Error writing to double write cache
3.1.3.2 Error writing to physical table file
4. InnoDB ACID Model
4.1 Atomicity
Mainly through the transaction mechanism
COMMITHE ROLLBACK sentence ( adopt Undo log Realization )
4.2 Consistency
Consistency assurance
InnoDB Double write buffer for (double write buffer Consistency assurance of disk storage )
InnoDB The failure recovery mechanism of (Redo log Consistency guarantee of data submission ,Undo log Consistency guarantee of transaction submission ,bin log Ensure the consistency and persistence of master-slave data )
4.3 Isolation
Isolation,
The isolation level of the transaction
InnoDB Locking mechanism
4.4 Durability
Durability guarantee
redo log Cache to disk
double write buffer Double write cache guarantee Data to disk
bin log Ensure the consistency and persistence of master-slave data
Please correct me if there is any mistake
边栏推荐
- Selenium's method of getting attribute values in DOM
- 研學旅遊實踐教育的開展助力文旅產業發展
- Add ICO icon to clion MinGW compiled EXE file
- Influence of oscilloscope probe on signal source impedance
- 让开发效率飞速提升的跨端方案
- 国外LEAD美国简称对照表
- [case] Application of element display and hiding -- element mask
- leetcode:1139. The largest square bounded by 1
- EN 438-7 laminated sheet products for building covering decoration - CE certification
- 【案例】定位的运用-淘宝轮播图
猜你喜欢
Influence of oscilloscope probe on measurement bandwidth
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
MySQL deep paging optimization with tens of millions of data, and online failure is rejected!
[case] Application of positioning - Taobao rotation map
显示屏DIN 4102-1 Class B1防火测试要求
五层网络协议
LeetCode_哈希表_困难_149. 直线上最多的点数
【案例】元素的显示与隐藏的运用--元素遮罩
Introduction of ArcGIS grid resampling method
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
随机推荐
Influence of oscilloscope probe on measurement bandwidth
终端安全能力验证环境搭建和渗透测试记录
浅聊我和一些编程语言的缘分
Postgres establish connection and delete records
vant 源码解析之 utils/index.ts 工具函数
Determine the best implementation of horizontal and vertical screens
shell编程100例
100 cases of shell programming
判断横竖屏的最佳实现
Learning robots have no way to start? Let me show you the current hot research directions of robots
字典树简单入门题(居然是蓝题?)
Using webassembly to operate excel on the browser side
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
《SAS编程和数据挖掘商业案例》学习笔记# 19
示波器探头对测量带宽的影响
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
Selenium gets the verification code image in DOM
[case] Application of positioning - Taobao rotation map
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
Material design component - use bottomsheet to show extended content (II)