当前位置:网站首页>Three implementation schemes of MySQL read-write separation
Three implementation schemes of MySQL read-write separation
2022-07-23 19:35:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
MySQL Three implementation schemes of read-write separation
List of articles
- MySQL Three implementation schemes of read-write separation
One 、 Building a “ One master and two slaves ” Of MySQL colony
First, build one mysql colony ( One master and two slaves ), Semi-synchronous replication :mysql Semi-synchronous replication , Three nodes .
Two 、 Read write separation implementation : Scheme 1
2.1 Configure multiple data sources
(1)、 be based on Spring/Spring Boot, Configure multiple data sources ( for example 2 individual ,master and slave)
(2)、 According to the concrete Service Method will manipulate data , Inject different data sources ,1.0 edition
By configuring multiple data sources , stay service Layer realizes read-write separation .
2.2 Use AbstractRoutingDataSource
(3)、 To improve the 1.1: Based on operation AbstractRoutingDataSource And custom annotations readOnly And Class , Simplify automatic data source switching
(4)、 Improve the second 1.2: Support configuring multiple slave libraries ;
Use AbstractRoutingDataSource And custom annotations .
(5)、 Improve three times 1.3: Support load balancing of multiple slave libraries
Ideas : stay myreadwritesep-abstract-rounting-v1 On the basis of , More than a read Data source of type , Then judge the annotated name by read When , stay read01 and read02 Choose... At random .
-- Create user , Execute... On the primary node
create schema performance;
CREATE USER 'performance'@'%' IDENTIFIED BY 'performance^pw';
GRANT ALL ON performance.* TO 'performance'@'%';
flush privileges;
-- Execute... On the primary node
create table performance.t_model_info(
m_id int(11) not null primary key auto_increment comment ' Primary key , Self increasing ',
model_type varchar(128) not null unique comment ' Module type ',
model_name varchar(128) not null unique comment ' Module name ',
model_status tinyint(1) not null default 0 comment '0 Enable , 1 Is not enabled '
)Engine=InnoDB AUTO_INCREMENT=1 default CHARSET=utf8mb4;2.3 The disadvantages of this version :
- Invasive strong ;
- “ After writing and reading ” Inconsistency ,server Method , Go to the main library first insert sentence , And then immediately select, But I can't find the data ;
3、 ... and 、 Read write separation implementation : Option two
3.1 adopt ShardingSphere-jdbc Read and write separation
improvement v1.0,ShardingSphere-jdbc Of Master-Slave function
1)SQL Parsing and transaction management , Automatic read-write separation
- First of all , Manage everything ;
- second , do SQL analysis , Automatic read-write separation ;
2) solve ” After writing and reading ” The problem of inconsistency
- If in a transaction , Write before they are read , The framework has an optimization ; In a business , The first few are poison , Just read it normally , As long as you meet someone who writes , No matter how many reads follow , Go to the main warehouse . This is the perfect solution “ After writing and reading ” The problem of inconsistency .
adopt Shardingsphere-jdbc The framework realizes the separation of reading and writing .
3.2 The disadvantages of this version :
- It's still invasive to the business ( This set of things , It needs to be configured into the business code );
- It is not friendly to the transformation of existing old systems ;
Four 、 Read write separation implementation : Option three
4.1 adopt ShardingSphere-Proxy Read and write separation
improvement v2.0, MyCat/ShardingSphere-Proxy Of Master-Slave function
1) You need to deploy a middleware , Rules are configured in middleware
2) Simulate one MySQL The server , No intrusion into the business system
shardingsphere-proxy Read and write separation .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/126809.html Link to the original text :https://javaforall.cn
边栏推荐
- Latex(katex)csdn 希腊字母表示,数学符号,集合符号,特殊标记
- 行业分析| 物流对讲
- Challenges of decentralized storage
- 【leetcode天梯】链表 · 022 链表中倒数第k个节点
- Little fish sends lidar | just dinner is the first lottery
- 固态硬盘的工作原理揭秘
- R语言检验样本是否符合正态性(检验样本是否来自一个正态分布总体):使用nortest包的sf.test函数检验样本是否符合正态分布(normality test)
- canvas绘制文本和清除绘制
- AE 教程,如何在 After Effects 中对 Illustrator 分图层文档进行动画绘制?
- MEE | 浙大程磊组开发设计与构建合成菌群新方法
猜你喜欢

【开发经验】开发项目踩坑集合【持续更新】

ACM MM 2022 Oral | DIG: 自监督文字识别的新框架,刷新11个公开场景文字数据集的识别性能,平均提升5%...

Todo fix bug tag feature and other configurations

H7-TOOL的I2C接口方式脱机烧录操作方法,已经发布(2022-07-16)

行业分析| 物流对讲

Type-C蓝牙音箱单C口可充电可OTG方案

为啥一问 JVM 就 懵B ?

Leetcode daily question (1514. path with maximum probability)

Weights & Biases (一)

树莓派3b串口登录前准备工作
随机推荐
Monotonic queue optimization DP
Shell
[machine learning] Wu Enda: lifelong learning
MySQL 啥时候用表锁,啥时候用行锁?
not all arguments converted during string formatting
Analyse de l'industrie | interphone logistique
一道题目初探组合数学与DP关系,可重集组合公式推导
时代潮头,华为将风帆对准数字金融的风与海
安全停止nodeos
公链之Sui(前脸书/Meta员工成立的新公链项目)
LeetCode每日一题(1514. Path with Maximum Probability)
Leetcode daily question (1514. path with maximum probability)
当代励志“女”录
FPGA flash reading and writing based on SPI
测试如何应对新的开发模式?
图学习总结
某些题目对应的智慧数据总结
行业分析| 物流对讲
【pm2】pm2常用命令
Notes of benthos