• notice
  • Congratulations on the launch of the Sought Tech site

MysqlsemiSynchronousReplication Introduction

Foreword

    Before version 5.5, the default replication was asynchronous (Asynchronous) mode, and 5.5 provides Semisynchronous Replication mode in the form of plugins.Before introducing semi sync, let's first understand: semi-synchronous Asynchronous and synchronous Synchronous.

Asynchronous replication mode

    After the main library writes the committed transaction event to the binlog, it returns success to the app.This mode does not guarantee that any committed transaction will be delivered to any slave and successfully applied.

Full synchronous replication mode.

    When the main library submits a transaction event, the main library will wait for the transaction to be delivered to all slaves, and all slaves apply the transaction/event to notify the main library before returning the call, the transaction has been success.

   From the definition, it can be seen that the asynchronous mode cannot guarantee the security of data, because it does not wait for the transaction submitted by the main database to be placed on the slave, while the full synchronous mode has to wait for all slaves to confirm that it has been submitted.The transaction is successfully applied, which will cause a delay in transaction processing.semi sync takes a more compromised way to ensure that the committed transaction must exist on at least two machines (main database and any standby database), and immediately returns to the client that the transaction is successful.

1.Definition of Semisynchronous Replication
 In Semisynchronous Replication mode, when a transaction/event is submitted on the main library, it will wait for at least one slave to notify the main library.The slave has received the passed events and writes them to the relay log, and then returns to the session layer that the writing is successful.Or until the delivery log times out.

 Second, advantages and disadvantages

   Advantages: When the transaction returns successfully to the client, the transaction exists on at least two machines, enhancing data security.Compared with asynchronous mode and fully synchronous mode, it is a compromise.
    Disadvantage: Semi-synchronization does have a certain impact on database performance, because transaction submission must wait for slave feedback.The performance penalty depends on the tcp/IP network transmission time, that is, the time to transmit committed transactions and wait for slave feedback to have received transactions.

Three, MySQL semi-synchronous features

    1 When the slave connects to the main library, it will tell the main library whether it is in semi sync mode.
    2 If the master library enables semi sync mode, and at least one slave also enables semi sync mode, a process that operates transactions in the master library Before the transaction, the process will be in blocks waiting state or until a timeout occurs.
    3 If and only when the passed events are delivered to the slave, written to the relay log, and flushed to disk, the main library will be notified of completion.
    4 Semisynchronous replication must be enabled on both the primary and secondary ends at the same time, otherwise, if any one is not set, the replication mode between the primary and backup will be changed to asynchronous replication mode.
    5 When all slaves do not return to the master database within the time (the default value of rpl_semi_sync_master_timeout) and successfully receive the event, the master and slave will return to the original asynchronous state.
 For the second point, MySQL 5.7 has been optimized.The ack Collector (Col) thread waits for the notification of the successful receipt of the transaction by the standby database.This will be described in detail later-"5.7 Semisync replication enhancement".

Fourth, exception handling

   When the standby database crashes, the main database will turn off the semi-sync feature after a certain waiting timeout, and downgrade to ordinary asynchronous replication.This situation is relatively simple.
MySQL's error.log will prompt:

    The more difficult situation is: when the host/main library crashes, there may be some transactions that have been submitted in the main library, but have not yet been passed to any standby library, that is, these transactions All are not returned to the client, so the client that initiated the transaction does not know whether the transaction has been completed-"the wall transaction".At this time, if the client does not switch, but waits for the main library of Crash to recover, and continues to operate in the main library, the client will find that the previous "wall transactions" have been completed, and can continue to carry out subsequent business processing; another In this case, if the client fails over to the standby database, the client will find that the previous "wall transactions" have not been successful, and it needs to re-do these transactions, and then continue with subsequent business processing.In fact, the master and standby are inconsistent at this time.It is necessary to check which library is correct through the primary and secondary data verification, and then repair it.
V.Summary

   In short, compared with the asynchronous replication mode semi sync before MySQL 5.5, a great improvement has been made, which enhances the security of data, and it is acceptable to exchange security for a certain performance loss.The follow-up will introduce how to install and use semi sync.

Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

how to get lipitor without a preion & lt;a href="https://lipiws.top/"& gt;atorvastatin 20mg for sale& lt;/a& gt; atorvastatin 40mg oral

Zolhxb

2024-03-09

Leave a Reply

+