• 利用pt-online-schema-change为千万级别表在线添加索引报错


    添加索引

    ALTER TABLE `FUND_PAY_TRADE_RECORD`

         ADD INDEX `IDX_PAY_THIRD_ID` (`THIRD_ID`) USING BTREE ;

    统计表大小5.6G

    spacer.gifblob.png

    备份表:

    mysqldump -uroot -p --master-data=2 --single-transaction -t  xiaodai   FUND_PAY_TRADE_RECORD > TRADE_RECORD0621.sql

    用pt工具变更:

    pt-online-schema-change --user=root --password= --alter="ADD INDEX IDX_PAY_THIRD_ID (THIRD_ID) USING BTREE" D=xiaodai,t=FUND_PAY_TRADE_RECORD   --no-check-replication-filters  --execute

    报错

    blob.pngThreads_running=52 exceeds its critical threshold 50

    从提示上可以看出是Threads_running 超过了警告的阀值,查看官方文档,有两种方式来设置这个参数:

    --critical-load
    type: Array; default: Threads_running=50
    Examine SHOW GLOBAL STATUS after every chunk, 
    and abort if the load is too high. The option accepts a comma-separated list of MySQL status variables and thresholds. 
    An optional =MAX_VALUE (or :MAX_VALUE) can follow each variable. If not given, 
    the tool determines a threshold by examining the current value at startup and doubling it.
    See --max-load for further details. These options work similarly, 
    except that this option will abort the tool’s operation instead of pausing it,
     and the default value is computed differently if you specify no threshold. 
     The reason for this option is as a safety check in case the triggers on the
     original table add so much load to the server that it causes downtime. 
     There is probably no single value of Threads_running that is wrong for 
     every server, but a default of 50 seems likely to be unacceptably high
     for most servers, indicating that the operation should be canceled immediately.

    大致的意思如下:
    每次chunk操作前后,会根据show global status统计指定的状态量的变化,默认是统计Thread_running。
    目的是为了安全,防止原始表上的触发器引起负载过高。这也是为了防止在线DDL对线上的影响。
    超过设置的阀值,就会终止操作,在线DDL就会中断。提示的异常如上报错信息。


    --max-load
    type: Array; default: Threads_running=25
    Examine SHOW GLOBAL STATUS after every chunk, and pause if any status variables are higher than their thresholds. 
    The option accepts a comma-separated list of MySQL status variables. An optional =MAX_VALUE (or :MAX_VALUE) can 
    follow each variable. If not given, the tool determines a threshold by examining the current value and increasing it by 20%.

    For example, if you want the tool to pause when Threads_connected gets too high, you can specify “Threads_connected”,
     and the tool will check the current value when it starts working and add 20% to that value. If the current value is 100, 
     then the tool will pause when Threads_connected exceeds 120, and resume working when it is below 120 again. If you want to
     specify an explicit threshold, such as 110, you can use either “Threads_connected:110” or “Threads_connected=110”.

    The purpose of this option is to prevent the tool from adding too much load to the server. If the data-copy queries are 
    intrusive, or if they cause lock waits, then other queries on the server will tend to block and queue. This will typically 
    cause Threads_running to increase, and the tool can detect that by running SHOW GLOBAL STATUS immediately after each query finishes. 
    If you specify a threshold for this variable, then you can instruct the tool to wait until queries are running normally again. This will 
    not prevent queueing, however; it will only give the server a chance to recover from the queueing. If you notice queueing, it is best to decrease the chunk time.

    --max-load 选项定义一个阀值,在每次chunk操作后,查看show global status状态值是否高于指定的阀值。该参数接受一个mysql status状态变量以及一个阀值,
    如果没有给定阀值,则定义一个阀值为为高于当前值的20%。
    注意这个参数不会像--critical-load终止操作,而只是暂停操作。当status值低于阀值时,则继续往下操作。
    是暂停还是终止操作这是--max-load和--critical-load的差别。

    参数值为列表形式,可以指定show global status出现的状态值。比如,Thread_connect 等等。
    格式如下:--critical-load="Threads_running=200"  或者--critical-load="Threads_running:200"。




  • 相关阅读:
    java关键字之synchronized
    java多线程之线程安全
    java多线程之管道流
    java多线程之多生产者-多消费者
    java多线程之生产者-消费者
    java多线程之wait和notify
    python读取json文件并解析
    java之继承中的静态变量
    shell多线程(3)while循环
    equals与hashcode
  • 原文地址:https://www.cnblogs.com/DBABlog/p/12926957.html
Copyright © 2020-2023  润新知