Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL semi-synchronous replication

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Introduction to semi-synchronous replication

What is semi-synchronous replication mode? Let's take a look at asynchronous replication mode, which is the default replication option for MySQL. Asynchronous replication is when the master database sends the binlog log to the slave database, and then it's gone. A problem exposed here is that when the slave server fails, it will certainly lead to data inconsistency between the master and slave database servers.

To solve the above problem, MySQL5.5 introduces a mode called semi-synchronous replication. By turning on this mode, you can ensure that the slave database receives the binlog log sent by the master database and writes it to its own relay log, and then feeds it back to the master database to inform you that the replication has been completed.

When this mode is turned on, when a timeout occurs, the master database will automatically switch to asynchronous replication mode until at least one binlog of the master database is received from the server and fed back to the master database. Only then will the primary database switch back to semi-synchronous replication mode.

Note:

Semi-synchronous replication mode must be turned on in both the master and slave servers, otherwise it will default to asynchronous replication mode.

2. Environmental description

Two linux virtual hosts

Linux version CentOS6.6, MySQL 5.5

Ip:192.168.95.11 (master), 192.168.95.12 (slave)

3. Installation and configuration

3.1. Installation premise

1. Must be MySQL5.5 or above

2. MySQL must have automatic loading function, that is, the have_dynamic_loading variable is YES (because we load and install this function plug-in in MySQL)

Show variables like 'have_dynamic_loading'; # checks whether it has automatic loading function.

3. Master-slave replication has been configured and ing is working.

Master-Slave replication configuration tutorial: h tt pvvl 6/p/6485819.html / w w.cn blo gs.co m/ph pstud y 2015-6/p/6485819.html

3.2. Installation

192.168.95.11 load installation:

1 mysql > install plugin rpl_semi_sync_master soname 'semisync_master.so';2 3 mysql > show plugins; # check whether the load is successful 4 5 mysql > SET GLOBAL rpl_semi_sync_master_enabled = 1; # enable semi-synchronous replication and disable it by default

192.168.95.12 load installation

1 mysql > INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so'; 2 3 mysql > show plugins; # check whether the load is successful 4 5 mysql > SET GLOBAL rpl_semi_sync_slave_enabled = 1; # enable semi-synchronous replication, default is 6 7 # restart slave server IO thread, and manually switch asynchronous mode to semi-synchronous mode 8 9 mysql > STOP SLAVE IO_THREAD;10 11 mysql > START SLAVE IO_THREAD

Configuration file 1 rpl_semi_sync_master_enabled=1 # master library configuration file is added, which means that starting MySQL in the future will automatically enable semi-synchronous replication 2 3 rpl_semi_sync_slave_enabled=1 # slave library configuration file addition, as above

4. View relevant parameters

1. Master and slave execute the command show variables like'% semi%'

Master:

Rpl_semi_sync_master_enabled=ON indicates that semi-synchronous replication is enabled

Rpl_semi_sync_master_timeout=1000 defaults to 1000 milliseconds, or 10-second timeout, and switches to asynchronous replication.

Rpl_semi_sync_master_wait_no_slave indicates whether to allow master. Everything has to wait for slave to receive confirmation. The default is ON.

Rpl_semi_sync_master_trace_level=32 indicates the debug level used to turn on semi-synchronous replication. Default is 32.

Slave:

Rpl_semi_sync_slave_enabled=ON indicates that semi-synchronous replication mode has been started in slave.

Rpl_semi_sync_slave_trace_level=32 indicates the debug level used to turn on semi-synchronous replication. Default is 32.

2. Master and slave execute the command show status like'% semi%'

Master

Rpl_semi_sync_master_status indicates whether the primary server uses asynchronous or semi-synchronous replication

Rpl_semi_sync_master_client indicates how many are configured for semi-synchronous replication from the server

Rpl_semi_sync_master_yes_tx indicates the number of successful submissions confirmed from the server

Rpl_semi_sync_master_no_tx indicates the number of failed submissions confirmed from the server

Slave:

Rpl_semi_sync_slave_status indicates that semi-synchronous replication is enabled from the server

5. Test

If the analog slave hangs up, and the master waits for 10 seconds and still does not receive the feedback signal, it will switch to asynchronous replication mode and continue to execute.

First create the database aa synchronously

1. Slave executes stop slave; to shut down master-slave replication

2. Master creates the table tab1 in the aa database and does not receive a feedback signal. After waiting for ten seconds (Rpl_semi_sync_master_timeout=1000 wait for timeout), continue to execute.

Master:

Slave:

3. Master creates a tab2 in the database and executes it without waiting for feedback.

[when feedback times out, master switches to asynchronous replication mode. It is in asynchronous mode at this time, there is no need to wait]

4. Slave executes start slave, starts data synchronization, establishes tab1 and tab2, feeds back to master, and switches to semi-synchronous replication.

5. Slave executes stop slave; to shut down master-slave replication

6. When master creates the table tab3 in the database, you need to wait 10 seconds to receive the slave feedback signal; wait for the timeout, switch to asynchronous replication mode, and continue to execute

[in step 4, data synchronization has been fed back to master, and master is already in semi-synchronous replication mode]

6. Summary

The performance and concurrency of semi-synchronous replication mode is lower than that of asynchronous replication mode, because each replication requires feedback, compared with one more step.

To be honest, I still don't quite understand why semi-synchronous replication can maintain the integrity of the data. If slave fails, master will not change back to asynchronous replication. It's no different from the previous full async. And even if there is one more feedback, what is the use of the feedback except for master to confirm it? If slave is dead and there is no feedback, there is no further way to deal with master.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report