佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > MySQL slave 延遲一列 外鍵檢查和自增加鎖

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

熱門標簽:呼叫中心市場需求 地方門戶網(wǎng)站 鐵路電話系統(tǒng) AI電銷 網(wǎng)站排名優(yōu)化 服務(wù)外包 Linux服務(wù)器 百度競價排名

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

一、現(xiàn)象

延遲大,大事物。

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

  • 無IO

  • SQL THREAD占用CPU 100%

二、pscak 采樣

采樣30個點

  • 外鍵檢查 占70%

  • 自增鎖獲取 占30%

三、自增鎖獲取邏輯

邏輯如下其實也是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加自增鎖。不知道什么原因。當前知道:

  • 如果主庫語句模式,從庫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了。

到此這篇關(guān)于MySQL slave 延遲一列 外鍵檢查和自增加鎖的文章就介紹到這了,更多相關(guān)MySQL slave 延遲 外鍵檢查和自增加鎖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • MySQL出現(xiàn)Waiting for table metadata lock的原因方法
  • MySQL表結(jié)構(gòu)變更你不可不知的Metadata Lock詳解
  • MYSQL METADATA LOCK(MDL LOCK)MDL鎖問題分析
  • 淺談MySQL next-key lock 加鎖范圍
  • MySQL 加鎖控制并發(fā)的方法
  • PHP+MySQL高并發(fā)加鎖事務(wù)處理問題解決方法
  • MYSQL METADATA LOCK(MDL LOCK) 理論及加鎖類型測試

標簽:衡水 崇左 湘潭 黃山 銅川 仙桃 蘭州 湖南

巨人網(wǎng)絡(luò)通訊聲明:本文標題《MySQL slave 延遲一列 外鍵檢查和自增加鎖》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    荣成市| 河西区| 景洪市| 通州市| 兴国县| 上饶县| 锡林郭勒盟| 祁门县| 循化| 云林县| 牡丹江市| 叙永县| 鹤峰县| 温宿县| 丽水市| 荣成市| 枣阳市| 拉孜县| 航空| 介休市| 双城市| 宁都县| 浠水县| 长岛县| 孝义市| 佛坪县| 南川市| 莲花县| 塔城市| 临桂县| 固安县| 文昌市| 大洼县| 渭南市| 洞口县| 大厂| 咸宁市| 云梦县| 镇康县| 盐山县| 广昌县|