当前位置:网站首页>项目中遇到的线上数据迁移方案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预计不会太慢,效率之后有待验证)
边栏推荐
猜你喜欢

小发猫物联网平台搭建与应用模型

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
牛客小白月赛7 谁是神箭手

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

Go microservice (II) - detailed introduction to protobuf

Bi skills - permission axis

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

FPGA timing constraint sharing 01_ Brief description of the four steps

"Only one trip", active recommendation and exploration of community installation and maintenance tasks

如何使用Async-Awati异步任务处理代替BackgroundWorker?
随机推荐
The kth largest element in the array
Download the first Tencent technology open day course essence!
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Send and receive IBM WebSphere MQ messages
2021 Hefei informatics competition primary school group
The 300th weekly match of leetcode (20220703)
Pytorch学习(四)
Wireshark网络抓包
2019年蜀山区第十五届青少年信息学竞赛
指定输出的字符集
1002. A+B for Polynomials (25)(PAT甲级)
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
26. 删除有序数组中的重复项 C#解答
整理混乱的头文件,我用include what you use
SSL证书续费相关问题详解
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Is the securities account opened by qiniu safe?