基于mysql5.6的metadata lock的介绍
1、max_write_lock_count
5.6官方文档解释:
After this many write locks, permit some pending read lock requests to be processed in between. Write lock requests have higher priority than read lock requests.
默认值:
Default Value (64-bit platforms):18446744073709551615
2、串行serializability
3、metadata解析
为了保护表结构的完整性、元数据的一致性。
A metadata lock on a table prevents changes to the table’s structure. This locking approach has the implication that a table that is being used by a transaction within one session cannot be used in DDL statements by other sessions until the transaction ends.
事务不提交,metadata lock不会释放。
4、metadata lock分为 read lock和write lock,以write lock的优先级最高。
特殊情况:write lock pending的数量大于max_write_lock_count时,会优先选择发起的select 请求,即read lock优先。
总结:
select 和 DDL都会对表发起metadata lock 请求,分别是r锁和x锁,以ddl的x锁优先级最高;
metadata lock作用:为了保持元数据的一致性;
遵从事务的原子性,事务不提交,metadata lock不释放;(隐式、显式事务都会产生metadata lock)。
版权声明:本文为博主原创文章,未经博主允许不得转载