A kind of cluster election method and systemTechnical field
The present invention relates to big data computing field, a kind of cluster election method more particularly, to big data computing andSystem.
Background technology
The each have their own cluster tupe of present big data computing, algorithm disunity.Company is from the system ground or even does not haveDo cluster, cause when after system crash cannot normal work, influence big data treatment normal execution.And it is existing many oldSystem does not all account for high-availability cluster processing scheme, or carries out High Availabitity treatment only with simple vrrp agreements.Work as voidControl node or network node in planization system is because when a variety of causes stops service, system is just uncontrollable to virtualize systemThe computer network functions of system, can only wait recovery to be serviced.And using the scheme of vrrp, typically only two machines perform heatStandby pattern, being susceptible to fissure causes ip to conflict, it is impossible to normal service.
The content of the invention
The present invention is to overcome at least one defect described in above-mentioned prior art(It is not enough), there is provided one kind makes the common not high canSystem realizes the cluster election method of High Availabitity function.
The present invention also provides a kind of cluster election system for making the available system of common not high realize High Availabitity function.
In order to solve the above technical problems, technical scheme is as follows:
A kind of cluster election method, including:
When cannot obtain the heartbeat of master server from server, candidate server is changed to from the state of server, and take to remainingBusiness device sends the ballot request that master server is elected in request as;
Voted more than the server of pre-set threshold numbers when candidate server is received, then election turns into master server and changes stateIt is master server;
When candidate server, when voting results are waited, other servers turn into master server, then candidate server change state isFrom server;
When without the election of any candidate server for master server, candidate server resends ballot request until there is a timeUntill election server turns into master server.
The present invention selects master server again when master server stops servicing by the way of vote by ballot, otherUsed as from server, the method changes the deployment scheme of original system to server under the premise of original system function is not influenceed, and makesVarious application clusters are constituted with distributed election agreement, the system for not possessing High Availabitity originally is possessed High Availabitity ability,The method is applicable very much for simple application system, it is not necessary in design phase worry about high availability scheme, concentrates industryIt is pragmatic existing.
In such scheme, after candidate server election turns into master server and changes state for master server, the new masterServer also sends master server heartbeat to other servers, and change state is from server after other servers receive heartbeat.New master server notifies other servers by sending heartbeat mode, and can be changed to state from clothes in time by other serversBusiness device, enables new master server to take over service in time, system is recovered normal working condition.
In such scheme, the pre-set threshold numbers are the half of Servers-all.
In such scheme, candidate server change state is the master server and from server sync state from after serverInformation.The synchronization of status information can not only enable a system to return to normal condition, but also can return to system to stopState before only servicing, it is ensured that the integrality of information.
A kind of cluster election system, including server, server include:
State change module, during for the heartbeat that master server cannot be obtained when server, change state is candidate server;
Ballot request module, for sending the ballot request that master server is elected in request as to remaining server;
Voting results receiver module, for the reception server voting results, throws when the server more than pre-set threshold numbers is receivedIt is master server that election turns into master server and notifies that state change module changes state during ticket;
Change state is master server when state change module is additionally operable to Server election as master server;
Master server notification module, for knowing that other servers turn into master server and notify state change module;
It is from server that state change module is additionally operable to change state after knowing that other servers turn into master server.
System of the invention is based on the mode of vote by ballot come again when master server stops servicing using modulesMaster server is selected, used as from server, the system changes original other servers under the premise of original system function is not influenceedThe deployment scheme of system, various application clusters are constituted using the distributed election agreement in ballot request module, are made originally notThe system for possessing High Availabitity possesses High Availabitity ability, and this system is applicable very much for simple application system, it is not necessary to settingMeter stage worry about high availability scheme, centralized traffic is realized.
In such scheme, ballot request module is additionally operable to an after state is changed to candidate server by state change moduleWhen not changing state again in fixing time, ballot request is sent to remaining server again.Request mechanism of voting again is set, canTo allow that system spontaneously re-emits ballot request until new master server is selected again, it is ensured that system existsThe service that new demand servicing device carrys out restarting systems can be selected after stopping service.
In such scheme, server also includes:
Heartbeat sending module, for after state change module change state is master server, main clothes being sent to other serversBusiness device heartbeat;
It is from server that state change module is additionally operable to change state after the heartbeat that new master server sends is received.
Setting heartbeat sending module is used to, to waiting the server of election results to give notice, enable other servers to tieThe process of beam ballot request, the state of remodifying is from server, to ensure the service of timely restarting systems.
In such scheme, the pre-set threshold numbers are the half of Servers-all.
In such scheme, server also includes:
State synchronized module, for being from after server or master server, with other services in state change module change stateDevice carries out status information simultaneously operating.The setting of state synchronized module can not only enable a system to return to normal condition, andAnd system can also be made to return to the state before stopping service, it is ensured that the integrality of information.
Compared with prior art, the beneficial effect of technical solution of the present invention is:
The present invention constitutes the high availability scheme of the cluster of big data computing using distributed election agreement, and it is not influenceing originalOn the premise of systemic-function, the deployment scheme of original system is somewhat changed, master server, remaining server are elected by agreementAs from server, when master server stops server, rinsed from server and select master server, new master server adapterService so that the common available system of not high realizes High Availabitity function, it is ensured that can be by spontaneous election after system crashCarry out the normal work of recovery system, it is ensured that the normal execution of big data treatment.It is especially suitable for simple application system, noNeeds excessively consider high availability scheme in the design phase, practical.
Brief description of the drawings
Fig. 1 is a kind of flow chart of cluster election method specific embodiment of the invention.
Fig. 2 is a kind of Organization Chart of cluster election system specific embodiment of the invention.
Specific embodiment
Accompanying drawing being for illustration only property explanation, it is impossible to be interpreted as the limitation to this patent;
In order to more preferably illustrate the present embodiment, accompanying drawing some parts have omission, zoom in or out, and do not represent the chi of actual productIt is very little;
To those skilled in the art, some known features and its explanation may be omitted and will be understood by accompanying drawing.
In the description of the invention, in the description of the invention, unless otherwise indicated, " multiple " is meant that two or twoMore than individual.
In the description of the invention, it is necessary to illustrate, unless otherwise clearly defined and limited, term " installation ", " companyConnect " should be interpreted broadly, for example, it may be being fixedly connected, or being detachably connected, or it is integrally connected;It can be machineTool is connected, or electrically connected;It can be joined directly together, or be indirectly connected with by intermediary, it may be said that twoThe connection of element internal.For the ordinary skill in the art, with concrete condition above-mentioned term can be understood in the present inventionConcrete meaning.
Technical scheme is described further with reference to the accompanying drawings and examples.
Embodiment 1
As shown in figure 1, being a kind of flow chart of cluster election method specific embodiment of the invention.Referring to Fig. 1, this specific embodimentA kind of specific steps of cluster election method include:
It is all to be changed to candidate server from the state of server when S1. cannot obtain the heartbeat of master server from server, and toRemaining server sends the ballot request that master server is elected in request as.
When usual system starts or master server goes offline can all cause that the heartbeat of master server cannot be obtained from server,Can now be given from server etc. by presetting regular hour threshold value or the number of times of master server heartbeat cannot be obtainedThe time of master server heartbeat is treated, when master server heartbeat cannot be obtained more than regular hour threshold value or more than certain number of times(Master server heartbeat cannot be obtained such as 3 times)When still cannot obtain the heartbeat of master server from server afterwards, from serverStarting state changes step, is candidate server by its own status modifier, and each to other servers in addition to itselfSend ballot request.Time threshold setting on the one hand can ensure wait heartbeat time, on the other hand again can ensure fromServer can start vote by ballot step to select master server again in time, to ensure system can be after collapse oneFix time interior timely recovery normal work.
S2. voted more than the server of pre-set threshold numbers when candidate server is received, then election turns into master server and changesState is master server;Default number of thresholds can preset, such as it is Servers-all to set default number of thresholdsThe half of quantity, because now former master server is in the state that goes offline, therefore, the Servers-all refers to removing what is gone offlineOther Servers-alls outside former master server.Ballot bag generally is sent from server, remaining candidate server receives ballot bagBe made whether afterwards agree to ballot, when total quantity exceed half server agree to then it is corresponding be elected as from server it is newMaster server.
When candidate server, when voting results are waited, other servers turn into master server, then candidate server change state isFrom server;
When without the election of any candidate server for master server, candidate server resends ballot request and re-executes stepRapid S2.
In step s 2, step is also performed after candidate server election turns into master server and changes state for master serverRapid S3:
S3. the new master server also sends master server heartbeat to other servers, and other servers change shape after receiving heartbeatState is from server.The setting purpose of this step is to notify that other servers have selected main clothes by sending heartbeat modeCan be changed to state from server in time by business device, other servers, new master server is taken over service in time, be madeSystem recovers normal working condition.
In step s3, candidate server change state is the master server and from server sync state from after serverInformation.The synchronization of status information is referred to after master server elects successfully, to each from server sync from application systemStatus information.The synchronization of status information can not only enable a system to return to normal condition, but also can recover systemTo the state stopped before service, it is ensured that the integrality of information.
Embodiment 2
The present invention also provides a kind of cluster election system to realize the high availability scheme of non-high-availability system.
As shown in Fig. 2 being a kind of Organization Chart of cluster election system of this specific embodiment.Referring to Fig. 2, this specific embodimentA kind of cluster election system specifically includes server, and server can determine master server by way of selected or electionWith from server, when master server stops server, it is possible to use system of the invention elects master server to rinseService is provided.Specifically, server includes:
State change module 110, during for the heartbeat that master server cannot be obtained when server, change state is candidate serviceDevice;The original state of server be from server state can all cause when system starts or master server goes offline from server withoutMethod obtains the heartbeat of master server, and after it cannot obtain master server heartbeat, state change module 110 can be by default certainTime threshold wait master server heartbeat, after more than regular hour threshold value server cannot still obtain master serverDuring heartbeat, state change module 110 can carry out state change, be candidate server by the status modifier of server.
Ballot request module 120, for sending the ballot request that master server is elected in request as to remaining server;
Voting results receiver module 130, for the reception server voting results, when receiving the server more than pre-set threshold numbersBy book server election is as master server and notifies that the change state of state change module 110 is master server during ballot;It is defaultNumber of thresholds can preset, such as set default number of thresholds as the half of Servers-all quantity.
Change state is master server when state change module 110 is additionally operable to Server election as master server;
Master server notification module 140, for knowing that other servers turn into master server and notify state change module 110;
It is from server that state change module 110 is additionally operable to change state after knowing that other servers turn into master server.
Can not succeed every time in view of vote by ballot, such as the server ballot that neither one server is received is superDuring more than half servers, then it is master server that neither one server can be caused successfully to elect.Therefore, ballot request module 120It is additionally operable to when state is not changed again in the certain hour after state is changed to candidate server by state change module 110, weightIt is new to send ballot request to remaining server.Change expression is not still within candidate server state to server state again, andIt is not changed to from server state or master server state, that is, represents and be elected as new main service still without a serverDevice.Request mechanism of voting again is set, can allow that system spontaneously re-emits ballot request until selecting againUntill new master server, it is ensured that system can select the service that new demand servicing device carrys out restarting systems after service is stopped.
In order to notify that other servers have elected new master server in time, heartbeat is also provided with serverSending module 150, for after the change state of state change module 110 is master server, main service being sent to other serversDevice heartbeat;
It is from server that state change module 110 is additionally operable to change state after the heartbeat that new master server sends is received.
Setting heartbeat sending module 150 is used to, to waiting the server of election results to give notice, enable other serversEnough processes for terminating ballot request, the state of remodifying is from server, to ensure the service of timely restarting systems.
In specific implementation process, in server also include state synchronized module 160, in state change module 110 moreIt is from after server or master server, status information simultaneously operating to be carried out with other servers to change state.State synchronized moduleSetting can not only be enabled a system to return to normal condition, but also system can be made to return to the state before stopping service,The integrality of guarantee information.
The present invention constitutes the high availability scheme of the cluster of big data computing using distributed election agreement, and it is not influenceingOn the premise of original system function, the deployment scheme of original system is somewhat changed, master server is elected by agreement, remaining clothesBusiness device, when master server stops server, is rinsed from server and selects master server, new master server as from serverAdapter service so that the common available system of not high realizes High Availabitity function, it is ensured that can be by spontaneity after system crashElection carrys out the normal work of recovery system, it is ensured that the normal execution of big data treatment.Especially fitted for simple application systemWith, it is not necessary to excessively consider high availability scheme in the design phase, it is practical.
The same or analogous part of same or analogous label correspondence;
Position relationship for the explanation of being for illustration only property described in accompanying drawing, it is impossible to be interpreted as the limitation to this patent;
Obviously, the above embodiment of the present invention is only intended to clearly illustrate example of the present invention, and is not to this hairThe restriction of bright implementation method.For those of ordinary skill in the field, can also do on the basis of the above descriptionGo out the change or variation of other multi-forms.There is no need and unable to be exhaustive to all of implementation method.It is all in the present inventionSpirit and principle within any modification, equivalent and the improvement made etc., should be included in the guarantor of the claims in the present inventionWithin the scope of shield.