MySQL asynchronous replication, semi-synchronous replication, enhanced semi-synchronous replication (the most complete in history)

Background: From the little buddy question

My friend's problem:

When mysql master-slave synchronization, what is the concept of semi-synchronization and enhanced semi-synchronization, I read that it is a bit unclear on the Internet, and I have not found a suitable explanation.

insert image description here

Here, Nien will give you a systematic and systematic review. Also include this question and reference answers in our "Nin Java Interview Collection PDF" MySQL topic, for the reference of later friends, and improve everyone's 3-high architecture, design, and development levels.

Note: This article is continuously updated in PDF. For the latest PDF files of Nien’s architecture notes and interview questions, please get them from the link below: Code Cloud

At present, MySQL mainly has three replication methods

1) Asynchronous replication

2) Semi-synchronous replication

3) Enhanced semi-synchronous replication

Recommended use: It is recommended to use asynchronous replication for high performance requirements. If the financial business is running, it is recommended to use enhanced semi-synchronous replication, and use ROW+GTID+5.7 or above

asynchronous replication

The default method of MySQL replication

illustrate:

If you don't understand this well, this is rocketmq's asynchronous brushing + asynchronous replication

For details, please refer to Nien's rocketmq high availability video, Chapter 17 video

semi-synchronous replication

5bfef20d053a20f3221f93b190e17726.png

rpl_semi_sync_master_wait_point=after_commit

illustrate:

If you don't understand this well, this is rocketmq's synchronous brushing + asynchronous replication

For details, please refer to Nien's rocketmq high availability video, Chapter 17 video

Advantages and disadvantages of semisynchronous replication

Disadvantage 1: phantom reading

When a user initiates a transaction, the transaction has been written to the redo log and the binlog log, but the transaction has not been written to the slave library. At this time, it is at the waiting slave dump. At this time, another user can read this data, and he himself could not;

Cons 2: Data Loss

After a transaction crashes at the waiting slave dump, the master library will have one more piece of data than the slave library

Question: At this time, if the master-slave replication is restored, can the data be synchronized to the slave server normally? (not tested!!)

Enhanced Semisynchronous Replication

7834e199a9c2f014f7cb743da0b43fec.png

rpl_semi_rsync_master_wait_point=after_sync

Improvement 1: Solve phantom reading

When a user initiates a transaction, after the transaction is written into the binary, it synchronizes with the slave library. At this time, other users cannot read the data, which solves the phantom reading

Improvement 2: Solve data loss

After a transaction crashes at the waiting slave dump, you can observe whether the last gtid value of the master database exists on the slave database. If it exists, this data will be restored normally. If it does not exist, delete the redundant GTID value of the master database. Then recover to ensure the integrity of the data;

illustrate:

If you don't understand this well, this is rocketmq's synchronous brushing + synchronous replication

For details, please refer to Nien's rocketmq high availability video, Chapter 17 video

deployment test

Asynchronous replication environment: one master and one slave

主IP:192.168.20.206

从IP:192.168.20.212

3 steps are required:

1. Load the semi-synchronous replication plug-in to the main library, and modify the my.cnf parameters of the main library;

2. Load the semi-synchronous replication plug-in for the slave library, and modify the my.cnf parameters of the slave library;

3. Execute in the slave library and use the stop salve io_thread and start slave io_thread commands to get it done

1.1) The main library loads the semi-synchronous replication plug-in

install plugin rpl_semi_sync_master soname 'semisync_master.so';

1.2) The main library opens the semi-synchronous replication mode

set global rpl_semi_sync_master_enabled=1;

set global rpl_semi_sync_master_timeout=1000;

2.3) The main library modifies the my.cnf file

vim /etc/my.cnf

[mysqld]

###:for replcation

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

2.1) Load the semi-synchronous replication plugin from the library

install plugin rpl_semi_sync_SLAVE soname 'semisync_slave.so';

2.2) Open the semi-synchronous replication mode from the library

set global rpl_semi_sync_slave_enabled=1;

2.3) Modify the my.cnf file from the library

vim /etc/my.cnf

[mysqld]

###:for replcation

rpl_semi_sync_slave_enabled=1

3.3) Use stop slave io_thread and start slave io_thread to execute in the slave library;

stop slave io_thread;

start slave io_thread;

Semi-synchronous replication monitoring command:

show plugins;

show global status like '%semi%';

show global variables like '%semi%';

references

https://blog.csdn.net/weixin_35555531/article/details/113948452

The Path to Technical Freedom PDF is available at:

Realize your architectural freedom:

" Have a thorough understanding of the 8-figure-1 template, everyone can do the architecture "

" 10Wqps review platform, how to structure it? This is what station B does! ! ! "

" Alibaba Two Sides: How to optimize the performance of tens of millions and billions of data?" Textbook-level answers are coming "

" Peak 21WQps, 100 million DAU, how is the small game "Sheep a Sheep" structured? "

" How to Scheduling 10 Billion-Level Orders, Come to a Big Factory's Superb Solution "

" Two Big Factory 10 Billion-Level Red Envelope Architecture Scheme "

… more architecture articles, being added

Realize your responsive freedom:

" Responsive Bible: 10W Words, Realize Spring Responsive Programming Freedom "

This is the old version of " Flux, Mono, Reactor Combat (the most complete in history) "

Realize your spring cloud freedom:

" Spring Cloud Alibaba Study Bible " PDF

" Sharding-JDBC underlying principle and core practice (the most complete in history) "

" Get it done in one article: the chaotic relationship between SpringBoot, SLF4j, Log4j, Logback, and Netty (the most complete in history) "

Realize your linux freedom:

" Linux Commands Encyclopedia: 2W More Words, One Time to Realize Linux Freedom "

Realize your online freedom:

" Detailed explanation of TCP protocol (the most complete in history) "

" Three Network Tables: ARP Table, MAC Table, Routing Table, Realize Your Network Freedom!" ! "

Realize your distributed lock freedom:

" Redis Distributed Lock (Illustration - Second Understanding - The Most Complete in History) "

" Zookeeper Distributed Lock - Diagram - Second Understanding "

Realize your king component freedom:

" King of the Queue: Disruptor Principles, Architecture, and Source Code Penetration "

" The King of Cache: Caffeine Source Code, Architecture, and Principles (the most complete in history, 10W super long text) "

" The King of Cache: The Use of Caffeine (The Most Complete in History) "

" Java Agent probe, bytecode enhanced ByteBuddy (the most complete in history) "

Realize your interview questions freely:

4000 pages of "Nin's Java Interview Collection" 40 topics

Please go to the official account of "Technical Freedom Circle" to get the PDF file updates of the above Nien architecture notes and interview questions↓↓↓

Guess you like

Origin blog.csdn.net/crazymakercircle/article/details/130207052