How to use Ceph Monitor Paxos algorithm
Editor to share with you how to use the Ceph Monitor Paxos algorithm, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Some related variables
Last_pn: the latest proposal number
Accepted_pn: the latest accepted proposal number
Accepted_pn_from:peon accepts the last_committed of the latest proposal number's leader (that is, only accepts pn values greater than accepted_pn_from)
First_committed:
Both last_committed:leader and peon exist, accept the latest value version number
Peer_first_committed: record the version number of the first commit in the cluster member
Peer_last_committed: record the version number of the latest commit in the cluster member
Some function parsing
Paxos::init ()
Read the value of last_pn/accepted_pn/last_committed/first_committed from MonitorDB
Leader
Paxos::collect ()
| | _ _ state = STATE_RECOVERING sets the current status to RECOVERING |
| | _ _ initialize the related variable uncommitted_v/uncommitted_pn/uncommitted_value/peer_first_committed/peer_last_committed |
| | _ _ check whether uncommitted value exists. Check whether the value of last_committed+1 exists in MonitorDB. If so, initialize uncommitted_pn/uncommitted_v/uncommitted_value. |
| | _ _ Paxos::get_new_proposal_number () generates a monotonously increasing and globally unique last_ PN value |
| | _ _ initialize accepted_pn=last_pn/accepted_pn_from=last_committed |
| | _ _ traverse mon- > get_quorum (), create a MMonPaxos message and set the last_committed/first_committed/pn (accepted_pn) of the message |
| | _ _ send MMonPaxos messages to all monitor nodes in mon- > get_quorum () |
Paxos::handle_last ()
| | _ _ update peer_first_committed/peer_last_committed array |
| | _ _ for peon.first_committed > leader.last_committed+1, leader calls mon- > bootstrap () |
| | _ _ Paxos::store_state () saves the version_t > leader.last_committed & & version_t leader.accepted_pn of the value in the MMonPaxos message, then Paxos::collect () is called |
| | _ _ for peon.accetped_pn = = leader.accepted_pn, the proposal number of leader is recognized by peon, and the current status is set to STATE_UPDATING_PREVIOUS for all peon's proposal number of leader. |
| | _ _ Paxos::begin (). The calling parameter is uncommitted_value passed from peon. |
Paxos::begin ()
| | _ _ initialize accepted array |
| | _ _ in the case of last_committed==0, set first_committed=1 |
| | _ _ write the uncommitted_value of peon passed in the parameters to MonitorDB |
| | _ _ update pending_v = last_committed+1/pending_pn=aceepted_pn and write to MonitorDB |
| | _ _ traverse mon- > get_quorum (), create a MMonPaxos message and set the message type to MMonPaxos::OP_BEGIN |
| | _ _ set the pn=accepted_pn/last_committed=last_committed/ value of the message [last _ committed+1] = new_value |
| | _ _ send MMonPaxos message to peon |
Paxos::handle_accept ()
| | _ _ for peon.accepted_pn! = leader.accepted_pn, it is rejected directly |
| | _ _ insert peon into accepted array |
| | _ _ if all peon returns OP_ACCEPT messages, call Paxos::commit_start () |
Paxos::commit_start ()
| | _ _ write last_committed=last_committed+1 to MonitorDB |
| | _ _ write uncommited_value to MonitorDB |
| | _ _ callback Paxos::commit_finish () function after successful writing of MonitorDB |
Paxos::commit_finish ()
| | _ _ traverse mon- > get_quorum (), and create a MMonPaxos message with a message type of MMonPaxos::OP_COMMIT |
| | _ _ set the value of the message [last _ committed] = new_value/pn=accepted_pn/last_committed=last_committed |
| | _ _ send a message to peon |
| | _ _ sets the current status to STATE_REFRESH |
Peon
Paxos::handle_collect ()
| | _ _ state = STATE_RECOVERING sets the current status to RECOVERING |
| | _ _ for first_committed of leader > last_committed+1 of peon, call mon- > bootstrap () |
| | _ _ create a MMonPaxos message and set the message type to MMonPaxos::OP_LAST |
| | _ _ sets the last_committed/first_committed of message |
| | _ _ if leader.leaded _ pn > peon.accepted_pn, set peon.accepted_pn=leader.accepted_pn and peon.accepted_pn_from=leader.pn_from |
| | _ _ write peon.accepted_pn to MonitorDB |
| | _ _ sets the pn/pn_from=accepted_pn/accepted_pn_from of MMonPaxos messages |
| | _ _ if leader.last _ committed < peon.last_committed, uncommitted value exists in peon, so read pending_pn/pending_value from MonitorDB and set it to uncommitted_pn/ value in MMonPaxos message. |
| | _ _ send MMonPaxos message to leader |
Paxos::handle_begin ()
| | _ _ if leader.pn < peon.accepted_pn, reject it directly |
| | _ state = STATE_UPDATING |
| | _ _ Save leader.uncommitted_value to MonitorDB |
| | _ _ Save pending_v=last_committed+1/pending_pn=accepted_pn to MonitorDB |
| | _ _ create a MMonPaxos message and set the message type to MMonPaxos::OP_ACCEPT |
| | _ _ set message pn=accepted_pn/last_committed=last_committed |
| | _ _ send MMonPaxos message to leader |
Paxos::handle_commit ()
| | _ _ Paxos::store_state () writes the value of leader committed to MonitorDB |
The processing flow correspondence between leader and peon is as follows:
Leader peon
Collect () handle_collect ()
Handle_last ()
Begin () handle_begin ()
Handle_accept ()
Commit_start ()
Commit_finish () handle_commit ()
The above is all the contents of the article "how to use the Ceph Monitor Paxos algorithm". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!