首页 > 其他分享 >重启失败的 pt-online-schema-change 任务

重启失败的 pt-online-schema-change 任务

时间:2024-06-19 17:24:18浏览次数:15  
标签:10 pt1717 drop pt online table new change

从 Percona Toolkit 3.6.0 开始,如果 pt-online-schema-change 被中断,你可以重新恢复它。

 

要重启任务,需要知道它在哪里失败了。这就是为什么第一个必须使用的选项是 -history。它指示 pt-online-schema-change 将进度存储在历史表中。历史表的默认名称是 percona.pt_osc_history。你可以使用选项 -history-table 来覆盖这个名称。历史表结构如下:

create table pt_osc_history (
  job_id     int           not null auto_increment,
  db         char(64)      not null,
  tbl        char(64)      not null,
  new_table_name char(64)      default null,
  altr       text          not null,
  args       text          not null,
  lower_boundary text,
  upper_boundary text,
  done       enum('yes','no')  not null default 'no',
  ts         timestamp     not null default current_timestamp on update current_timestamp,
  primary key (job_id)
) engine=innodb default charset=utf8mb4;

其中:

·job_id:是 pt-online-schema-change 运行的唯一标识符

·db:数据库名称

·tbl:表的名称

·new_table_name:pt-online-schema-change 为执行任务而创建的表副本的名称

·altr:alter table命令的 -alter 参数

·args:传递给 pt-online-schema-change 命令的其他参数

·lower_boundary:最新处理的 chunk 的下边界

·upper_boundary:最新处理的 chunk 的上边界

·done:任务是否完成的指示符

·ts:任务条目更新时记录的时间戳。实际上,这就是处理完最新数据块的时间戳。

 

如果表索引包含二进制列,如 BLOB 或 BINARY,请使用选项 -binary-index 创建历史表。在这种情况下,lower_boundary 和 upper_boundary 将使用 BLOB 数据类型,而不是 TEXT。pt-table-checksum中的-replicate表也采用了同样的思路。

 

一旦使用 -history 选项运行 pt-online-schema-change,它就会创建一条包含作业详细信息的记录。如果作业失败,你可以很容易地在该工具输出或历史表中找到它的唯一标识符,并重新启动它。

 

下面是几个 pt-online-schema-change 运行后 percona.pt_osc_history 表内容的示例:

mysql> select * from percona.pt_osc_historyG
*************************** 1. row ***************************
        job_id: 1
            db: test
           tbl: pt1717
new_table_name: __pt1717_new
          altr: engine=INNODB
          args: {"history":1,"execute":1,"progress":["time","5"],"drop-new-table":0,"max-lag":"10","chunk-size":"10","alter":"engine=INNODB","drop-triggers":0}
lower_boundary: 9991
upper_boundary: 10000
          done: yes
            ts: 2024-06-05 13:32:09
*************************** 2. row ***************************
        job_id: 2
            db: test
           tbl: pt1717
new_table_name: __pt1717_new
          altr: engine=INNODB
          args: {"alter":"engine=INNODB","max-lag":"10","drop-new-table":0,"drop-triggers":0,"progress":["time","5"],"history":1,"chunk-size":"10","execute":1}
lower_boundary: NULL
upper_boundary: NULL
          done: no
            ts: 2024-06-05 13:32:09
*************************** 3. row ***************************
     job_id: 3
            db: test
           tbl: pt1717
new_table_name: __pt1717_new
          altr: engine=INNODB
          args: {"progress":["time","5"],"execute":1,"chunk-size":"10","history":1,"drop-new-table":0,"alter":"engine=INNODB","max-lag":"10","drop-triggers":0}
lower_boundary: NULL
upper_boundary: NULL
          done: no
            ts: 2024-06-05 13:32:09
*************************** 4. row ***************************
        job_id: 4
            db: test
           tbl: pt1717
new_table_name: __pt1717_new
          altr: engine=INNODB
          args: {"drop-triggers":0,"alter":"engine=INNODB","progress":["time","5"],"history":1,"chunk-size":"10","drop-new-table":0,"max-lag":"10","execute":1}
lower_boundary: 4901
upper_boundary: 4910
          done: no
            ts: 2024-06-05 13:32:12
4 rows in set (0,00 sec)

其中:

任务1成功结束了。

done: yes

任务2和任务2还没有启动:

lower_boundary: NULL
upper_boundary: NULL
          done: no

任务3被中断了:

lower_boundary: 4901
upper_boundary: 4910
          done: no

要重新启动任务,请运行 pt-online-schema-change,并选择 -resume=ID_OF_YOUR_PREVIOUSLY_FAILED_JOB。工具会检查之前创建的表副本及其触发器是否还在,并从之前失败的数据块启动作业。

$ ./bin/pt-online-schema-change h=127.0.0.1,P=12345,u=msandbox,p=msandbox,D=test,t=pt1717 --execute --chunk-size 10 --max-lag 10 --alter 'engine=INNODB' --progress time,5 --no-drop-new-table --no-drop-triggers --history --resume=4
2024-06-05T13:54:11 Job 5 started.
Found 2 slaves:
s76 -> 127.0.0.1:12346
s76 -> 127.0.0.1:12347
Will check slave lag on:
s76 -> 127.0.0.1:12346
s76 -> 127.0.0.1:12347
Operation, tries, wait:
  analyze_table, 10, 1
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
Altering `test`.`pt1717`...
Altering new table...
Altered `test`.`__pt1717_new` OK.
2024-06-05T13:54:11 Creating triggers...
2024-06-05T13:54:11 Created triggers OK.
2024-06-05T13:54:11 Copying approximately 9956 rows...
2024-06-05T13:54:14 Job 5 finished successfully.
2024-06-05T13:54:14 Copied rows OK.
2024-06-05T13:54:14 Analyzing new table...
2024-06-05T13:54:14 Swapping tables...
2024-06-05T13:54:14 Swapped original and new tables OK.
Not dropping old table because --no-drop-triggers was specified.
Not dropping triggers because --no-drop-triggers was specified.  To drop the triggers, execute:
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_pt1717_del`
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_pt1717_upd`
DROP TRIGGER IF EXISTS `test`.`pt_osc_test_pt1717_ins`
Successfully altered `test`.`pt1717`.

可以同时使用 -history 和 -resume 选项,也可以不使用。需要注意的是,如果不使用选项 -history,一旦任务再次失败,就无法重新启动。

 

选项 -resume 的另一个前提条件是 -no-drop-new-table 和 -no-drop-triggers。如果删除了新表和触发器,pt-online-schema-change 就无法重新启动任务,因为没有先前复制的数据。

$ ./bin/pt-online-schema-change h=127.0.0.1,P=12345,u=msandbox,p=msandbox,D=test,t=pt1717 --execute --chunk-size 10 --max-lag 10 --alter 'engine=INNODB' --progress time,5 --history --resume=9
2024-06-05T13:58:10 Job 10 started.
Found 1 slaves:
s76 -> 127.0.0.1:12346
Will check slave lag on:
s76 -> 127.0.0.1:12346
Operation, tries, wait:
  analyze_table, 10, 1
  copy_rows, 10, 0.25
  create_triggers, 10, 1
  drop_triggers, 10, 1
  swap_tables, 10, 1
  update_foreign_keys, 10, 1
Altering `test`.`pt1717`...
New table `test`.`___pt1717_new` not found, restart operation from scratch
`test`.`pt1717` was not altered.
History saved. Job id: 10

 

总结

如果想在失败后恢复 pt-online-schema-change,可使用选项 -history -no-drop-new-table -no-drop-triggers 来恢复。如果任务失败,可以通过提供任务 ID 作为选项 -resume 的参数来恢复任务。你可以在 pt-online-schema-change 输出和历史表中找到失败任务的 ID。

标签:10,pt1717,drop,pt,online,table,new,change
From: https://www.cnblogs.com/abclife/p/18252179

相关文章

  • iptables 四表五链
    https://blog.csdn.net/weixin_48190891/article/details/107815698iptables是基于内核态框架netfilter实现。他们共同组成的Linux包过滤防火墙。组成默认五种规则链:INPUTOUTPUTFORWARDPREROUTINGPOSTROUTING默认四种规则表:filter:包过滤nat:源及目的地址转换ma......
  • MBR60200PT-ASEMI逆变箱专用MBR60200PT
    编辑:llMBR60200PT-ASEMI逆变箱专用MBR60200PT型号:MBR60200PT品牌:ASEMI封装:TO-247最大平均正向电流(IF):60A最大循环峰值反向电压(VRRM):200V最大正向电压(VF):0.85V~0.90V工作温度:-40°C~175°C反向恢复时间:5ns芯片个数:2芯片尺寸:72mil引脚数量:3正向浪涌电流(IFMS):500A包装方式:5......
  • MBR60100PT-ASEMI逆变焊机专用MBR60100PT
    编辑:llMBR60100PT-ASEMI逆变焊机专用MBR60100PT型号:MBR60100PT品牌:ASEMI封装:TO-247最大平均正向电流(IF):60A最大循环峰值反向电压(VRRM):100V最大正向电压(VF):0.70V~0.90V工作温度:-65°C~175°C芯片个数:2芯片尺寸:mil正向浪涌电流(IFMS):400AMBR60100PT特性:低正向压降低功率损......
  • golang json库 忽略 omitempty
    json库的obmitempty介绍众所周知,golang的json库有个omitempty的tag,有了它,这个json序列化的时候,如果这个字段是零值,则会忽略此字段的序列化,导致json字符串中没有对应的字符串。这对于某些人是困惑的,一般默认是没有omitempty这个tag的,但是。但是来了,但是protobuf生成的pb.......
  • ChatGPT Plus GPT-4o Claude 3 Opus合租拼车全新方式
    无需自己搭建,登录即可用,国内直连访问,聚合多家最强大模型,随意选择使用。立即体验datapipe.top支持OpenAI最新GPT-4o,获得快速高质量的对话,保证可用配额。支持多种大模型,GPT-4o,Claude-3,Llama3等最强模型。AskInternet联网搜索用于替代传统搜索,更高效。支持GPT-3.5/K......
  • 如何使用AI写PPT工具快速生成答辩PPT?
    拜托,做答辩PPT真的一点也不难副本很多快要毕业的同学在做答辩PPT的时候总是感觉毫无思路,一窍不通,但这并不是你们的错。制作答辩PPT看起来似乎很容易,但在真正制作的时候,版式、字体、大小之类的调整真的很让人恼火。与其在PPT上耗费时间,不如多花些精力在答辩练习上。现在科技......
  • 深入理解JavaScript中的闭包与作用域链
    作为一名JavaScript开发者,了解闭包与作用域链是非常重要的。本文将深入探讨这两个概念,帮助您更好地理解JavaScript的运行机制。作用域链在JavaScript中,每个函数都有一个属于自己的作用域,称为局部作用域。当函数被执行时,会创建一个执行上下文,其中包括局部作用域和其父级作用域......
  • 掌握异步编程:探索JavaScript中的Promise与async/await
    在现代JavaScript开发中,异步编程已经成为了不可或缺的一部分。为了更好地处理异步操作,JavaScript引入了Promise和async/await两个重要概念。本文将带您了解这两个概念,帮助您掌握异步编程。 PromisePromise是异步编程的一种解决方案,它表示一个异步操作的最终完成(或失败)及其结......
  • HarmonyOS NEXT - 从TypeScript到ArkTS的适配指导
    一:ArkTS语法适配背景二:从TypeScript到ArkTS的适配规则三:适配指导案例ArkTS语法适配背景 ArkTS在保持TypeScript(简称TS)基本语法风格的基础上,进一步通过规范强化静态检查和分析,使得在程序开发期能检测更多错误,提升程序稳定性,并实现更好的运行性能。本文将进一步解释为什么......
  • 使用ChatGPT来写程序代码课程作业
    学生使用ChatGPT写代码的弊端:剽窃:ChatGPT生成的代码可能与其他来源的内容相似,而且具有非常明显的特征,肉眼可辨,如果学生直接将ChatGPT生成的代码用作自己的作业,会被视为抄袭,导致诚信问题。质量:虽然ChatGPT可以生成程序代码,但它并不是一个专门为撰写作业而设计的工具。因此,......