Background technology
The fast development of network technology has promoted development and the extensive use of group system.A cluster is comprised of whole interconnected servers, and these servers are used as a unified computational resource, externally show as single system, and are managed with the pattern of triangular web.Along with the progressively maturation of cluster topology, cluster has become a hot technology in fields such as finance, telecommunications and government network at present, and it can guarantee high availability, expandability and the anti-calamity of system.
For a desirable cluster, the user need not to pay close attention to the composition node of group system, and a cluster is exactly a system, rather than some independently computing nodes, and cluster administrator can increase or delete the node of group system as required.Group system has following advantage: high scalability, high availability, high-performance and high performance-price ratio.According to the different characteristic of group system, group system can be divided three classes: high availability cluster, load balancing cluster and HPCC.
high availability cluster is again the HA cluster, the a kind of of cluster, be based on as the terminal use provides the service of continuation and produce, be used for externally providing service highly reliably, in this class group system, all nodes adopt Master (master)/Slave (from) or Multi-Active (many activation) mode same service externally is provided, consider conforming problem, the Multi-Active mode deals with very complicated, often cause the reduction for the treatment of effeciency, so more employing Master/Slave mode, accepted request by Master and distribute unitedly, the main distinction of Master/Slave and Multi-Active is to have a special joint, functional role is different from other nodes.The selection of Master is dynamic often, avoids the generation of Single Point of Faliure (SPOF, Single Point of Failure).The selection of Master is a typical Leader (host node) election process, and the application in high availability cluster is very general.
A qualified Leader electoral machinery need to solve following problem: avoid occurring a plurality of Leader (>1); The division of processing network; Avoid the collapse of election process node; Tolerance slow network etc.
Traditional Leader electoral machinery comprises following several at present:
(1) for each node in group system configures respectively numbering, select the maximum or minimum node of numbering as host node;
(2) node in group system generates numbering at random, selects the maximum node of numbering as host node;
(3) node in group system all uses identical major key to write database, and the node of successful write into Databasce is as host node.
Above-mentioned traditional Leader electoral machinery can realize the Master election of the group system of stationary nodes number, but can't satisfy the requirement of cluster dynamic, during number of nodes dynamic change in group system, can't realize the selection of host node.
Summary of the invention
The technical problem to be solved in the present invention is to provide a kind of electoral machinery and node of host node, can in the group system of number of nodes dynamic change, realize the election of host node.
For solving the problems of the technologies described above, the electoral machinery of a kind of host node of the present invention comprises:
Motion is initiated in the node request except self in cluster of each node in cluster, whether the quantity that judgement allows self to initiate the node of motion reaches the minimum required value that allows to initiate motion, if reach, the node broadcasts motion except self in cluster, and whether the quantity that judges the node of accepting motion reaches the received minimum required value of motion, if reach, determine that the node of motion is host node, the received motion of the node broadcasts in cluster except self.
Further, whether the quantity that judgement allows self to initiate the node of motion reaches the minimum required value that allows to initiate motion, comprising:
After motion is initiated in the node request except self in cluster, receive response message, whether the node that sends response message according to the motion response message judgement of carrying in response message allows to initiate motion, if allow, the quantity of the node of allow initiating motion add up, and whether reach according to the quantity that total number of nodes judgement of cluster allows to initiate the node of the motion the minimum required value that allows the initiation motion.
Further, whether the quantity that the node of motion is accepted in judgement reaches the received minimum required value of motion, comprising:
After the node broadcasts motion except self in cluster, receive response message, whether accept motion according to the node that whether carries the judgement transmission response message of receiving information in response message, if accept, the quantity of the node of accepting motion added up, and whether the quantity of the accepting the node of motion according to total number of nodes judgement of cluster reaches the received minimum required value of motion.
Further, to initiate the minimum required value of motion and the received minimum required value of motion be that total number of nodes adds 1 1/2nd the value of rounding up for described permission.
Further, total number of nodes of described cluster is preserved by each node in cluster, in each monitoring nodes cluster in cluster, node adds and leaves, to have node to add fashionable, add the quantity of the node of increase in total number of nodes, when having node to leave, deduct the quantity of the node that leaves on total number of nodes.
Further, a kind of electoral machinery of host node comprises:
After each node in cluster is initiated the message of motion in the request of receiving, according to whether accepted motion before receiving described message, return to response message to the node that sends described message, indicate whether to allow to send the node initiation motion of described message, and, after receiving motion, judge whether to allow to send the node initiation motion of motion, if so, return to response message to the node that sends motion, motion is accepted in indication.
Further, also comprise:
After each node in cluster is initiated the message of motion in the request of receiving, judge that also described request initiates the request mark (request ID) of message of motion whether greater than the request ID of the maximum that has received, if, carry out described basis and whether accepted motion before receiving described message, return to response message to the node that sends described message, and the request ID that records the message that current request initiates motion is the request ID of the maximum that received.
Further, also comprise:
Returning to response message to the node that sends motion, after motion is accepted in indication, received motion etc. the node broadcasts of motion to be sent, if do not receive the received motion of the node broadcasts that sends motion within the stand-by period, mark is current does not accept motion, allows the node of request motion to initiate motion.
Further, a kind of node comprises: unit, motion unit and host node determining unit are initiated in motion, wherein:
The unit is initiated in described motion, is used for to cluster the node request except self and initiates motion, and whether the quantity that judgement allows self to initiate the node of motion reaches the minimum required value that allows the initiation motion, if reach, notifies described motion unit;
Described motion unit is used for the node broadcasts motion except self to cluster, and judges that whether the quantity of the node of accepting motion reaches the received minimum required value of motion, if reach, notifies described host node determining unit;
Described host node determining unit is used for determining that the node of motion is host node, the received motion of the node broadcasts in cluster except self.
Further, a kind of node comprises: initiate judging unit and motion judging unit, wherein:
Described initiation judging unit, be used for after the message of motion is initiated in the request of receiving, according to whether accepted motion before receiving described message, return to response message to the node that sends described message, indicate whether to allow to send the node initiation motion of described message;
Described motion judging unit is used for after receiving motion, judges whether to allow to send the node initiation motion of motion, if so, returns to response message to the node that sends motion, and motion is accepted in indication.
In sum, the present invention's dynamic negotiation from the node of group system elects host node, reaches in the situation that the number of nodes elastic telescopic in cluster is determined the purpose of host node.
Embodiment
This paper has proposed a kind of Leader electoral machinery that can the support node elastic telescopic, host node election for the group system that realizes the node dynamic change, the information of Dynamic Acquisition node in the method, according to number of nodes actual in group system, adjust the Leader election process, reach in the situation that the purpose of the flexible Leader of determining of node elastic.
The electoral machinery of the host node of present embodiment comprises two message passages, election information interchange channel and information about firms interchange channel, and concrete channel selecting mode can be selected according to practical application (for example heartbeat or arbitration dish).
In present embodiment, each node has Three role concurrently, be Proposer (motion side), Acceptor (reciever) and Learner (study side), Proposer sends prepare request (preparation request) and propose request (motion request) arrives Acceptor, and Acceptor feedback prepare response (preparation is replied) and propose response (motion is replied) give Proposer.In case Proposer obtains lease (node that obtains lease is host node for Lease, the lock in free time limit) and just notifies afterwards all Learner.These message are by the transmission of election information interchange channel, and the election information interchange channel can be asynchronous, unsettled.
Concrete election information exchange flow process oneself becomes Leader as example take certain node election as shown in Figure 1, and duration is T, and the electoral machinery of the host node of present embodiment comprises:
Step 101: in cluster, the Proposer of each node generates Prepare Request, the request ID (request ID) that comprises encapsulation Prepare Request, the type that message is set is Prepare Request, and the node in cluster is broadcasted, and motion is initiated in request;
Request ID is monotonic increase.
The false code that generates and broadcast Prepare Request is as follows:
After step 102:Acceptor receives Prepare Request, whether the request ID that judges Prepare Request is greater than the request ID of the maximum that has received, if, the request ID that records current Prepare Request is the request ID of the maximum that received, generate PrepareResponse, carry the motion response message in Prepare Response, send to Proposer;
When Acceptor allowed Proposer to initiate motion, the motion response message comprised the information that indication Acceptor allows motion, and for example motion response message is empty (null); Accepted the motion of other nodes at Acceptor, when not allowing Proposer to initiate motion, the motion response message comprises the accepted motion of Acceptor (ID of accepted node).
The false code of step 102 is as follows:
After step 103:Proposer receives Prepare Response, judge whether Prepare Response is legal, if legal, judge according to the motion response message whether Acceptor allows Proposer to initiate motion, if allow, allow the quantity of the Acceptor of initiation motion whether to reach the minimum required value that allows to initiate motion according to total number of nodes judgement, if reach, register a timer, generate the ID that Propose Request carries the node of motion, formal application is carried out in the node broadcasts motion in cluster;
Also carry the timing of timer in Propose Request, Proposer is waited for the time announcement Acceptor of Propose Response.
Proposer judges Prepare Response legal comprising whether: whether the response ID that judges Prepare Response is identical with the request ID of Prepare Request, if identical, judges that Prepare Response is legal; If not identical, judge that Prepare Response is illegal.
Proposer judges according to the motion response message whether Acceptor allows Proposer to initiate motion and comprise: judge whether the motion response message is null, if be null, judge that Acceptor allows Proposer to initiate motion; Otherwise, judge that Acceptor does not allow Proposer to initiate motion.
When Acceptor allowed Proposer to initiate motion, Proposer also added up the quantity of the Acceptor that allows to initiate motion.
Whether Proposer reaches according to the quantity that total number of nodes judgement allows to initiate the Acceptor of motion the minimum required value that allows to initiate motion, comprising: whether the quantity that judgement allows to initiate the Acceptor of motion reaches total number of nodes adds 1 1/2nd the value of rounding up.
Proposer does not receive Propose Response yet in the situation that timer arrives timing, determines the motion failure, marks host node and does not determine.
The false code of step 103 is as follows:
After step 104:Acceptor receives Propose Request, judge whether to allow Proposer to initiate motion, if so, generate Propose Response, carry and receive information, Propose Response is sent to Proposer;
Acceptor judges whether to allow Proposer to initiate application, comprising: judge that the request ID of Propose Request whether less than the request ID of the maximum that has received, if so, judges not allow Proposer to initiate to apply for; If not, judgement has allowed Proposer to initiate application.
Acceptor is also according to timing registration one timer that carries in Propose Request, the time of lease broadcast waited in record, do not receive the lease broadcast in the situation that timer arrives, mark is current does not accept motion, allows the Proposer of request motion to initiate motion.
The false code of step 104 is as follows:
After step 105:Proposer receives Propose Response message, whether carry according to Propose Response and receive information, whether the quantity that the Acceptor of motion is accepted in judgement reaches the received minimum required value of motion, if reach, illustrate that present node becomes Leader, broadcasting lease broadcast is given all Learner, broadcasts received motion.
Proposer is after receiving Propose Response, whether the response ID that also judges Propose Response is identical with the request ID of Prepare Request, if identical, the quantity of the Acceptor that accepts motion is added up, and whether the quantity that the Acceptor of motion is accepted in judgement reaches minimum required value.
Whether the quantity that Proposer accepts the Acceptor of motion according to total number of nodes judgement reaches minimum required value, comprising: whether the quantity that the Acceptor of motion is accepted in judgement reaches total number of nodes adds 1 1/2nd the value of rounding up.
When Proposer reaches minimum required value in the quantity of judging the Acceptor that accepts motion, determine the motion success, mark host node definite.
The false code of step 105 is as follows:
The false code whether quantity of Acceptor that motion is accepted in judgement in step 105 reaches minimum required value is as follows:
Take MajorityQuorum as example, the function of accepting election results is as follows:
QuorumAccept(numAccepted){
return(numAccepted>=ceil((double)(numNodes+1)/2));
}
False code and above-mentioned false code that whether the quantity of the Acceptor that judgement permission initiation is applied in step 103 reaches minimum required value are similar, and difference only is that variable is slightly different.
In present embodiment, the main monitor node in information about firms interchange channel adds or leaves, relevant message comprises MemberJoin and the MemberLeave between node, node in cluster is all preserved total number of nodes of cluster, adds the quantity of the node of increase after receiving MemberJoin in total number of nodes; Deduct the quantity of the node that leaves in total number of nodes after receiving MemberLeave.
False code is as follows:
As shown in Figure 2, present embodiment also provides a kind of node, comprising: unit, motion unit and host node determining unit are initiated in motion, wherein:
The unit is initiated in motion, is used for to cluster the node request except self and initiates motion, and whether the quantity that judgement allows self to initiate the node of motion reaches the minimum required value that allows the initiation motion, if reach, notifies the motion unit;
The motion unit is used for the node broadcasts motion except self to cluster, and judges that whether the quantity of the node of accepting motion reaches the received minimum required value of motion, if reach, notifies the host node determining unit;
The host node determining unit is used for determining that the node of motion is host node, the received motion of the node broadcasts in cluster except self.
The unit is initiated in motion, concrete being used for after motion is initiated in the node request except self to cluster, receive response message, whether the node that sends response message according to the motion response message judgement of carrying in response message allows to initiate motion, if allow, the quantity of the node of allow initiating motion add up, and whether reach according to the quantity that total number of nodes judgement of cluster allows to initiate the node of the motion the minimum required value that allows the initiation motion.
The motion unit, concrete being used for after the node broadcasts motion except self to cluster, receive response message, whether accept motion according to the node that whether carries the judgement transmission response message of receiving information in response message, if accept, the quantity of the node of accepting motion added up, and whether the quantity of the accepting the node of motion according to total number of nodes judgement of cluster reaches the received minimum required value of motion.
Allow to initiate the minimum required value of motion and total number of nodes that the received minimum required value of motion is cluster and add 1 1/2nd the value of rounding up.
Total number of nodes of cluster is initiated unit and motion unit preservation by motion, in each monitoring nodes cluster in cluster, node adds and leaves, to have node to add fashionable, add the quantity of the node of increase in total number of nodes, when having node to leave, deduct the quantity of the node that leaves on total number of nodes.
As shown in Figure 3, the another kind of node of present embodiment comprises: initiate judging unit and motion judging unit, wherein:
The initiation judging unit is used for after the message of motion is initiated in the request of receiving, and according to whether accepted motion before receiving message, returns to response message to the node that sends message, indicates whether to allow to send the node initiation motion of message;
The motion judging unit is used for after receiving motion, judges whether to allow to send the node initiation motion of motion, if so, returns to response message to the node that sends motion, and motion is accepted in indication.
Initiate judging unit, also be used for after the message of motion is initiated in the request of receiving, judgement request is initiated the request ID of message of motion whether greater than the request ID of the maximum that has received, if, carry out according to whether accepted motion before receiving message, return to response message to the node that sends message, and the request ID that records the message that current request initiates motion is the request ID of the maximum that received.
The motion judging unit, also be used for returning to response message to the node that sends motion, after motion is accepted in indication, received motion etc. the node broadcasts of motion to be sent, if do not receive the received motion of the node broadcasts that sends motion within the stand-by period, mark is current does not accept motion, allows the node of request motion to initiate motion.
obviously, those skilled in the art should be understood that, above-mentioned each module of the present invention or each step can realize with general calculation element, they can concentrate on single calculation element, perhaps be distributed on the network that a plurality of calculation elements form, alternatively, they can be realized with the executable program code of calculation element, carried out by calculation element thereby they can be stored in storage device, perhaps they are made into respectively each integrated circuit modules, perhaps a plurality of modules in them or step being made into the single integrated circuit module realizes.Like this, the present invention is not restricted to any specific hardware and software combination.
Above this be only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.