MySQL:slave 延迟一列 外键检查和自增加锁
延迟大,大事物。
表结构
image.png
无IO
image.png
SQL THREAD占用CPU 100%
image.png
二、pscak 采样采样30个点
外键检查 占70%
image.png
自增锁获取 占30%
image.png
三、自增锁获取逻辑逻辑如下其实也是innodb_autoinc_lock_mode参数的作用
switch(lock_mode){caseAUTOINC_NO_LOCKING://innodb_autoinc_lock_mode=2/*AcquireonlytheAUTOINCmutex.*/dict_table_autoinc_lock(m_prebuilt->table);break;caseAUTOINC_NEW_STYLE_LOCKING://innodb_autoinc_lock_mode=1注意这里没有break巧妙的完成了逻辑/*Forsimple(single/multi)rowINSERTs,wefallbacktotheoldstyleonlyifanothertransactionhasalreadyacquiredtheAUTOINClockonbehalfofaLOADFILEorINSERT...SELECTetc.typeofstatement.*/if(thd_sql_command(m_user_thd)==SQLCOM_INSERT||thd_sql_command(m_user_thd)==SQLCOM_REPLACE){dict_table_t*ib_table=m_prebuilt->table;/*AcquiretheAUTOINCmutex.*/dict_table_autoinc_lock(ib_table);/*Weneedtocheckthatanothertransactionisn'talreadyholdingtheAUTOINClockonthetable.*/if(ib_table->n_waiting_or_granted_auto_inc_locks){/*Releasethemutextoavoiddeadlocks.*/dict_table_autoinc_unlock(ib_table);}else{break;}}/*Fallthroughtooldstylelocking.*/caseAUTOINC_OLD_STYLE_LOCKING://innodb_autoinc_lock_mode=0触发DBUG_EXECUTE_IF("die_if_autoinc_old_lock_style_used",ut_ad(0););error=row_lock_table_autoinc_for_mysql(m_prebuilt);//这个函数上表上的自增锁if(error==DB_SUCCESS){/*AcquiretheAUTOINCmutex.*/dict_table_autoinc_lock(m_prebuilt->table);}break;default:ut_error;}
binlog row格式,innodb_autoinc_lock_mode=1 按理说不会触发row_lock_table_autoinc_for_mysql加自增锁。不知道什么原因。当前知道:
如果主库语句模式,从库innodb_autoinc_lock_mode=1 ,insert select 肯定会触发。
如果从库 innodb_autoinc_lock_mode=0 肯定会触发。
但是都不满足。疑惑。
四、方案删除外键
innodb_autoinc_lock_mode设置为2,从逻辑来看肯定不会做row_lock_table_autoinc_for_mysql了。
作者微信:
微信.jpg
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。