MySQL master (semi-synchronous replication asynchronous replication) Copy from

1.MySQl master-slave replication

  • Principle : Copy binlog log of the master server from the server to perform again, to achieve a consistent state from the master data.

  • Process : Open an I / O threads from the library, the request to log Binlog main library. A master node binlog dump thread turn, check their binary logs, and sends the slave node; save data received from the library to the relay log (log Relay), additional SQL open a thread, the operation in the Relay perform again on the machine itself

  • Advantages :
    • As a backup database, and does not affect traffic
    • Do read and write separation, typically a library to write, read one or more libraries, distributed on different servers, and give full play to the performance of the database server, but to ensure data consistency

2. From the master copy of the log format

Here log format refers to binary logs in three formats: statement statement-based replication, the row row-based replication, based on statements and row (mix) replication. The way in which the row-based replication from the primary to better ensure the consistency of the data repository, but a large amount of log, disk space issues to consider when setting

show variables like ‘%binlog%format%’;    #查看当前使用的binlog的格式
set binlog_format = ‘row’;                #设置格式,这种方法只在当前session生效
set global binlog_format = ‘row’;       #在全局下设置binlog格式,会影响所有的Session

3. Copy architecture

3.1, a master multi-slave architecture

When requested main reservoir pressure is very large, the configuration can be achieved by a multi-copy master-slave architecture separate read and write, a large amount of real-time requirements are not very high up requests to multiple database by reading data from the load balancing, reduced reads the pressure of the main library. And when the main library downtime can be a switch-based bank from the bank to continue to provide services

3.2, multi-level replication architecture

Because each from the library at the main library will have a separate thread to push Binlog Dump binlog log, so with the increase in the number of libraries, IO pressure and the pressure of the main library network will also increase, this time, a multi-stage copy architecture came into being.

Multi-stage architecture only on the basis of a replication master from the plurality, and each of the main library and then adds a library Master2 from between the two main libraries, the two main libraries are only used to a main library pushed to its BInlog log pushed to the individual from the library, in order to alleviate the pressure of a push main library.

But its drawback is Binlog logs to be copied twice to reach from the library, increasing the delay replication.

We can solve this problem by applying Blackhol storage engine (the black hole engine) from the library in the secondary, lower latency multi-level replication.

"Black hole engine" is written in the data table Blackhole not written to disk, so the table will always be empty Blackhole list, to insert data / update / delete records only in Binlog in, and copy it to go from the library .

3.3, dual-master replication / Dual Master architecture

Double replication scheme intended for all of a scene from the switching master

In architecture there is only one main library, when the main library is down, which will be a switch-based bank from the bank to continue to provide services. The original main library there is no data source, and then when the new main library received new data, the original master database was not synchronized, so their data is more and more big, then the original will not be able to become the main library the main one from the replication environment. When the original primary database back to normal, need to be added to the replication environment.

In order to avoid repeating problems that add the main library, two master copy came into being. Two databases from each other mainly, when the main library down the recovery, because it is the original from the library (now the main library) from the machine, so it will still copy the data on the new main library. Regardless of how the role of the main library switch, the original primary database will not be out of the replication environment.

4. replication

MySQL master copy from two replication, asynchronous replication and are semi-sync

4.1 Asynchronous Replication

1, logic,

That is the default MySQL replication is asynchronous, the main library after the completion of the transaction execution submitted by the client will immediately return the results to the client, and does not care whether it has received treatment from the library, so there will be a problem, if the main crash out, this time on the main transaction has been submitted may not be transferred from the library, if at this time, will enhance the main force, may lead to incomplete data on the new primary.

2, technically

The main library affairs Binlog write events to Binlog file, in which case only the main library Dump thread sends notice about these new Binlog, then the primary database will continue to process the commit operation, but this time will not spread any guarantee that these Binlog a node from the library.

4.2 fully synchronous replication

1, logic,

It means that when it returned to the client the main library executing the transaction, all of the libraries are executed the transaction. All because of the need to wait for completion of the transaction executed from the library to return, so the whole synchronous replication performance is bound to receive a serious impact.

2, technically

When the primary database transaction is committed, all the nodes must be received from the library, APPLY and submit the transaction, then the main thread library to continue to do follow-up operation. But the disadvantage is that the main library to complete a transaction time will be stretched, reduced performance.

4.3 semi-synchronous replication

1, logic,

Is interposed between fully synchronous with one copy of the full asynchronous replication, only the primary database and wait at least one receive Flush Binlog to Relay Log file can, without waiting for all the primary database repository feedback to the master node from the library from the library . Meanwhile, here is a feedback received, not been fully completed and submitted feedback, so, save a lot of time.

2, technically

Be between asynchronous replication and fully synchronous replication, the master database After you perform a transaction submitted by the client does not immediately returned to the client, but wait at least one received from the library to the relay log in and write it back to the client. With respect to the asynchronous replication, semi-synchronous replication improves data security, but it also caused some delay, the delay is at least a TCP / IP round trip time. Therefore, semi-sync is preferably used in low-latency network.

Guess you like

Origin www.cnblogs.com/bigox/p/11530540.html