- 源码地址:https://github.com/noplay/python-mysql-replication
- 文件解析:
├── binlogstream.py├── bitmap.py├── column.py├── _compat.py├── event.py├── exceptions.py├── gtid.py├── __init__.py├── packet.py├── row_event.py├── table.py
- binlogstream.pyBinLogStreamReader类,是调用入口,这个类支持用户传入mysql配置,slave需要同步的信息等,同时实现了__iter__,注册slave,读packet,协议参考:https://dev.mysql.com/doc/internals/en/replication-protocol.html
- BinLogPacketWrapper类,mysql网络包序列化和反序列化
- 各个event(select、update、insert、delete、rollback、heartbeat等)对应的实现类,全都继承子BinlogEvent,在BinLogPacketWrapper类中把获取到的event映射到对应的evnet处理类
- pymysql中的connnections.py:Connection类,实现连接、读写mysql包(具体包格式由protocol实现)