当前位置:网站首页>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
边栏推荐
- 基于STM32F103ZET6库函数串口实验
- [webdriver] upload files using AutoIT
- 与爱同行,育润走进贫困家庭,助推公益事业
- Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly
- Browser large screen capture
- Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]
- The dplyr package filter function of R language filters the data in dataframe data through combinatorial logic (and logic). The content of one field is equal to one of the specified vectors, and the v
- Error:Connection refused: connect
- 开源仓库贡献 —— 提交 PR
- Face recognition 4- research on Baidu commercial solutions
猜你喜欢

How to solve MySQL 1045 error in Linux

mysql. What is the concept of sock

mysql.sock的概念是什么

Does MySQL support foreign keys

How to use the chart control of the b/s development tool devextreme - customize the axis position?

Basic operations such as MySQL startup under Windows platform

Automatic vending machine

MySQL触发器如何创建与删除

从一个被应用商店坑了的BUG说起

How to create a virtual image
随机推荐
[webdriver] upload files using AutoIT
布隆过滤器:
阿里云不同账号新旧服务器镜像迁移数据迁移同步
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
基于STM32F103ZET6库函数串口实验
Force deduction daily question 06.29 add two numbers
Createstore for Redux source code analysis
3h精通OpenCV(九)-最简单的人脸检测
Self taught structure (small turtle C language)
ISO 32000-2 国际标准7.7
What are the usage scenarios for locks in MySQL
Does MySQL support foreign keys
Basic operations such as MySQL startup under Windows platform
mysql如何查询表的字符集编码
从一个被应用商店坑了的BUG说起
R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
R语言dplyr包filter函数通过组合逻辑(与逻辑)过滤dataframe数据中的数据、其中一个字段的内容等于指定向量中的其中一个,并且另外一个字段值大于某一阈值
数字孪生能源系统,打造低碳时代“透视”眼
Maidong Internet won the bid of Dajia Insurance Group