MySQL:slave 延迟一列 外键检查和自增加锁

发布时间:2020-08-16 14:17:40 作者:gaopengtttt
来源:ITPUB博客 阅读:112


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

一、现象

延迟大,大事物。

MySQL:slave 延迟一列 外键检查和自增加锁

image.png

二、pscak 采样

采样30个点

三、自增锁获取逻辑

逻辑如下其实也是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加自增锁。不知道什么原因。当前知道:

但是都不满足。疑惑。

四、方案

作者微信:


MySQL:slave 延迟一列 外键检查和自增加锁

微信.jpg


推荐阅读:
  1. MySQL之数据表控制语句
  2. MySQL的基本操作

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql slave 一列

上一篇:教你如何创建第一个Java应用程序,编程小白不容错过~

下一篇:【恩墨学院】深度学习在美团点评推荐平台排序中的运用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》