当前位置:网站首页>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
边栏推荐
- Write an interface based on flask
- Material design component - use bottomsheet to show extended content (II)
- R language [data management]
- js常用方法封装
- 五层网络协议
- EasyExcel的讀寫操作
- 【日常训练】729. 我的日程安排表 I
- Is Kai Niu 2980 useful? Is it safe to open an account
- 让开发效率飞速提升的跨端方案
- SQL series (basic) - Chapter 2 limiting and sorting data
猜你喜欢
leetcode:1139. The largest square bounded by 1
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
秋招将临 如何准备算法面试、回答算法面试题
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
R语言【数据管理】
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
示波器探头对信号源阻抗的影响
Longest swing sequence [greedy practice]
LeetCode_ Hash table_ Difficulties_ 149. Maximum number of points on the line
最长摆动序列[贪心练习]
随机推荐
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
postgis 安装地理信息扩展
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
让开发效率飞速提升的跨端方案
AITM 2-0003 水平燃烧试验
Écrire une interface basée sur flask
hdu2377Bus Pass(构建更复杂的图+spfa)
【案例】定位的运用-淘宝轮播图
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
POJ 3414 pots (bfs+ clues)
AITM2-0002 12s或60s垂直燃烧试验
JS common method encapsulation
Five layer network protocol
Postgres establish connection and delete records
bazel是否有学习的必要
selenium 获取dom内验证码图片
Utils/index TS tool function
Modifiers of attributes of TS public, private, protect
概率论机器学习的先验知识(上)
PHP deserialization +md5 collision