当前位置:网站首页>MySQL数据库主从同步,一致性解决方案
MySQL数据库主从同步,一致性解决方案
2022-06-29 11:32:00 【一只小小狗】
MySQL数据库主从同步,一致性解决方案
方法1 半同步复制
介于异步复制和同步复制之间,主库在执行完客户端提交的事务后不会立即返回给客户端,
而是至少要等到一个从库接收并写到redo log中,才会返回给客户端,相对于异步复制,半同步复制提高了数据的安全性
- 半同步复制原理
事务在主库写完binlog后,需要从库返回一个已接收,才能返回给客户端
确保事务提交后binlog至少传输到一个从库
不保证从库应用完这个事务的binlog
优点:利用数据库原生功能,比较简单
缺点:主库的写请求时延会增长,吞吐量会降低
方法2 数据库中间件
- 所有的读写请求都走数据库中间件,通常情况下写请求走主库,读请求走从库
记录所有路由到写库的key, 如果在主从同步的窗口内(假设500ms),有读请求过来了,
此时从库有可能还是旧的数据,就需要将key上的读请求路由到主库访问
在主从同步时间过完后,对应key的读请求继续路由到从库
优点:能保证绝对一致,
缺点:数据库中间件的成本较高
方法3 缓存记录写key法
- 写请求
如果key要发生写操作,记录到cache里,设置主从同步的缓存超时时间,比如500ms
然后修改主数据库
读请求
先到缓存里查,对应key有没有相关数据
如果有,说明缓存命中,这个key刚刚发生过写操作,此时需要将请求路由主库读取最新的数据
如果没有,说明缓存没有命中,说明这个key近期没有发生过写操作,此时将请求路由到从库,继续读写分离
优点:相对数据库中间件,成本较低
缺点:为了保证一致性,引入了cache组件,并且读写数据库时都多了缓存操作
如有错误欢迎指正
边栏推荐
- The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
- Helping the ultimate experience, best practice of volcano engine edge computing
- RepOptimizer: 其实是RepVGG2
- &3 在浏览器中查看请求报文和响应报文
- 杰理之关于 TWS 配对方式配置【篇】
- Pro test! Centos7 deploy PHP + spool
- 如何查看网站已经保存的密码
- GBase8s数据库INTO TEMP 子句创建临时表来保存查询结果。
- GBase8s数据库select有ORDER BY 子句5
- 杰理之关于 TWS 声道配置【篇】
猜你喜欢

Pro test! Centos7 deploy PHP + spool

Embedded database development programming (IV) -- DDL, DML

ERP编制物料清单 华夏

面试突击61:说一下MySQL事务隔离级别?

Sofaregistry source code | data synchronization module analysis

如何查看网站已经保存的密码
Some printer driver PPD files of Lenovo Lingxiang lenovoimage
![Jerry's about TWS pairing mode configuration [chapter]](/img/c8/d78e817295169753244299545d9aba.png)
Jerry's about TWS pairing mode configuration [chapter]

基于字节码的统一异常上报实践

面试突击61:说一下MySQL事务隔离级别?
随机推荐
GBase8s数据库select有ORDER BY 子句5
Ensure drinking water safety! Panyu Shawan waterway water quality online monitoring system passed the acceptance
Easy express: we use Zadig to realize 10000 times of construction and deployment, smart operation and maintenance, and release development productivity
The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
Object class - the father of ten thousand classes
2022年资料员-岗位技能(资料员)操作证考试题库及模拟考试
Sofaregistry source code | data synchronization module analysis
Meichuang was selected as one of the first member units of the "business security promotion plan" of the ICT Institute
MATLAB Gui 实现点击按钮,打开文件对话框,导入图片功能
恒泰证券开户安全吗 证券排名
保障饮用水安全!番禺沙湾水道水质在线监测系统通过验收
ArtBench:第一个类平衡的、高质量的、干净注释的和标准化的艺术品生成数据集
ERP编制物料清单 华夏
AUTOCAD——文字显示方式、CAD怎么直接打开天正图纸
DALL-E 2背后的工程实践:确保模型的输出符合内容政策
Li Kou daily question - day 31 -1779 Find the nearest point with the same X or Y coordinate
Is the table queried by this EMR sparksql node ODPs?
What is the main account of Chia Tai futures used for 4 quotation software?
When a technician becomes a CEO, what "bugs" should be modified?
杰理之关于 TWS 声道配置【篇】