zoukankan      html  css  js  c++  java
  • MySQL学习(二十四)主从同步-半同步

    概述

    MySQL 默认是异步复制,半复制是为了数据一致性,防止异步同步数据过程中,事务丢失。同步复制的话可以保证数据的一致性,数据不丢失可以回滚,但是响应慢,master 必须等待 slave 返回的ack响应才算完整地完成事务,而异步复制则有可能出现数据不一致的问题,半复制处于异步复制和同步复制的中间。
    半复制只需要等待(默认)一台 slave 完成了写入就算完成事务请求了。

    半复制过程

    Semisynchronous replication can be used as an alternative to asynchronous replication:
    
    - A slave indicates whether it is semisynchronous-capable when it connects to the master.
    
    - If semisynchronous replication is enabled on the master side and there is at least one semisynchronous slave, a thread that performs a transaction commit on the master blocks and waits until at least one semisynchronous slave acknowledges that it has received all events for the transaction, or until a timeout occurs.
    
    - The slave acknowledges receipt of a transaction's events only after the events have been written to its relay log and flushed to disk.
    
    - If a timeout occurs without any slave having acknowledged the transaction, the master reverts to asynchronous replication. When at least one semisynchronous slave catches up, the master returns to semisynchronous replication.
    
    - Semisynchronous replication must be enabled on both the master and slave sides. If semisynchronous replication is disabled on the master, or enabled on the master but on no slaves, the master uses asynchronous replication.
    
    

    为了理解,以下列出和同步复制和异步复制的对比。

    To understand what the “semi” in “semisynchronous replication” means, compare it with asynchronous and fully synchronous replication:
    
    With asynchronous replication, the master writes events to its binary log and slaves request them when they are ready. There is no guarantee that any event will ever reach any slave.
    
    With fully synchronous replication, when a master commits a transaction, all slaves also will have committed the transaction before the master returns to the session that performed the transaction. The drawback of this is that there might be a lot of delay to complete a transaction.
    
    Semisynchronous replication falls between asynchronous and fully synchronous replication. The master waits only until at least one slave has received and logged the events. It does not wait for all slaves to acknowledge receipt, and it requires only receipt, not that the events have been fully executed and committed on the slave side.
    

    参考资料 :

  • 相关阅读:
    关于findViewById返回空指针的错误
    android客户端向服务器发送图片和文字,类似于发微博。能用json格式发送吗?
    nodejs 学习资料大全
    篇章三:[AngularJS] 使用AngularCSS動態載入CSS
    篇章二:[AngularJS] 使用AngularAMD動態載入Service
    篇章一:[AngularJS] 使用AngularAMD動態載入Controller
    Angular 资料大集合
    js-音乐播放器,播放|暂停|滑块的功能
    JS-以鼠标位置为中心的滑轮放大功能demo1
    使用 Electron 构建桌面应用(拖动控制篇)
  • 原文地址:https://www.cnblogs.com/Benjious/p/12844062.html
Copyright © 2011-2022 走看看