您好,登錄后才能下訂單哦!
小編給大家分享一下Ceph Monitor Paxos算法怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
一些相關(guān)變量
last_pn:最新的proposal number;
accepted_pn:最新的接受的proposal number;
accepted_pn_from:peon接受最新的proposal number的leader的last_committed(也就是說(shuō)只接受比accepted_pn_from大的pn值)
first_committed:
last_committed:leader和peon都存在的,接受最新value的版本號(hào);
peer_first_committed:記錄集群成員中第一次commit的版本號(hào);
peer_last_committed:記錄集群成員中最新commit的版本號(hào);
一些函數(shù)解析
Paxos::init()
從MonitorDB中讀取last_pn/accepted_pn/last_committed/first_committed的值;
leader
Paxos::collect()
|__state = STATE_RECOVERING 設(shè)置當(dāng)前狀態(tài)為RECOVERING
|__初始化相關(guān)變量uncommitted_v/uncommitted_pn/uncommitted_value/peer_first_committed/peer_last_committed
|__檢查是否存在uncommitted value存在,通過(guò)查看MonitorDB中是否存在last_committed+1的值存在,若存在則初始化uncommitted_pn/uncommitted_v/uncommitted_value
|__Paxos::get_new_proposal_number() 生成一個(gè)單調(diào)遞增的且全局唯一的last_pn值
|__初始化accepted_pn=last_pn/accepted_pn_from=last_committed
|__遍歷mon->get_quorum(),創(chuàng)建MMonPaxos消息且設(shè)置消息的last_committed/first_committed/pn(accepted_pn)
|__向mon->get_quorum()中所有monitor節(jié)點(diǎn)發(fā)送MMonPaxos消息
Paxos::handle_last()
|__更新peer_first_committed/peer_last_committed數(shù)組
|__對(duì)于peon.first_committed > leader.last_committed+1,則leader調(diào)用mon->bootstrap()
|__Paxos::store_state() 保存MMonPaxos消息中value值的version_t>leader.last_committed && version_t<=peon.last_committed到leader的MonitorDB中
|__遍歷peer_last_committed數(shù)組中所有peon,對(duì)于數(shù)組中peon.version_t < leader.last_committed來(lái)說(shuō),創(chuàng)建MMonPaxos消息且消息類型是MMonPaxos::OP_COMMIT且將該消息發(fā)送給peon
|__對(duì)于peon.accepted_pn > leader.accepted_pn,則調(diào)用Paxos::collect()
|__對(duì)于peon.accetped_pn == leader.accepted_pn,則認(rèn)為peon認(rèn)可leader的proposal number,對(duì)于所有peon都認(rèn)可leader的proposal number,則設(shè)置當(dāng)前狀態(tài)為STATE_UPDATING_PREVIOUS
|__Paxos::begin(),調(diào)用參數(shù)是peon傳過(guò)來(lái)的uncommitted_value
Paxos::begin()
|__初始化accepted數(shù)組
|__對(duì)于last_committed==0的情況,設(shè)置first_committed=1
|__將參數(shù)中傳遞進(jìn)來(lái)的peon的uncommitted_value寫入到MonitorDB中
|__更新pending_v = last_committed+1/pending_pn=aceepted_pn且寫入到MonitorDB中
|__遍歷mon->get_quorum(),創(chuàng)建MMonPaxos消息且設(shè)置消息類型是MMonPaxos::OP_BEGIN
|__設(shè)置消息的pn=accepted_pn/last_committed=last_committed/value[last_committed+1]=new_value
|__發(fā)送MMonPaxos消息到peon
Paxos::handle_accept()
|__對(duì)于peon.accepted_pn != leader.accepted_pn,則直接拒絕
|__將peon插入到accepted數(shù)組中
|__若所有peon都返回OP_ACCEPT消息,則調(diào)用Paxos::commit_start()
Paxos::commit_start()
|__寫last_committed=last_committed+1到MonitorDB中
|__將uncommited_value寫入到MonitorDB中
|__寫MonitorDB成功后回調(diào)Paxos::commit_finish()函數(shù)
Paxos::commit_finish()
|__遍歷mon->get_quorum(),創(chuàng)建MMonPaxos消息且消息類型是MMonPaxos::OP_COMMIT
|__設(shè)置消息的value[last_committed]=new_value/pn=accepted_pn/last_committed=last_committed
|__將消息發(fā)送給peon
|__設(shè)置當(dāng)前狀態(tài)為STATE_REFRESH
peon
Paxos::handle_collect()
|__state = STATE_RECOVERING 設(shè)置當(dāng)前狀態(tài)為RECOVERING
|__對(duì)于leader的first_committed > peon的last_committed+1,則調(diào)用mon->bootstrap()
|__創(chuàng)建MMonPaxos消息且設(shè)置消息類型為MMonPaxos::OP_LAST
|__設(shè)置消息的last_committed/first_committed
|__若leader.accepted_pn > peon.accepted_pn,則設(shè)置peon.accepted_pn=leader.accepted_pn,同時(shí)設(shè)置peon.accepted_pn_from=leader.pn_from
|__將peon.accepted_pn寫入到MonitorDB中
|__設(shè)置MMonPaxos消息的pn/pn_from=accepted_pn/accepted_pn_from
|__若leader.last_committed < peon.last_committed,則說(shuō)明peon存在uncommitted value,于是從MonitorDB讀取出pending_pn/pending_value且設(shè)置到MMonPaxos消息中的uncommitted_pn/value[pending_v]中
|__發(fā)送MMonPaxos消息給leader
Paxos::handle_begin()
|__對(duì)于leader.pn < peon.accepted_pn,則直接拒絕
|__state = STATE_UPDATING
|__保存leader.uncommitted_value到MonitorDB
|__保存pending_v=last_committed+1/pending_pn=accepted_pn到MonitorDB
|__創(chuàng)建MMonPaxos消息且設(shè)置消息類型為MMonPaxos::OP_ACCEPT
|__設(shè)置消息pn=accepted_pn/last_committed=last_committed
|__將MMonPaxos消息發(fā)送給leader
Paxos::handle_commit()
|__Paxos::store_state() 將leader committed的value寫入到MonitorDB中
leader和peon之間的處理流程對(duì)應(yīng)關(guān)系如下:
leader peon
collect() handle_collect()
handle_last()
begin() handle_begin()
handle_accept()
commit_start()
commit_finish() handle_commit()
以上是“Ceph Monitor Paxos算法怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。