当前位置:网站首页>如何做数据平滑迁移:双写方案
如何做数据平滑迁移:双写方案
2022-07-27 04:30:00 【pbrong】
1.什么是数据迁移
数据迁移指的是将一批数据从同构存储系统(如MySQLA到MySQLB)或异构存储系统(如MySQL-MongoDB)间搬运迁移。
最简单的数据迁移方式是通过脚本或定时任务将数据进行搬运,亦或是通过类似canal之类的工具进行数据同步。
这种最简单方案在数据量小且系统对数据一致性要求低的情况下可以良好生效,但是对于大数据量的实时在线系统来讲,需要在数据迁移的过程中做好以下三个保障:
- 在线迁移:迁移应该是在线的迁移,也就是在迁移的同时还会有数据的写入
- 数据一致性:数据应该保证完整性,也就是说在迁移之后需要保证新的库和旧的库的数据是一致的
- 可回滚:迁移的过程需要做到可以回滚,这样一旦迁移的过程中出现问题,可以立刻回滚到源库不会对系统的可用性造成影响
2.数据双写迁移方案
数据双写迁移是最常用的一种数据迁移方案,可以保证迁移过程是在线的、迁移前后数据是一致的、迁移过程是可回滚的。数据双写迁移方案分为五大步,分别是:同步、双写、校验、切读、切写。以MySQL数据迁移至MongoDB为例来说明这五大步的流程。
2.1.同步
首先通过Binlog监听工具(如Canal)获取MySQL的全量日志及增量日志,并且不断写入MongoDB:
2.2.双写
在进行了同步操作之后,此时MongoDB中数据已经几乎和MySQL一致,但是此时并不能直接将读写操作切换到MongoDB中,因为在切换的这个过程中会出现数据不一致,此时就需要双写。
所谓双写其实就是在程序中写入MySQL时,也将这份数据转换格式并同时写入MongoDB,为了不影响接口写入的pct99时间,可以将对MongoDB的写入进行异步化,对于写入失败的数据再定时回捞写入。
注意由于Binlog监听程序也在进行数据增量写入,所以可以通过开关控制双写启动后,关闭Binlog监听程序。
2.3.校验
经过同步及双写两个步骤,此时MySQL和MongoDB应该已经保持线上实时同步了,但是为了确保双写的数据不出问题,需要通过定时任务来对MySQL及MongoDB的数据一致性做抽样校验,当校验到数据不一致时,以MySQL的数据为准覆盖MongoDB中的对应数据。
2.4.切读
当抽样校验持续一段时间(如一周)时,如果数据一致性基本为100%时,可以启动切读。
所谓切读指的是将数据读取时,不对MySQL进行读取,而是对MongoDB进行读取。此时通过灰度控制来进行小流量数据读取,在观察一段时间没问题后,逐步放大切读流量,直到100%读MongoDB。
2.5.切写
切读完成后,读取时就已经不依赖于老MySQL,而是依赖于新MongoDB了。此时要做的最后一步是切写,也就是关闭双写,只写MongoDB。此时数据迁移完成,读写均通过MongoDB。
边栏推荐
- [day02] Introduction to data type conversion, operators and methods
- QString转换char*
- Two way republication experiment
- Understand kingbasees V9 in one picture
- 打开编程的大门
- Cloudcompare & PCL match point distance suppression
- Prometheus Node Exporter 常用监控指标
- 0 dynamic programming medium leetcode467. The only substring in the surrounding string
- Bubble sort (detailed)
- Structural mode - decorator mode
猜你喜欢

Huawei's entry into the commercial market: due to the trend, there are many challenges

Anonymous named pipes, understanding and use of interprocess communication in shared memory

Solution to the third game of 2022 Hangzhou Electric Multi school league

JS day 2 (variables, variable usage, naming rules, syntax extensions)
![Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号](/img/31/ed0d8c1a5327059f2de7493bec1c6c.png)
Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号
![Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number](/img/31/ed0d8c1a5327059f2de7493bec1c6c.png)
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number

Database leader Wang Shan: strive for innovation and carefully Polish high-quality database products

Visualization domain svg
![[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!](/img/26/22597a7ece0431a4e54703945a775c.jpg)
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!

e. The difference between target and e.currenttarget
随机推荐
【动态规划百题强化计划】11~20(持续更新中)
els 兼容性DC、传递图片到窗口
Overview of communication protocols
Structural mode - facade mode
干货 | 独立站运营怎么提高在线聊天客户服务?
There are two solutions for the feign call header of microservices to be discarded (with source code)
第六章:云数据库
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"
Maximum value, minimum value, bubble sort in the array
Pinia uses plug-ins for persistent storage.
Open the door of programming
Visualization domain svg
Chapter 6: cloud database
在有序数组找具体某个数字
ELS compatibility DC, transfer pictures to window
数组中的最大值,最小值,冒泡排序
Two way republication experiment
Differences and uses of SRAM, DRAM, SDRAM and DDR
F - Pre-order and In-order(Atcoder 255)
pinia的持久化存储,pinia使用插件进行持久化存储。