canal读取mysql的binlog日志时,当binlog被人为改变了引发的问题

https://blog.csdn.net/siyuan494/article/details/78934290

http://shift-alt-ctrl.iteye.com/blog/2399603

https://blog.csdn.net/my201110lc/article/details/77885720


什么是 Mysql 的二进制日志(binlog)?

  • binlog 记录了数据库变更的事件(如 create table、update records)。由一组二进制日志文件(如 log-bin.000010)和一个索引文件(如 log-bin.index)组成。
  • binlog 有两个重要用途:主从复制和数据恢复;
  • 通过log-bin参数开启 binlog,通过binlog-do-dbbinlog-ignore-db参数配置记录和忽略的 schema;
  • 使用RESET MASTER命令可以清除已记录的 binlog;
  • 使用 Mysql 内置的mysqlbinlog工具可以查看和操作 binlog;
  • binlog 有三种格式:基于语句的、基于行数据和混合模式;
  • 关于记录 binlog 的时机,官网上如是说:

Binary logging is done immediately after a statement or transaction completes but before any locks are released or any commit is done. This ensures that the log is logged in commit order. Within an uncommitted transaction, all updates (UPDATE, DELETE, or INSERT) that change transactional tables such as InnoDB tables are cached until a COMMIT statement is received by the server. At that point, mysqld writes the entire transaction to the binary log before the COMMIT is executed.

  • binlog 的 Event 结构(目前主要用的是 v4 版本),下表中的字段名后的两个用冒号分隔的是 offset 和 length。
什么是 Canal?

Canal 是由 Alibaba 开源的一个基于 binlog 的增量日志组件,其核心原理是 Canal 伪装成 Mysql 的 slave,发送 dump 协议获取 binlog,解析并存储起来给客户端消费。

Canal 的核心架构

整体架构

  • Canal 是一个 CS 的架构,Client 和 Server 基于 netty 进行通信,采用的 protobuf 协议;
  • Server 包含了一个或多个 Instance(一个 Instance 可以想象为监听一个数据库的 binlog),Server 将 Client 的请求转至具体的 Instance 处理;
  • 一个 Instance 又包含了 EventParser、EventSink 和 EventStore 三个核心部件。EventParser 负责获取 Mysql 的 binlog 并进行解析,然后将解析的 Event 交给 EventSink 进行过滤和路由处理,处理之后的数据交由 EventStore 进行存储。而 Server 转过来的请求最终就会获取或者操作 EventStore 上存储的数据。



https://www.cnblogs.com/huangxincheng/p/7456397.html

猜你喜欢

转载自blog.csdn.net/java173842219/article/details/80085554