27
扩容与数据迁移 朋春 @我是aleafs MyFOX技术第二讲

My fox 扩容与数据迁移

  • Upload
    aleafs

  • View
    1.861

  • Download
    2

Embed Size (px)

DESCRIPTION

淘宝数据产品的分布式MySQL集群的扩容原理,怎么让40台mysql互联互通,进行数据的随时迁移。

Citation preview

Page 1: My fox 扩容与数据迁移

扩容与数据迁移

朋春

@我是aleafs

MyFOX技术第二讲

Page 2: My fox 扩容与数据迁移

回顾

Page 3: My fox 扩容与数据迁移

关于MyFOX

□ 分布式MySQL集群中间层

□ 数据离线批量写入

□ 透明的数据查询代理

□ 集群管理

Page 4: My fox 扩容与数据迁移

节点结构

MyFOX

12热节点(MySQL)

15k SAS盘,300G * 12,raid10

内存:24G

成本:4.5W / T

8冷节点(MySQL)

7.2k SATA盘,1T * 12,raid10

内存:24G

成本:1.6W / T

路由表

30天无访问的冷数据

新增

热数

Page 5: My fox 扩容与数据迁移

节点2

dbname.t_2

路由表

KEY: thedate=20110811,cid=1

node path modtime hittime …

…,cid=2

节点1

dbname.t_1dbname.t_2

Page 6: My fox 扩容与数据迁移

装完数据

UPDATE ... SET modtime = NOW() WHERE ...

modtime:

每条路由对应的分片的数据更新时间

Page 7: My fox 扩容与数据迁移

路由访问

SELECT node, path, modtime FROM ... WHERE ...

modtime:

if (force_load ||!cache || modtime > cache.savetime) {

// load data from mysql

}

Page 8: My fox 扩容与数据迁移

同时…

if (rand(1,100) <= 10) {

}

UPDATE ... SET hittime = NOW() WHERE ...

Why we use “rand” here

NOT ONLY...

BUT ALSO...

Page 9: My fox 扩容与数据迁移

决策

SELECT node, path FROM ...

WHERE hittime < ’30天前 ’

AND isarchive = 0

Page 10: My fox 扩容与数据迁移

@letonlife:

“…搬运工伤不起”

Page 11: My fox 扩容与数据迁移

工作队列

SELECT ... FROM task_queque

WHERE task_flag = FLAG_WAIT AND trytimes < 3

ORDER BY priority ASC,

trytimes ASC,

ABS(task_position – AGENT_POSITION) ASC,

autokid ASC

Page 12: My fox 扩容与数据迁移

MySQL MySQL

scp (*.MYI, *.MYD)

MySQL MySQLAPP

SELECT LOAD

MySQL MySQL

APP

A.

B.

C.

脚本部署在DB上,有安全隐患

两次落地,两次网络传输

实施

Page 14: My fox 扩容与数据迁移

172.1.1.1 172.1.1.2

dbname.t_2

dbname.t_2

dbname.t_2_fed

CREATE TABLE dbname.t_2_fed (

...

) ENGINE = FEDERATED \

CONNECTION=‘mysql://user:[email protected]/dbname/t_2’

INSERT INTO dbname.t_2 SELECT * FROM dbname.t_2_fed

Page 15: My fox 扩容与数据迁移

真相总是在背后

dbname.t_2dbname.t_2

如何选择一台“最优”的机器作为源表来复制

呢?

Page 16: My fox 扩容与数据迁移

例如:

var task = {

“path” : “dim_category_arch_0.t_92d_1”,

“from” : “1,2,3,4,5,6,7,8”,

“save” : “17,18,19,20”,

}

Page 17: My fox 扩容与数据迁移

节点 机器列表

1 172.001.001.001 172.002.001.001

2 172.001.003.002 172.002.021.002

17 172.001.003.017 172.002.003.017

172.001.003.017 fed

□ 172.001.001.001

□ 172.002.001.001

□ 172.001.003.002

□ 172.002.021.002

Page 18: My fox 扩容与数据迁移

就近原则

□ 同机房

□ 同机柜

□ 同交换机

□ 快速

□ 低碳

□ 稳定

□ 安全

IP “ ”

Page 19: My fox 扩容与数据迁移

一致性检查

□ COUNT

□ XOR

Page 20: My fox 扩容与数据迁移

修改“指针”

序号 路由KEY 路由值

1

thedate=20110811,cid=1

node=1,path=dbname.t_1

2

node=2,path=dbname.t_2

3 thedate=20110811,cid=2

node=9,path=dbname.t_2

node=2,path=dbname.t_2

Page 21: My fox 扩容与数据迁移

卸磨杀驴

/* */

DROP TABLE IF EXISTS dbname.t_2 /* ON NODE 2 */

Why NOT “right now”

Page 22: My fox 扩容与数据迁移

小结

Page 23: My fox 扩容与数据迁移

从16到40

□ Federated

□ 就近原则

Page 24: My fox 扩容与数据迁移

2000台机器的时候

...

MyFOX

route route route route...

MySQL MySQL

chunk server chunk server

MySQL MySQL

Page 25: My fox 扩容与数据迁移

干掉“节点”

□ Mysql承担chunk server

□ 每个chunk跨机房三份冗余

□ 如果宕机,立即复制

□ …

Page 26: My fox 扩容与数据迁移

预告

第三讲:数据压缩

Page 27: My fox 扩容与数据迁移

Thanks

@我是aleafs

[email protected]