Database replication technology to copy some thinking about lagging

In addition to using replication technique can be tolerated node failures improve availability, also contains scalable (multi-node to process more requests) and latency (the distance between the user copy deployed geographically closer place) and the like.

In use master-slave replication, synchronization if you try to copy all of the copies of the single node failure or network outage will cause the entire system can not write. And the more nodes, the probability of failure is also higher, so much from a copy of the general way is through asynchronous replication.

Using asynchronous replication will result in the main, from inconsistent data nodes, this inconsistency theory is only temporary, and if you stop writing the database, after a period of time, the node will eventually catch up with the master node, this effect is also known as final consistency

Under actual circumstances, when the system is close to the design limit, or there is a problem (inevitable) network, then there may be a lag is not theoretical problem, but a real practical problems. Here are three replication latency issues that may arise, and the corresponding mechanisms Solutions

  • Read their writing
    to submit new data to refund to the main program, but when users read their own data, the data may come from the node, resulting in inconsistencies.

    In the case of the figure, the need to "read-after-write consistency", also known as read-write consistency of the mechanism to ensure that users can always see themselves updated with the latest submissions.
  • Monotonous reading
    as shown below, to see the latest content after the user has read outdated content, such as call-back time being, this time need to write monotonous consistency.
    In order to determine if a user is read more than once, you will never see the rollback phenomenon

  • Prefix read consistent
    causal appeared unusual, it is a particular problem partition (slice) appear in the database. The order mechanism is needed for a series of write request occurrence of certain order, then read the contents will be written in accordance with the time.

Program thinking to solve

在应用层层面可以提供比底层数据库更强有力的保证,如保证在主节点上进行特定类型的读取,而代价是,应用层代码会非常复杂且容易出错。所以应该假定数据库能“做正确的事情”,情况就简单的,最好的办法是抽象出一层,提供事务这种更强力的保证

Guess you like

Origin www.cnblogs.com/yeni/p/11987339.html