当前位置:网站首页>项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
2022-07-04 18:00:00 【Koikoi123】
项目有一个需求,旧库拆分到新库,将旧数据迁移到新库里,期间需要考虑补录和迁移数据,因为没有canal同步,我分配到的任务就是在代码里加入补录迁移数据的接口去保证迁移顺滑和数据一致性
因为线上数据量很大且每时每刻都会有数据入表,需要考虑的几个点:
- 先整理出凌晨期间持续增长数据的表,正常时间入库的表在凌晨一般都不会写入,或者事先限制告知用户在凌晨期间不要做入表操作,因此可以忽略不做迁移
- dba迁移1点前所有数据,假设迁移时间一小时,2点迁完,2点后实现双写,新旧数据源内的数据都会做写入
- 配置多数据源,实现自定义注解切换数据源
- 我会写一个开放接口,传入指定时间范围(假如1点-2点),期间新旧数据源会有偏差,我只需要传入时间范围参数,接口做迁移1-2点之间的数据即可
- 该接口要做两件事,新增和修改,分别拉取create_time和update_time在该时间段内的所有数据,这里一定要事先提交DB工单去申请给线上的这两个字段建立索引
- 先从旧表查create_time范围的数据,因为是双写,所以从旧数据源内查出的实体类list需要不传ID插入新数据源(并且要分页插入)保证迁移的数据是一致的,但是ID不保证(因为自增ID可能会有问题)
- 再从旧表查update_time范围的数据,并且sql多加 update_time != create_time来确保只查出更新过的旧数据,这里迁移的时候ID是保证一致的,可以根据所传ID进行更新(这里是可以走索引的,目前线上log表数据量有千万级别,但凌晨一小时内数据其实不多,批量update预计不会太慢,效率之后有待验证)
边栏推荐
- The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
- Is the securities account opened by qiniu safe?
- 26. Delete the duplicate item C solution in the ordered array
- Bi skills - permission axis
- How test engineers "attack the city" (Part 2)
- 牛客小白月赛7 谁是神箭手
- 小发猫物联网平台搭建与应用模型
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- Pytest 可视化测试报告之 Allure
- Cache é JSON uses JSON adapters
猜你喜欢

OpenCV的二值化处理函数threshold()详解

How to use async Awati asynchronous task processing instead of backgroundworker?

性能优化之关键渲染路径

与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用

To sort out messy header files, I use include what you use

Go微服务(二)——Protobuf详细入门

Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading

自由小兵儿

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

Nebula importer data import practice
随机推荐
How to use async Awati asynchronous task processing instead of backgroundworker?
Using FTP
Unity editor extends C to traverse all pictures in folders and subdirectories
A method of using tree LSTM reinforcement learning for connection sequence selection
BI技巧丨权限轴
每日一题(2022-07-02)——最低加油次数
神经网络物联网平台搭建(物联网平台搭建实战教程)
在线文本行固定长度填充工具
Lm10 cosine wave homeopathic grid strategy
1672. 最富有客户的资产总量
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
千万不要只学 Oracle、MySQL!
LeetCode第300场周赛(20220703)
Qt实现界面滑动切换效果
An example of multi module collaboration based on NCF
Unity adds a function case similar to editor extension to its script, the use of ContextMenu