TiDB Binlog 集群运维

本文首先介绍 Pump 和 Drainer 的状态及启动、退出的内部处理流程,然后说明如何通过 binlogctl 工具或者直接在 TiDB 执行 SQL 操作来管理 binlog 集群,最后的 FAQ 部分会介绍一些常见问题以及处理方法。

Pump/Drainer 的状态

Pump/Drainer 中状态的定义:

  • online:正常运行中
  • pausing:暂停中
  • paused:已暂停
  • closing:下线中
  • offline:已下线

这些状态由 Pump/Drainer 服务自身进行维护,并定时将状态信息更新到 PD 中。

Pump/Drainer 的启动、退出流程

Pump

  • 启动:Pump 启动时会通知所有 online 状态的 Drainer,如果通知成功,则 Pump 将状态设置为 online,否则 Pump 将报错,然后将状态设置为 paused 并退出进程。

  • 退出:Pump 进程正常退出前要选择进入暂停或者下线状态;非正常退出(kill -9、进程 panic、宕机)都依然保持 online 状态。

    • 暂停:使用 kill(非 kill -9)、Ctrl+C 或者使用 binlogctl 的 pause-pump 命令都可以暂停 Pump。接收到暂停指令后,Pump 会变更状态为 pausing,并停止接受 binlog 的写请求,也停止向 Drainer 提供 binlog 数据。安全退出所有线程后,更新状态为 paused 然后退出进程。
    • 下线:仅在使用 binlogctl 的 offline-pump 命令的情况下才会下线 Pump。接收到下线指令后,Pump 会变更状态为 closing,并停止接受 binlog 的写请求。Pump 继续向 Drainer 提供 binlog,等待所有 binlog 数据都被 Drainer 消费后再将状态设置为 offline 并退出进程。

Drainer

  • 启动:Drainer 启动时将状态设置为 online,并尝试从所有非 offline 状态的 Pump 获取 binlog,如果获取 binlog 失败,会不断尝试重新获取。

  • 退出:Drainer 进程正常退出前要选择进入暂停或者下线状态;非正常退出(kill -9 、进程 panic、宕机)都依然保持 online 状态。

    • 暂停:使用 kill(非 kill -9)、Ctrl+C 或者使用 binlogctl 的 pause-drainer 命令都可以暂停 Drainer。接收到指令后,Drainer 会变更状态为 pausing,并停止从 Pump 获取 binlog。安全退出所有线程后,更新状态为 paused 然后退出进程。
    • 下线:仅在使用 binlogctl 的 offline-drainer 命令的情况下才会下线 Drainer。接收到下线指令后,Drainer 变更状态为 closing,并停止从 Pump 获取 binlog。安全退出所有线程后,更新状态为 offline 然后退出进程。

关于 Pump/Drainer 暂停、下线、状态查询、状态修改等具体的操作方法,参考如下 binlogctl 工具的使用方法介绍。

使用 binlogctl 工具管理 Pump/Drainer

binlogctl 支持如下这些功能:

  • 查看 Pump/Drainer 状态
  • 暂停/下线 Pump/Drainer
  • Pump/Drainer 异常状态处理

详细的介绍和使用方法请参考 binlogctl 工具

使用 TiDB SQL 管理 Pump/Drainer

要查看和管理 binlog 相关的状态,可在 TiDB 中执行相应的 SQL 语句。

  • 查看 TiDB 是否开启 binlog,0 代表关闭,1 代表开启

    show variables like "log_bin";
    +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | 0 | +---------------+-------+
  • 查看 Pump/Drainer 状态

    show pump status;
    +--------|----------------|--------|--------------------|---------------------| | NodeID | Address | State | Max_Commit_Ts | Update_Time | +--------|----------------|--------|--------------------|---------------------| | pump1 | 127.0.0.1:8250 | Online | 408553768673342237 | 2019-05-01 00:00:01 | +--------|----------------|--------|--------------------|---------------------| | pump2 | 127.0.0.2:8250 | Online | 408553768673342335 | 2019-05-01 00:00:02 | +--------|----------------|--------|--------------------|---------------------|
    show drainer status;
    +----------|----------------|--------|--------------------|---------------------| | NodeID | Address | State | Max_Commit_Ts | Update_Time | +----------|----------------|--------|--------------------|---------------------| | drainer1 | 127.0.0.3:8249 | Online | 408553768673342532 | 2019-05-01 00:00:03 | +----------|----------------|--------|--------------------|---------------------| | drainer2 | 127.0.0.4:8249 | Online | 408553768673345531 | 2019-05-01 00:00:04 | +----------|----------------|--------|--------------------|---------------------|
  • 异常情况下修改 Pump/Drainer 状态

    change pump to node_state ='paused' for node_id 'pump1';
    Query OK, 0 rows affected (0.01 sec)
    change drainer to node_state ='paused' for node_id 'drainer1';
    Query OK, 0 rows affected (0.01 sec)

    该 SQL 的功能和 binlogctl 中的 update-pump 和 update-drainer 命令的功能一样,因此也只有在 Pump/Drainer 异常的情况下使用。

文档内容是否有帮助?

下载 PDF文档反馈社区交流
产品
TiDB
TiDB Cloud
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.