Summary of the invention
The technical problem to be solved in the present invention is to provide electoral machinery and the node of a kind of host node, it is possible to
In the group system that number of nodes dynamically changes, it is achieved the election of host node.
For solving above-mentioned technical problem, the electoral machinery of a kind of host node of the present invention, including:
Motion is initiated in the request of the node in addition to self in cluster of each node in cluster, it is judged that allow self
Whether the quantity of the node initiating motion reaches the minimum required value allowing to initiate motion, if reached, then
The node broadcasts motion in addition to self in cluster, and judge whether the quantity of the node accepting motion reaches
The received minimum required value of motion, if reached, it is determined that the node of motion is host node, to cluster
In the received motion of node broadcasts in addition to self.
Further, it is judged that allow whether the quantity of the node self initiating motion reaches to allow to initiate motion
Minimum required value, including:
After motion is initiated in the request of the node in addition to self in cluster, receive response message, according to response
The motion response message carried in message judges whether the node sending response message allows to initiate motion, as
Fruit allows, then to allowing the quantity initiating the node of motion to add up, and according to total nodes of cluster
Amount judges whether the quantity allowing to initiate the node of motion reaches the minimum required value allowing to initiate motion.
Further, it is judged that whether the quantity of the node accepting motion reaches the received minimum requirement of motion
Value, including:
After the node broadcasts motion in addition to self in cluster, receive response message, according to response message
In whether carry the information of acceptance judge send response message node whether accept motion, if accept, then
The quantity of the node accepting motion is added up, and judges to accept motion according to total number of nodes of cluster
The quantity of node whether reach the received minimum required value of motion.
Further, the described minimum required value allowing to initiate motion and the received minimum required value of motion
Be total number of nodes add 1 1/2nd the value that rounds up.
Further, total number of nodes of described cluster is preserved by each node in cluster, each in cluster
Joining and departing from of monitoring nodes cluster interior joint, fashionable there being node to add, add in total number of nodes
The quantity of the node increased, when there being node to leave, deducts the number of the node left on total number of nodes
Amount.
Further, the electoral machinery of a kind of host node, including:
Each node in cluster, after the message of motion is initiated in the request of receiving, disappears according to described in receiving
The most accept motion before breath, returned response message to the node sending described message, indicated whether to allow
The node sending described message initiates motion, and, after receiving motion, it may be judged whether allow to send out
The node sending motion initiates motion, if it is, return response message, instruction to the node sending motion
Accept motion.
Further, also include:
Each node in cluster, after the message of motion is initiated in the request of receiving, also judges that described request is initiated
Whether request mark (request ID) of the message of motion is more than the maximum request ID having been received by, as
Fruit is then to perform described basis and the most accepted motion before receiving described message, disappears described in sending
The node of breath returns response message, and the request ID recording the message that motion is initiated in current request is
The maximum request ID received.
Further, also include:
Return response message to the node sending motion, after instruction accepts motion, wait motion to be sent
The received motion of node broadcasts, if do not receive the node broadcasts sending motion within the waiting time
Received motion, then labelling does not currently accept motion, it is allowed to request motion node initiate motion.
Further, a kind of node, including: motion is initiated unit, motion unit and host node and is determined list
Unit, wherein:
Unit is initiated in described motion, initiates motion for the request of the node in addition to self in cluster, it is judged that
Whether the quantity allowing the node self initiating motion reaches the minimum required value allowing to initiate motion, if
Reach, then notify described motion unit;
Described motion unit, for the node broadcasts motion in addition to self in cluster, and judges that acceptance carries
Whether the quantity of the node of case reaches the received minimum required value of motion, if reached, then notice is described
Host node determines unit;
Described host node determines unit, is host node for determining the node of motion, except self in cluster
The received motion of outer node broadcasts.
Further, a kind of node, including: initiate judging unit and motion judging unit, wherein:
Described initiation judging unit, after the message initiating motion in the request of receiving, according to receiving
Before described message, the most accept motion, return response message, instruction to the node sending described message
Permission sends the node of described message and initiates motion;
Described motion judging unit, for after receiving motion, it may be judged whether has allowed to send motion
Node initiates motion, if it is, return response message to the node sending motion, instruction accepts motion.
In sum, present invention dynamic negotiation from the node of group system elects host node, reaches
The purpose of host node is determined in the case of number of nodes elastic telescopic in cluster.
Detailed description of the invention
This paper presents a kind of Leader electoral machinery that node elastic can be supported flexible, be used for realizing joint
The host node election of the point dynamically group system of change, dynamically obtains the information of node in the method, according to
Number of nodes actual in group system, adjusts Leader election process, reaches flexible at node elastic
In the case of determine the purpose of Leader.
The electoral machinery of the host node of present embodiment comprises two message exchange passages, and election information exchanges
Passage and information about firms interchange channel, concrete channel selecting mode can select according to reality application
(such as heartbeat or arbitration disk).
In present embodiment, each node has Three role concurrently, i.e. Proposer (motion side), Acceptor
(reciever) and Learner (study side), Proposer sends prepare request (preparation request)
(accurate with propose request (motion request) to Acceptor, Acceptor feedback prepare response
Standby response) and propose response (motion response) to Proposer.Once Proposer obtains and rents
About note that all of after (Lease, has the lock of time limit, it is thus achieved that the node of lease is host node)
Learner.These message are transmitted by election information interchange channel, and election information interchange channel can be different
Step, unstable.
Concrete election information exchange flow process is as it is shown in figure 1, oneself become Leader with the election of certain node and be
Example, time a length of T, the electoral machinery of the host node of present embodiment, including:
Step 101: in cluster, the Proposer of each node generates Prepare Request, including encapsulation
The request ID (request ID) of Prepare Request, the type arranging message is Prepare Request,
Node in cluster is broadcasted, and motion is initiated in request;
Request ID is monotonic increase.
The false code generating and broadcasting Prepare Request is as follows:
After step 102:Acceptor receives Prepare Request, it is judged that Prepare Request's
Whether request ID is more than the maximum request ID having been received by, if it is, record current Prepare
The request ID of Request is the maximum request ID having been received by, and generates PrepareResponse,
In Prepare Response, carry motion response message, be sent to Proposer;
When Acceptor allows Proposer to initiate motion, motion response message comprises instruction Acceptor
Allowing the information of motion, such as motion response message is empty (null);Other joints have been accepted at Acceptor
The motion of point, when not allowing Proposer to initiate motion, motion response message comprises Acceptor and accepts
Motion (ID of accepted node).
The false code of step 102 is as follows:
After step 103:Proposer receives Prepare Response, it is judged that Prepare Response
The most legal, if legal, then judge whether Acceptor allows Proposer according to motion response message
Initiate motion, if it is allowed, then judge the number allowing to initiate the Acceptor of motion according to total number of nodes
Whether amount reaches the minimum required value allowing to initiate motion, if reached, registers an intervalometer, generates
Propose Request carries the ID of the node of motion, and the node broadcasts motion in cluster carries out formal Shen
Please;
In Propose Request, also carry the timing of intervalometer, Proposer is waited Propose
The time announcement Acceptor of Response.
Proposer judges that Prepare Response is the most legal and includes: judge Prepare Response's
The request ID of response ID and Prepare Request is the most identical, if identical, then judges
Prepare Response is legal;If it is not the same, then judge that Prepare Response is illegal.
According to motion response message, Proposer judges whether Acceptor allows Proposer to initiate motion bag
Include: judge whether motion response message is null, if null, then judge that Acceptor allows Proposer
Initiate motion;Otherwise, it is determined that Acceptor does not allow Proposer to initiate motion.
When Acceptor allows Proposer to initiate motion, Proposer is also to allowing to initiate motion
The quantity of Acceptor adds up.
According to total number of nodes, Proposer judges whether the quantity allowing to initiate the Acceptor of motion reaches
Allow to initiate the minimum required value of motion, including: judge that the quantity allowing to initiate the Acceptor of motion is
No reach total number of nodes adds 1 1/2nd the value that rounds up.
Proposer is not in the case of intervalometer arrival timing receives Propose Response yet, really
Determine motion failure, mark host node and do not determine.
The false code of step 103 is as follows:
After step 104:Acceptor receives Propose Request, it may be judged whether allowed Proposer
Initiate motion, if it is, generate Propose Response, carry the information of acceptance, by Propose Response
It is sent to Proposer;
Acceptor judges whether to allow Proposer to initiate application, including: judge Propose Request
Request ID whether less than the maximum request ID received, if it is, judge not allow
Proposer initiates application;If it is not, then judge to have allowed Proposer to initiate application.
Acceptor registers an intervalometer, record according further to the timing carried in Propose Request
Wait the time of lease broadcast, in the case of not receiving lease broadcast in intervalometer arrival,
Labelling does not currently accept motion, it is allowed to the Proposer of request motion initiates motion.
The false code of step 104 is as follows:
After step 105:Proposer receives Propose Response message, according to Propose
Whether Response carries the information of acceptance, it is judged that whether the quantity of the Acceptor accepting motion reaches motion
Received minimum required value, if reached, illustrates that present node becomes Leader, broadcast lease broadcast
Message gives all of Learner, broadcasts received motion.
Proposer, after receiving Propose Response, also judges the response of Propose Response
The request ID of ID with Prepare Request is the most identical, if identical, then to accepting motion
The quantity of Acceptor adds up, and judges whether the quantity of the Acceptor accepting motion minimizes
Required value.
Proposer judges according to total number of nodes whether the quantity of the Acceptor accepting motion minimizes
Required value, including: judge whether the quantity of the Acceptor accepting motion reaches what total number of nodes added 1
The value that rounds up of 1/2nd.
Proposer, when the quantity judging to accept the Acceptor of motion minimizes required value, determines
Motion success, marks host node and has determined that.
The false code of step 105 is as follows:
Judge whether the quantity of the Acceptor accepting motion minimizes the puppet of required value in step 105
Code is as follows:
As a example by MajorityQuorum, the function accepting election results is as follows:
QuorumAccept(numAccepted){
Return (numAccepted >=ceil ((double) (numNodes+1)/2));
}
Judge whether the quantity allowing to initiate the Acceptor of application minimizes required value in step 103
False code similar with above-mentioned false code, differ only in variable and be slightly different.
The addition of the main monitor node in information about firms interchange channel or leave in present embodiment, relevant
Message includes MemberJoin and MemberLeave between node, and the node in cluster all preserves cluster
Total number of nodes, plus the number of node increased in total number of nodes after receiving MemberJoin
Amount;In total number of nodes, the quantity of the node left is deducted after receiving MemberLeave.
False code is as follows:
As in figure 2 it is shown, present embodiment additionally provides a kind of node, including: motion is initiated unit, is carried
Case unit and host node determine unit, wherein:
Unit is initiated in motion, initiates motion for the request of the node in addition to self in cluster, it is judged that allow
Whether the quantity of the node that self initiates motion reaches the minimum required value allowing to initiate motion, if reached,
Then notice motion unit;
Motion unit, for the node broadcasts motion in addition to self in cluster, and judges to accept motion
Whether the quantity of node reaches the received minimum required value of motion, if reached, then notice host node is true
Cell;
Host node determines unit, is host node for determining the node of motion, in cluster in addition to self
The received motion of node broadcasts.
Motion initiate unit, specifically for the node except self in addition in cluster request initiation motion after,
Receive response message, judge to send the joint of response message according to the motion response message carried in response message
Whether point allows to initiate motion, if it is allowed, then to allowing the quantity initiating the node of motion to add up,
And judge whether the quantity allowing to initiate the node of motion reaches to allow to initiate according to total number of nodes of cluster
The minimum required value of motion.
Motion unit, specifically for after the node broadcasts motion in addition to self in cluster, receives response
According to whether carrying the information of acceptance in response message, message, judges whether the node sending response message accepts
Motion, if accepted, then adds up the quantity of the node accepting motion, and according to total joint of cluster
Point quantity judges whether the quantity of the node accepting motion reaches the received minimum required value of motion.
The minimum required value of permission initiation motion and the received minimum required value of motion are total nodes of cluster
Quantity add 1 1/2nd the value that rounds up.
Total number of nodes of cluster is initiated unit by motion and motion unit preserves, each node prison in cluster
Joining and departing from of control cluster interior joint, fashionable there being node to add, plus increase in total number of nodes
The quantity of node, when there being node to leave, deducts the quantity of the node left on total number of nodes.
As it is shown on figure 3, the another kind of node of present embodiment, including: initiate judging unit and motion is sentenced
Disconnected unit, wherein:
Initiate judging unit, after the message initiating motion in the request of receiving, according to disappearing receiving
The most accept motion before breath, returned response message to the node sending message, indicated whether to allow to send
The node of message initiates motion;
Motion judging unit, for after receiving motion, it may be judged whether has allowed to send the node of motion
Initiating motion, if it is, return response message to the node sending motion, instruction accepts motion.
Initiate judging unit, be additionally operable to after the message of motion is initiated in the request of receiving, it is judged that request is initiated
Whether the request ID of the message of motion is more than the maximum request ID having been received by, if it is,
Perform according to the most having accepted motion before receiving message, return response message to the node sending message,
And the request ID recording the message that motion is initiated in current request is the maximum request having been received by
ID。
Motion judging unit, is additionally operable to returning response message to the node sending motion, and instruction acceptance carries
After case, wait the received motion of the node broadcasts of motion to be sent, if do not received within the waiting time
To the received motion of the node broadcasts sending motion, then labelling does not currently accept motion, it is allowed to request
The node of motion initiates motion.
Obviously, those skilled in the art should be understood that each module of the above-mentioned present invention or each step can
To realize with general calculating device, they can concentrate on single calculating device, or distribution
On the network that multiple calculating devices are formed, alternatively, they can be with calculating the executable journey of device
Sequence code realizes, and performs such that it is able to be stored in storing in device by calculating device, or
They are fabricated to respectively each integrated circuit modules, or the multiple modules in them or step are made
Single integrated circuit module is become to realize.So, the present invention is not restricted to any specific hardware and software
In conjunction with.
More than should be only the preferred embodiments of the present invention, be not limited to the present invention, for ability
For the technical staff in territory, the present invention can have various modifications and variations.All spirit in the present invention and former
Within then, any modification, equivalent substitution and improvement etc. made, should be included in the protection model of the present invention
Within enclosing.