Open baiwfg2 opened 2 years ago
http://mysql.taobao.org/monthly/2020/04/02
增加SX 锁,SX模式是对X模式的一种优化,它与读操作的S模式兼容,但是多个SX锁之间是冲突的。
InnoDB读写锁实现的核心思想是避免使用pthread rwlock,而尽量使用原子操作+自旋的模式来实现加解锁,这样可以在低冲突的场景下,以尽量小的开销实现加解锁。遇到实在是冲突高的读写锁,再使用InnoDB条件变量实现等待。
InnoDB读写锁上的X锁所有权是可以在不同线程间转移的,主要用于支持Change Buffer的场景。Change Buffer是一棵全局共享的B+树,存储在系统表空间中。在读取二级索引Page的时候Change Buffer需要与二级索引Page进行合并,这时如果所有IO线程都在读取二级索引Page,将没有IO线程读取Change Buffer Page,因此Change Buffer Page的读取被放到单独的IO线程。而读取二级索引Page的时候,已经对Page加上了X锁,当在异步IO线程需要把Change Buffer合并到二级索引的Page的时候,必须在不解锁的情况下让异步线程获得Page的X锁,这就是X锁所有权转移需要实现的功能
rw_lock_t
, rw_lock_x_lock_func
, rw_lock_x_unlock_func
, rw_lock_x_lock_move_ownership
有加解锁的流程图
https://zhuanlan.zhihu.com/p/414816343 , 行锁分析
https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html
It is also worth noting here that conflicting locks can be held on a gap by different transactions. For example, transaction A can hold a shared gap lock (gap S-lock) on a gap while transaction B holds an exclusive gap lock (gap X-lock) on the same gap. The reason conflicting gap locks are allowed is that if a record is purged from an index, the gap locks held on the record by different transactions must be merged.
https://severalnines.com/blog/understanding-lock-granularity-mysql/ mysql 以前支持BDB,它有page-level locking
row-level locking has disadvantages too: one of them is that row-level locking usually takes up more memory than page-level or table-level locking, it’s also usually slower than page-level or table-level locks because the engine must acquire more locks
http://mysql.taobao.org/monthly/2018/06/01/ 翻译官方文章
讲Link_buf https://zhuanlan.zhihu.com/p/53037796
在脏页落盘以及checkpoint 推进的过程中,需要严格保证 redo 日志先落盘再刷脏页的顺序,在MySQL 8 之前,InnoDB 存储引擎严格的保证 MTR 写入 redo log buffer的顺序是按照 LSN 递增的顺序,以及 flush list 中的脏页按LSN递增顺序排序。 在多线程并发写入 redo log buffer 以及 flush list 时,这一约束是通过两个全局锁 log_sys_t::mutex 和 log_sys_t::flush_order_mutex 实现的
http://mysql.taobao.org/monthly/2015/03/02/ ,5.7.6 page flush 优化 优化自适应flush,避免checkpoint lsn 被覆盖,各bp的flush 要均衡
在recv_recover_page_func
-> recv_parse_or_apply_log_rec_body
,根据log type 来回放。它并没有做成PG那样的type 与replayFunc 间的映射表的形式
batch/bulk insert :
https://dba.stackexchange.com/questions/270906/mysql-insert-into-select-vs-bulk-inserts-performance https://stackoverflow.com/questions/5526917/how-to-do-a-batch-insert-in-mysql
get + lock unlock, leave
http://mysql.taobao.org/monthly/2017/05/01/ http://mysql.taobao.org/monthly/2020/08/04/
http://liuyangming.tech/07-2019/InnoDB-Lock.html https://bbs.huaweicloud.com/blogs/105346
btr_cur_search_to_nth_level
https://developer.aliyun.com/article/910248
http://mysql.taobao.org/monthly/2022/09/01/ https://developer.aliyun.com/article/910248 https://blog.csdn.net/weixin_43559761/article/details/122116114 lob::insert, lob::alloc_lob_page
https://segmentfault.com/a/1190000019899944
写操作序与提交操作序一致性 线程1:事务1 insert拿到新页, 事务2 delete, 归还page 线程2:trx 3 insert,发生在事务2 delete后,拿到相同的Page,比delete先提交(redo先写进全局buffer) 结果回放顺序是:线程1 insert -> 线程2 insert -> 线程1 delete,顺序错误
方法一:在delete时,getpage发现是写动作,设置pageCtr的写标志,等trx 3 想以写方式来getPage时,发现有人设置了write bit,于是只能等,这样trx 2 能先提交 trx2 提交后才恢复写标志
mtr_t::memo_push 这个函数分析下 type是怎么给的
https://planet.mysql.com/entry/?id=27130
如何证明一个线程加锁写4字节int,一个线程只读,会出问题? https://blog.csdn.net/D_Guco/article/details/100066985
https://bartoszmilewski.com/2014/10/25/dealing-with-benign-data-races-the-c-way/ https://bartoszmilewski.com/2020/08/11/benign-data-races-considered-harmful/
显示汇编各源码:gcc -c -g -Wa,-adlhn a.c
https://doordash.engineering/2021/04/01/examining-problematic-memory-with-bpf-perf-and-memcheck/
taobao mysql
https://blog.csdn.net/u011385940/article/details/120206427 taobao mysql 文章列表
test
可编 m_string-t dd_cache_t