分类: Mysql/postgreSQL
2014-08-24 14:59:29
1、 InnoDB存储引擎体系架构
(1).后台线程
默认,InnoDB后台线程有7个,4个IO thread, 1个master thread, 1个锁(lock)监控线程,1个错误监控线程
4个IO thread:insert buffer thread、log thread、read thread、write thread
(2)内存
缓冲池(buffer pool)、重做日志缓冲池(redo log buffer)、额外内存池(additional memory pool)
InnoDB把数据库文件按页(每页16k)读取到缓冲池,按最近最少使用算法保留缓冲池中缓存数据,数据库文件修改,首先修改缓冲池中页(胀页),按一定得频率刷新到文件
(3)master thread 源码分析
Void master_thread(){
Goto loop;
Loop:
For(int i=0;i<10;i++)
{
Thread_sleep(1);
Do log buffer flush to disk
If(last_one_second_ios<5)
Do merge at most 5 insert buffer
If(buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct)
Do buffer pool flush 100 dirty page
If(no user activity)
Goto background loop
}
If(last_ten_second_ios < 200)
do buffer pool flush 100 dirty page
do merge at most 5 insert buffer
do log buffer flush to disk
do full purge
if(buf_get_modified_ratio_pct > 70%)
do buffer pool flush 100 dirty page
else
buffer pool flush 10 dirty page
do fuzzy checkpoint
goto loop
background loop:
do full purge
do merge 20 insert buffer
if not idle:
goto loop:
else:
goto flush loop
flush loop:
do buffer pool flush 100 dirty page
if(buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct)
goto flush loop
goto suspend loop
suspend loop:
suspend_thread()
waiting event
goto loop;
}
(4)关键特性
插入缓冲
两次写
自适应哈希索引