狀態(tài)機復制
成都創(chuàng)新互聯(lián)公司是一家專業(yè)從事網(wǎng)站建設、網(wǎng)絡營銷、微信平臺小程序開發(fā)、網(wǎng)站運營為一體的建站企業(yè);在網(wǎng)站建設告別千篇一律,告別似曾相識,這一次我們重新定義網(wǎng)站建設,讓您的網(wǎng)站別具一格。成都響應式網(wǎng)站建設公司,實現(xiàn)全網(wǎng)營銷!一站適應多終端,一樣的建站,不一樣的體驗!
MGR本質(zhì)上一個狀態(tài)機復制的集群。在狀態(tài)機復制的架構(gòu)中,數(shù)據(jù)庫被當做一個狀態(tài)機。每一次寫操作都會導致數(shù)據(jù)庫的狀態(tài)變化。為了創(chuàng)建一個高可用的數(shù)據(jù)庫集群,有一個組件,即事務分發(fā)器,將這些操作按照同樣的順序發(fā)送到多個初始狀態(tài)一致的數(shù)據(jù)庫上,讓這些數(shù)據(jù)庫執(zhí)行同樣的操作。因為初始狀態(tài)相同,每次執(zhí)行的操作也相同,所以每次狀態(tài)變化后各個數(shù)據(jù)庫上的數(shù)據(jù)保持一致。
分布式的狀態(tài)機復制
事務分發(fā)器是一個單點,為了避免單點故障,可以采用分布式的狀態(tài)機復制。在分布式的狀態(tài)機復制中,有多個事務分發(fā)器,它們彼此互相通信。事務分發(fā)器可以同時接收事務請求,就像單個事務分發(fā)器同時接收事務請求一樣。從應用層來說,并發(fā)的事務發(fā)到同一個事務分發(fā)器和發(fā)到不同的事務分發(fā)器上效果是一樣的。事務分發(fā)器之間會互相通信,把所有的事務匯總、排序。最終,每個事務分發(fā)器上都有一份完整的排好序的事務請求。每個事務分發(fā)器只連接到一個數(shù)據(jù)庫上,并負責把事務請求依次發(fā)送到相連的數(shù)據(jù)庫上去執(zhí)行,其就是一個分布式狀態(tài)機復制的模型了。
分布式的高可用數(shù)據(jù)庫
將分布式的事務分發(fā)模塊集成到數(shù)據(jù)庫系統(tǒng)中,就變成了一個分布式的高可用數(shù)據(jù)庫系統(tǒng)。用戶通過數(shù)據(jù)庫的用戶接口執(zhí)行事務。數(shù)據(jù)庫收到事務請求后,首先交由事務分發(fā)模塊處理。事務分發(fā)模塊將事務匯總排序,然后依次交由數(shù)據(jù)處理模塊去執(zhí)行這些事務。如果去掉內(nèi)部的細節(jié),就會發(fā)現(xiàn)這是一個非常簡潔的數(shù)據(jù)庫集群方案。MGR就是這樣一個分布式的高可用MySQL系統(tǒng)。
品味來自官檔的一段話~
The most common way to create a fault-tolerant system is to resort to making components redundant, in other words the component can be removed and the system should continue to operate as expected. This creates a set of challenges that raise complexity of such systems to a whole different level. Specifically, replicated databases have to deal with the fact that they require maintenance and administration of several servers instead of just one. Moreover, as servers are cooperating together to create the group several other classic distributed systems problems have to be dealt with, such as network partitioning or split brain scenarios.
Therefore, the ultimate challenge is to fuse the logic of the database and data replication with the logic of having several servers coordinated in a consistent and simple way. In other words, to have multiple servers agreeing on the state of the system and the data on each and every change that the system goes through. This can be summarized as having servers reaching agreement on each database state transition, so that they all progress as one single database or alternatively that they eventually converge to the same state. Meaning that they need to operate as a (distributed) state machine.
MySQL Group Replication provides distributed state machine replication with strong coordination between servers. Servers coordinate themselves automatically when they are part of the same group.