溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MySQL:slave 延遲一列 外鍵檢查和自增加鎖

發(fā)布時間:2020-08-16 14:17:40 來源:ITPUB博客 閱讀:126 作者:gaopengtttt 欄目:MySQL數(shù)據(jù)庫


本文沒有太多可讀性,完全是自己的筆記

一、現(xiàn)象

延遲大,大事物。

  • 表結(jié)構(gòu)


    MySQL:slave 延遲一列 外鍵檢查和自增加鎖

    image.png

  • 無IO


    MySQL:slave 延遲一列 外鍵檢查和自增加鎖

    image.png

  • SQL THREAD占用CPU 100%

MySQL:slave 延遲一列 外鍵檢查和自增加鎖

image.png

二、pscak 采樣

采樣30個點

  • 外鍵檢查 占70%


    MySQL:slave 延遲一列 外鍵檢查和自增加鎖

    image.png

  • 自增鎖獲取 占30%


    MySQL:slave 延遲一列 外鍵檢查和自增加鎖

    image.png

三、自增鎖獲取邏輯

邏輯如下其實也是innodb_autoinc_lock_mode參數(shù)的作用

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 觸發(fā)
        DBUG_EXECUTE_IF("die_if_autoinc_old_lock_style_used",
                ut_ad(0););
        error = row_lock_table_autoinc_for_mysql(m_prebuilt); //這個函數(shù)上表上的自增鎖
        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 按理說不會觸發(fā)row_lock_table_autoinc_for_mysql加自增鎖。不知道什么原因。當(dāng)前知道:

  • 如果主庫語句模式,從庫innodb_autoinc_lock_mode=1 ,insert select 肯定會觸發(fā)。

  • 如果從庫 innodb_autoinc_lock_mode=0 肯定會觸發(fā)。

但是都不滿足。疑惑。

四、方案

  • 刪除外鍵

  • innodb_autoinc_lock_mode設(shè)置為2,從邏輯來看肯定不會做row_lock_table_autoinc_for_mysql了。

作者微信:


MySQL:slave 延遲一列 外鍵檢查和自增加鎖

微信.jpg


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI