当前位置:网站首页>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
边栏推荐
- Tencent cloud released orbit, an automated delivery and operation and maintenance product, to promote enterprise applications to be fully cloud native
- 开源仓库贡献 —— 提交 PR
- 【WebDriver】使用AutoIt上传文件
- Digital twin energy system, creating a "perspective" in the low-carbon era
- Basic operations such as MySQL startup under Windows platform
- Can MySQL views create indexes
- 双亲委派机制
- Segment tree and tree array template (copy and paste are really easy to use)
- mongoTemplate - distinct 使用
- Uploading files using AutoIT
猜你喜欢
Split palindrome string [dp + DFS combination]
Online text digit recognition list summation tool
Force deduction daily question 06.29 add two numbers
位图的详细介绍及模拟实现
关于日期相加减问题
OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
Digital twin energy system, creating a "perspective" in the low-carbon era
How to solve MySQL 1045 error in Linux
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
Leetcode daily question - 535 Encryption and decryption of tinyurl
随机推荐
Leetcode daily question - 535 Encryption and decryption of tinyurl
Selenium key combination operation
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
Master slave replication of MySQL
Walk with love, educate and run poor families, and promote public welfare undertakings
填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]
自动收售报机
Error:Connection refused: connect
mysql如何查询表的字符集编码
How to use the chart control of the b/s development tool devextreme - customize the axis position?
Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner
R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
测试dble split功能执行+导入耗时shell脚本参考
The soft youth under the blessing of devcloud makes education "smart" in the cloud
使用 SSH 方式拉取代码
PCB frame drawing - ad19
What value can SRM systems bring to the enterprise?
布隆过滤器:
Selenium file upload method
[the sixth operation of modern signal processing]