說MGR - MGR的基本原理

狀態機複製


MGR本質上一個狀態機複製的集羣。在狀態機複製的架構中,數據庫被當做一個狀態機。每一次寫操作都會導致數據庫的狀態變化。爲了創建一個高可用的數據庫集羣,有一個組件,即事務分發器,將這些操作按照同樣的順序發送到多個初始狀態一致的數據庫上,讓這些數據庫執行同樣的操作。因爲初始狀態相同,每次執行的操作也相同,所以每次狀態變化後各個數據庫上的數據保持一致。



分佈式的狀態機複製


事務分發器是一個單點,爲了避免單點故障,可以採用分佈式的狀態機複製。在分佈式的狀態機複製中,有多個事務分發器,它們彼此互相通信。事務分發器可以同時接收事務請求,就像單個事務分發器同時接收事務請求一樣。從應用層來說,併發的事務發到同一個事務分發器和發到不同的事務分發器上效果是一樣的。事務分發器之間會互相通信,把所有的事務彙總、排序。最終,每個事務分發器上都有一份完整的排好序的事務請求。每個事務分發器只連接到一個數據庫上,並負責把事務請求依次發送到相連的數據庫上去執行,其就是一個分佈式狀態機複製的模型了。



分佈式的高可用數據庫


將分佈式的事務分發模塊集成到數據庫系統中,就變成了一個分佈式的高可用數據庫系統。用戶通過數據庫的用戶接口執行事務。數據庫收到事務請求後,首先交由事務分發模塊處理。事務分發模塊將事務彙總排序,然後依次交由數據處理模塊去執行這些事務。如果去掉內部的細節,就會發現這是一個非常簡潔的數據庫集羣方案。MGR就是這樣一個分佈式的高可用MySQL系統。



品味來自官檔的一段話~


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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章