当前位置:网站首页>How to do smooth data migration: Double write scheme
How to do smooth data migration: Double write scheme
2022-07-27 04:53:00 【pbrong】
1. What is data migration
Data migration refers to transferring a batch of data from a homogeneous storage system ( Such as MySQLA To MySQLB) Or heterogeneous storage systems ( Such as MySQL-MongoDB) Transportation and migration between .
The simplest way of data migration is to move data through scripts or scheduled tasks , Or through similar canal Such tools for data synchronization .
This simplest scheme can work well when the amount of data is small and the system has low requirements for data consistency , But for real-time online systems with a large amount of data , The following three guarantees need to be made in the process of data migration :
- Online migration : Migration should be online , That is, data will be written while migrating
- Data consistency : Data should be complete , That is to say, after the migration, it is necessary to ensure that the data of the new library is consistent with that of the old library
- Roll back : The migration process needs to be rolled back , In this way, once problems occur in the migration process , You can rollback to the source library immediately without affecting the availability of the system
2. Data double write migration scheme
Data double write migration is the most commonly used data migration scheme , It can ensure that the migration process is online 、 The data is consistent before and after migration 、 The migration process can be rolled back . The data double write migration scheme is divided into five steps , Namely : Sync 、 Double write 、 check 、 Cut and read 、 Cut and write . With MySQL Data migration to MongoDB As an example to illustrate the five step process .
2.1. Sync
First, through Binlog Monitoring tools ( Such as Canal) obtain MySQL Full log and incremental log , And keep writing MongoDB:
2.2. Double write
After synchronization , here MongoDB The data in is almost the same as MySQL Agreement , But at this time, you cannot directly switch the read / write operation to MongoDB in , Because there will be data inconsistency in the process of switching , At this point, you need to double write .
The so-called double writing is actually writing in the program MySQL when , Also convert this data into format and write it at the same time MongoDB, In order not to affect the interface written pct99 Time , Can be right MongoDB Write to asynchronize , For the data that fails to be written, it will be retrieved and written regularly .
Pay attention to Binlog The listener is also writing data incrementally , Therefore, you can control the double write startup through the switch , close Binlog Monitor program .
2.3. check
After two steps of synchronization and double writing , here MySQL and MongoDB Online real-time synchronization should have been maintained , But in order to ensure that there is no problem with double write data , It is necessary to correct MySQL And MongoDB The consistency of data is checked by sampling , When the data is verified to be inconsistent , With MySQL The data is subject to coverage MongoDB Corresponding data in .
2.4. Cut and read
When sampling verification lasts for a period of time ( Like a week ) when , If the data consistency is basically 100% when , Can start read cut .
Cut reading refers to reading data , incorrect MySQL To read , It's right MongoDB To read . At this time, small flow data is read through gray control , After observing for a period of time, there is no problem , Gradually enlarge the cutting and reading flow , until 100% read MongoDB.
2.5. Cut and write
After reading , When reading, it is no longer dependent on the old MySQL, It depends on new MongoDB 了 . The last step to do at this time is to cut and write , That is, turn off double writing , Just write MongoDB. At this point, the data migration is complete , Pass both reading and writing MongoDB.
边栏推荐
- Do you know about wechat merchant billing?
- Cloudcompare & PCL matching point median (or standard deviation) distance suppression
- JS第二天(变量、变量的使用、命名规则、语法扩展)
- 2022-07-26: what is the output of the following go language code? A:5; B:hello; C: Compilation error; D: Running error. package main import ( “fmt“ ) type integer in
- js小技巧
- What is the difference between using varchar type and using date type for timestamp column?
- 华为入局商用市场:趋势使然,挑战颇多
- The data in echart histogram is displayed at the top of the chart
- Using JSON type to realize array function in MySQL
- Digital integrated circuit: MOS tube device chapter (I)
猜你喜欢

Yolov4网络详解

Three cores of Redux

IIC 通信协议 (一)

HCIA dynamic routing OSPF experiment

Interview must ask | what stages does a thread go through from creation to extinction?

如何做数据平滑迁移:双写方案

JS第二天(变量、变量的使用、命名规则、语法扩展)

Technology sharing | gtid that needs to be configured carefully_ mode

2022杭电多校联赛第三场 题解

Session&Cookie&token
随机推荐
Ref Hook
Session&Cookie&token
How does novice Xiaobai learn to be we media?
QString转换char*
结构型模式-桥接模式
HCIA static routing comprehensive experiment
pinia的持久化存储,pinia使用插件进行持久化存储。
Using JSON type to realize array function in MySQL
微信小程序编辑头像
Effect Hook
Prometheus node exporter common monitoring indicators
ELS compatibility DC, transfer pictures to window
有趣的C语言
Vscode opens a new chapter in the visualization of pull request update code branches
STM32 cubeMX HAL-----PWM—改变频率
利用Power Automate,轻松下载Power BI报告中的数据
RSA asymmetric encryption and decryption signature verification tool
IIC communication protocol (I)
Word/excel has a fixed table size. When filling in the content, the table does not change with the cell content
关于gorm的BeforeDelete钩子方法不生效的问题