More Related Content Similar to Cdc@ganji.com (20) Cdc@ganji.com4. LAMP架构面临的挑战
性能提升 Caching
多平台 Key-Value
web/wap/mobile Indexing
社交化(SNS) OLAP
离线/实时统计分析 Graph DB
数据挖掘 BigTable
多机房 ...
6. 应用层解决...
在业务代码中维护 缺点
多写 代码复杂,维护困难
消息中间件异步处理 工作量大,效率下降
简单,灵活 容易引入BUG
容错能力差
分布式事务?
开发效率?
服务化?
7. 系统层面...
方案 项目
PHP mysqlnd
Language API
JDBC
MySQL Proxy
Data Middleware
Vitess
MySQL Trigger + UDF
Flexviews
MySQL Binlog Parser Amoeba
JBinlog
10. 2 Tungsten Replicator介绍
11. tungsten-replicator
Data replication engine for MySQL
Easy failover
Multiple masters
Multiple sources to a single slave
Parallel replication
Replicate to Oracle and PostgreSQL
O'Reilly MySQL Application of the Year 2011
http://code.google.com/p/tungsten-replicator/
15. 实现细节
MySQL 编码(JSON)
Row Based Replication Meta:
Schema,Table
Kestrel Action:
Insert/Update/Delete
Memcache Protocol
Row Data
High Performance
Persistence
Fan-out Queue Tungsten
Reliable Get ReplicationFilter
https://github.com/robey ColNamesFilter
/kestrel
16. 优化配置
Replication Queue
extractor ColNames Applier Extractor
Filter Applier
Kestre
MySQL Queue
独立服务器
BinLog
“Trigger” Server
No THL
18. Availability?
需求
服务崩溃
MySQL
数据重复
Tungsten
Kestrel
乱序? 数据丢失
Hardware
网络故障
对业务透明 自动响应
数据丢失
同步延迟
19. Master/Slave
CDC
Master switcher
MySQL 应用逻辑
Master
CDC
Slave
根据延迟信息进行切换
20. Master/Slave 2
P1 P2 P3 P4 P5 P6
P1 P7
P2 P3
...
P1 P2 P3 P4 P5 P6
P1 P7
P2 P3
...
更新数据流
21. Master/Slave 2
block1 block2
P1 P2 P3 P4 P5 H1 P6
P1 P7
P2 …
P3
P1 P2 P3 P4 P5 H1 P6
P1 P7
P2 …
P3
SN: 100
Timestamp: 13000000
Delay=now() - timestamp
定时更新heartbeat表,生成heartbeat数据
以Block为单位进行切换
Master处理完成一个Block后,通知Slave处理该Block
切换时,Slave重放当前Block,确保数据不丢失
22. Zookeeper
信息 格式 描述
配置 主CDC服务器地址 启动,切换
从CDC服务器地址
Switcher进程 0 – 主处理进程HOST:PID 任务分配
1 – 从处理进程HOST:PID
2 - 备份进程 HOST:PID
处理状态 主CDC 状态监控
Block SN 同步
最新的timestamp
23. 优点
实时 高可用
系统延时 <100ms 可用于线上业务
独立性
对线上业务的非侵入性
可移植性
事务友好
灵活
支持多库,多表
同时支持多种后端应用,互相独立
数据一致性 数据随意组合
与DB保持严格一致
数据可以回放
27. 跨机房同步
App
主机房A
延迟不一致
Master
Message 产生数据错误
Queue
DB
MQ
Search/Cache
Slave
DB
App
机房B
28. 跨机房同步
主机房A
部署新机房 <2个月
代码修改工作量<1人月
Master
没有延迟同步问题
DB
Slave
DB Search/Cache
CDC
机房B
29. 数据迁移
场景 优点
表结构调整 不需要修改现有业务
存储调整 不需要修改表结构
异构数据库 停服时间短
MySQL → NoSQL
关键点
如何获取增量数据
如何较少开发的工作量
如何减少停服时间
30. 更多...
更新客户信息
Call Center
支付及收入
ERP
数据更新历史记录
Data + Version
数据校验
33. 谢谢!
Questions?
We are hiring...
PHP研发工程师
WEB前端研发工程师