[Original] problems encountered during MySQL switchover based on Keepalived

Source: Internet
Author: User
[Original] problems encountered during MySQL switchover based on Keepalived Problem Description:
MySQL implements master-slave switchover based on keepalived. Business A and Business B (in fact, the businesses running on A and B are the same) use MySQL for database query at the same time. Restart the keepalived service to test whether the MySQL master/slave switchover can provide normal services for the business.

Symptom:
After the MySQL master-slave switchover, the TCP connection information related to business A has been changed to A new TCP connection, and the TCP connection information related to business B remains unchanged.

The specific environment is as follows::
Business A: 172.16.177.158
Business B: 172.16.177.159

VIP: 172.16.177.147
MySQL master: 172.16.177.148
MySQL slave: 172.16.177.149




In normal service running status, service A establishes six TCP connections with the MySQL master (148) through the VIP (which the business developer informs), corresponding to the ports respectively.
43666, 43668, 43669, 43670, 43673, 43674.

When the VIP switch is completed by restarting the keepalived service on the 148 host, and the MySQL master/slave switchover is achieved, the following packet capture information is displayed:

The following is the TCP link information on 158.




We can see that there are 10 RST ......, Well, no matter why four more.

Next, let's take a look at the connection information from MySQL master 148.



From the two above, we can only see that there are new requests on the two TCP links, and the TCP resend occurs due to the restart of keepalived. The two TCP links correspond to ports 43673 and 43669 respectively.
Here, the resend request port is the same as that shown in packet capture on 158.

Let's take a look at the connection information from MySQL 149 (formerly MySQL slave.




It can be seen that 10 TCP links are dropped by RST. It corresponds to the above 10 TCP links.

In summary, the entire process can be described as follows:
  • At the beginning, 158 and 148 established six OCS business TCP connections;
  • When keepalived is restarted, TCP connections that use ports 43673 and 43669 are in the process of signaling interaction, while VIP 147 is drifting from 148 to 149, at this time, requests on the two TCP links will trigger retransmission because no response is received;
  • After the VIP is successfully bound to 149, the retransmission request on the preceding two TCP links will be sent to RST, and the request will be sent to RST only when there are new requests on other TCP links. After being RST, the OSC will re-establish the TCP connection.
The following describes the status of each TCP link separately:

TCP link of port 43673.

TCP link with Port 43669.

TCP link with Port 43666.

TCP link with Port 43674.

TCP link with Port 43670.

TCP link with Port 43668.

TCP link with Port 43671.

TCP link with Port 43665.

TCP link with Port 43672.

TCP link with Port 43667.



This is also true for businesses of 159.

Summary:
It is worth thinking about the emergence of the above problems: restart keepalived to enable the MySQ master/slave switchover method for practical application scenarios ?! If the master-slave switchover is similar to the one caused by keepalived restart, how can we solve the inconsistency between the master and the slave ?! Is it appropriate for a business program to trigger a detection interval for the current TCP link in the "semi-open" status through a certain retention mechanism? What is the value of wait_timeout in MySQL !?
What is truly disturbing is that the master/slave switchover is only implemented by restarting keepalived. no tcp fin or RST is received on either the MySQL side or the business side, however, TCP link problems can only be found when there are "actions" at the business layer. this phenomenon will inevitably cause some problems for services like MySQL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.