当前位置:网站首页>Distributed | several steps of rapid read / write separation
Distributed | several steps of rapid read / write separation
2022-06-29 17:44:00 【ActionTech】
author : Wang Juan
Love can be born dble Team test members , Mainly responsible for dble Requirements testing , Automated writing and community problem solving . People don't talk too much .
In this paper, the source : Original contribution
* Produced by aikesheng open source community , Original content is not allowed to be used without authorization , For reprint, please contact the editor and indicate the source .
dble from 3.20.10 Version start ⽀ It has a simple read-write separation function , It can be separated from the functions of database and table ⽤.
How to quickly have read-write separation ?
First step , Get a group ready mysql real example , And ensure that this group mysql The master-slave replication relationship of the instance is normal . The following uses one master and two slaves mysql:
Lord :172.100.9.6:3307
from :172.100.9.2:3307、172.100.9.3:3307
Separate to 2 From instances show slave status , Check whether the replication relationship is normal .

The second step , stay db.xml To configure mysql example . as follows :
<dbGroup rwSplitMode="1" name="ha_group1" delayThreshold="100">
<heartbeat>show slave status</heartbeat>
<dbInstance name="hostM1" password="******" url="172.100.9.6:3307" user="test" maxCon="1000" minCon="10" primary="true"/>
<dbInstance name="hostS1" password="******" url="172.100.9.2:3307" user="test" maxCon="1000" minCon="10" readWeight="1"/>
<dbInstance name="hostS2" password="******" url="172.100.9.3:3307" user="test" maxCon="1000" minCon="10" readWeight="1"/>
</dbGroup>
To configure dbGroup The following parameters should be paid attention to :
rwSplitMode: Load balancing mode for read operations , Optional value 0/1/2/3
In into ⾏ When reading load balancing, it will proceed according to this configuration ⾏
0: Do not balance , Distribute directly to the primary instance , Slave instances will be ignored , Will not try to build ⽴ Connection pool , But there will be ⼼ Jump connect
1: Read operations are balanced across all slave instances , When all slave instances are not ⽤ when , An error will be reported when issuing a statement .
2: Read operations are balanced across all instances .
3: Read operations are balanced across all slave instances , When all slave instances are not ⽤ when , Send the statement to the main instance .delayThreshold: Specify the master-slave delay threshold , Unit second , Default -1 , surface ⽰⽆ Delay
In into ⾏ When reading the load balance, it will be based on the latest ⼀ Time of ⼼ Skip status and delay of Reading database and main database ⾏ Judge , If master-slave replication does not ⼯ The delay in making or copying exceeds delayThreshold To configure , Then it is considered that this node is not suitable for ⾏ Read , Depend on ⼼ Jump statement is show slave status . If delayThreshold=-1 Then the load balancing selection will not be read ⾏ Delay detection .readWeight: Node weight ( Load balancing makes ⽤)
During the load balancing process, you will check whether the weights of all nodes are equal , If it's not equal , Then the pressure will be allocated according to the weight ⼒. The value must be ⼤ Is equal to 0 The integer of . If it is equipped with 0 surface ⽰ This node does not participate in reading . Attention should be paid to , Total weight ( Sum of weights of all nodes ) must ⼤ On 0.How to distinguish between read nodes and write nodes ?
Write nodes :primary=“true”
Read node :primary No configuration or primary=“false”
The third step ,user.xml Add read / write separation users . adopt dbGroup Assign to db.xml in dbGroup Of name.
<rwSplitUser name="rwSplit1" password="111111" dbGroup="ha_group1" />
Step four , To dble The management side executes reload @@config_all , Make configuration effective . At this point, you can use the newly created read-write separation user rwSplit1 Sign in dble 了 .
How to verify whether the read / write separation configuration is effective ?
Separate to 3 individual mysql Instance execution :set global general_log = on , Turn on general log .

Use rwSplit1 The user login dble 8066 port , Perform the following sql :
insert into test_table values (1, ‘name1’),(2, ‘name2’);
select * from test_table;

View the write node general log ,insert The statement is sent to the write node .

Point by point view 2 The number of read nodes general log ,select Statement to one of the read nodes .

Add :
1、 At the same time open dble When reading and writing the functions of separation and database and table separation , Sub database and sub table quotation ⽤ Of dbGroup and Read write separation citation ⽤ Of dbGroup Must be independent of each other ⽴.rwSplitUser lead ⽤ Of dbGroup , Only in the db.xml It can be defined in .
2、 Multiple rwSplitUser Can lead to ⽤ Same as ⼀ individual dbGroup .
3、dble Read / write separates which statements are sent to the primary instance , Which statements are sent to the slave instance ? Reference resources :https://github.com/actiontech/dble/discussions/3145
边栏推荐
- 传承中华美德,关注中老年大健康,育润奶粉敬老情浓
- 一次采集JSON解析错误的修复
- Bottom level internal skill cultivation
- [the sixth operation of modern signal processing]
- Error:Connection refused: connect
- Visio标注、批注位置
- The aggregate function in the epidisplay package of R language divides numerical variables into different subsets based on factor variables, and calculates the summary statistics and aggregate data. W
- VB.Net读写NFC Ntag标签源码
- mysql视图能不能创建索引
- What is a SCM system? What are the advantages of a supply chain management system?
猜你喜欢

Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what

Mysql database literacy, do you really know what a database is

How to solve the 2003 error of MySQL in Linux

Let's start with a bug that was cheated by the app store

Opencv+yolo-v3 for target tracking

Leetcode daily question - 535 Encryption and decryption of tinyurl

linux中mysql 1045错误如何解决

Online sql to CSV tool

Walk with love, educate and run poor families, and promote public welfare undertakings

Selenium file upload method
随机推荐
[try to hack] cookies and sessions
面试中问最常问的海量数据处理你拿捏了没?
人脸识别4-百度商用方案调研
2022春夏系列 KOREANO ESSENTIAL重塑时装生命力
R语言使用epiDisplay包的kap函数(kap.2.raters函数)计算Kappa统计量的值(总一致性、期望一致性)、对两个评分对象的结果进行一致性分析、评分的类别为多个类别
一次采集JSON解析错误的修复
Timer interrupt experiment based on stm32f103zet6 library function
Set double click to run the jar file
Can MySQL views create indexes
Visual Studio插件CodeRush正式发布v22.1——优化调试可视化工具
MaxCompute字符串替换函数-replace
selenium 组合键操作
mac安装php7.2
阿里云不同账号新旧服务器镜像迁移数据迁移同步
第42期:MySQL 是否有必要多列分区
力扣今日题-535. TinyURL 的加密与解密
R语言使用自定义函数编写深度学习线性激活函数、并可视化线性激活函数
Go语言多方式并发实现龟兔赛跑
SRM supplier collaborative management system function introduction
How to use the chart control of the b/s development tool devextreme - customize the axis position?