阿里云cak搭建mysql_MySQL:slave 延迟一列 外键检查和自增加锁

本文没有太多可读性,完全是自己的笔记

一、现象

延迟大,大事物。

表结构

53b0d92dc67556dd5359c5a474a79ab3.png

无IO

e6d80d0b4e303a2ee0be0292a848e829.png

SQL THREAD占用CPU 100%

4cb3bb10be8fa8e7f6e527498d7ee517.png

二、pscak 采样

采样30个点

外键检查 占70%

9dcbcac89896ee215547c9783ee8f266.png

自增锁获取 占30%

4290f7779f7fcbaac4953d6d233e2129.png

三、自增锁获取逻辑

逻辑如下其实也是innodb_autoinc_lock_mode参数的作用

switch (lock_mode) {

case AUTOINC_NO_LOCKING://innodb_autoinc_lock_mode=2

/* Acquire only the AUTOINC mutex. */

dict_table_autoinc_lock(m_prebuilt->table);

break;

case AUTOINC_NEW_STYLE_LOCKING: // innodb_autoinc_lock_mode=1 注意这里没有break 巧妙的完成了逻辑

/* For simple (single/multi) row INSERTs, we fallback to the

old style only if another transaction has already acquired

the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT

etc. type of statement. */

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;

/* Acquire the AUTOINC mutex. */

dict_table_autoinc_lock(ib_table);

/* We need to check that another transaction isn't

already holding the AUTOINC lock on the table. */

if (ib_table->n_waiting_or_granted_auto_inc_locks) {

/* Release the mutex to avoid deadlocks. */

dict_table_autoinc_unlock(ib_table);

} else {

break;

}

}

/* Fall through to old style locking. */

case AUTOINC_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) {

/* Acquire the AUTOINC mutex. */

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了。

作者微信:

eee519470a16c36728af00b0a3a66dc9.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值