CN107819556A - A kind of service state switching method and device - Google Patents
A kind of service state switching method and device Download PDFInfo
- Publication number
- CN107819556A CN107819556A CN201610818126.9A CN201610818126A CN107819556A CN 107819556 A CN107819556 A CN 107819556A CN 201610818126 A CN201610818126 A CN 201610818126A CN 107819556 A CN107819556 A CN 107819556A
- Authority
- CN
- China
- Prior art keywords
- service
- state
- moment
- mark
- preset duration
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/22—Arrangements for detecting or preventing errors in the information received using redundant apparatus to increase reliability
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/06—Management of faults, events, alarms or notifications
- H04L41/0654—Management of faults, events, alarms or notifications using network fault recovery
- H04L41/0663—Performing the actions predefined by failover planning, e.g. switching to standby network elements
Abstract
The embodiment of the invention discloses a kind of service state switching method and device, the equipment applied to destination service is configured with.This method includes:Read the first mark recorded in target database and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, judge the time difference at the first moment and current time whether more than the first preset duration;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If it is not the same, judge the time difference at the first moment and current time whether more than the second preset duration;If it is, the service state of switching destination service is master state, the first moment of renewal is current time, and renewal first is identified as the second mark.When switching the service state of service using this programme, it is not necessary to additionally dispose Zookeeper, reduce the resource that extra deployment Zookeeper is consumed.
Description
Technical field
The present invention relates to field of computer technology, more particularly to a kind of service state switching method and device.
Background technology
Service (server), for the angle of hardware, refer to the server being physically present;From the angle of software
Say, refer to the computer software for possessing server side functionality, service is generally connected with client (client), and client passes through
The service of access obtains corresponding service content, such as accesses database;When client obtains a certain service content, in order to anti-
Only to should the service of item service content break down or other no normal direction clients provide the phenomenon of service content, prior art
In, it will usually set at least two services to provide same service content, the state of these services can be divided into:Master state and standby
With state, the service in master state is referred to as main service (active server), and the service in stand-by state is referred to as standby
Service (standby server).
When client obtains service content, service content is provided for client in real time by main service, when main service can not
When continuing to provide service content, active service switching oneself state is master state with as new main service, and thus new
Main service continues to provide the user corresponding service content, and the switching of above-mentioned this stand-by state and master state is referred to as active and standby cut
Change.
In the prior art, (one distributed, open source code generally by ZooKeeper for the method for active-standby switch
Distributed application program coordination service) realize, such as HDFS (Hadoop Distributed File System, Hadoop
Distributed file system), YARN (Yet Another Resource Negotiator, another resource coordination person) service;It is existing
There is technology to be used as lock by creating znode nodes on ZooKeeper, getting the service of lock turns into main service, is not locked
Service as active service.Main service regularly updates znode nodes, continues holder lock, when main service break down with
When ZooKeeper is disconnected, znode nodes are no longer updated, then active service gets lock and the own services that automatically switch
State, turn into new main service.
The switching of the service state serviced in the prior art needs to rely on the ZooKeeper disposed in advance, otherwise can not be real
The switching of existing service state.Therefore, a kind of ZooKeeper cans that need not dispose are designed and realize cutting for the service state serviced
The method of changing is very necessary.
The content of the invention
The embodiment of the invention discloses a kind of service state switching method and device, with no deployment ZooKeeper's
In the case of, realize the switching of the service state of service.Technical scheme is as follows:
For the above-mentioned purpose, in a first aspect, the embodiments of the invention provide a kind of service state switching method, applied to
The equipment of destination service is equipped with, methods described includes:
The first mark recorded in target database and the first moment are read, wherein, described first is identified as in master
With the mark of the service of state, first moment is the present service period initial time of the service in master state;
It is identical to judge that first mark identifies whether with the second of the destination service;
If identical, the service state for judging the destination service is master state, and judges first moment with working as
Whether the time difference at preceding moment is more than the first preset duration;If it is, the service state for switching the destination service is standby shape
State;If it has not, renewal first moment is current time;
If it is not the same, the service state for judging the destination service is stand-by state, and judge first moment with
Whether the time difference at current time is more than the second preset duration;If it is, the service state for switching the destination service is primary
State, it is current time to update first moment, and renewal described first is identified as second mark, wherein, described second
Preset duration is not less than first preset duration.
Preferably, the service state switching method also includes:
According to the service state of local record, whether the service state for judging the destination service is master state;
If it is, judging whether the network connection of the destination service and the target database disconnects;
If off, the second moment and current time of local record are contrasted, if second moment and current time
Time difference exceedes first preset duration, and the service state for switching the destination service is stand-by state, wherein, described second
Moment is the present service period initial time of the service in master state;
If do not disconnected, the first mark recorded in the reading target database and the first moment are performed;
The time difference for judging first moment and current time whether more than the first preset duration judged result
Be it is no, or the time difference for judging first moment and current time whether more than the second preset duration judged result
During to be, the service state switching method also includes:
It is current time to update second moment.
Preferably, the service state according to local record, judge the destination service service state whether based on
With state, including:
According to the default cycle very first time and the service state of local record, the destination service is periodically judged
Whether service state is master state;Wherein, the cycle very first time is less than first preset duration, and described second is default
Duration is not less than first preset duration and the cycle very first time sum.
Preferably, it is described to read the first mark recorded in target database and the first moment, including:
Based on default second time cycle, periodically read the first mark for being recorded in the target database and
First moment, wherein, second time cycle is less than first preset duration, and second preset duration is not less than described
First preset duration and the second time cycle sum.
Preferably, when the first mark and the first moment of main service are not recorded in the target database, the clothes
Business state switching method also includes:
Using described second mark as described first identify, will current time as first moment, write the mesh
Mark database;
The service state for switching the destination service is master state.
Preferably, first mark and second mark include:The port information and equipment of corresponding with service
IP address information.
Second aspect, the embodiments of the invention provide a kind of service state switching device, applied to being configured with destination service
Equipment, the service state switching device includes:
Read module, for reading the recorded in target database first mark and the first moment, wherein, described first
The mark of the service in master state is identified as, first moment is the present service period of the service in master state
Initial time;
First judge module, for judging that it is identical that first mark identifies whether with the second of the destination service;
First processing module, in the case of being in the judged result of first judge module, judge the mesh
The service state of mark service is master state, and judges whether the time difference at first moment and current time is pre- more than first
If duration;If it is, the service state for switching the destination service is stand-by state;If it has not, renewal first moment is
Current time;
Second processing module, in the case of being no in the judged result of first judge module, judge the mesh
The service state of mark service is stand-by state, and judges whether the time difference at first moment and current time is pre- more than second
If duration;If it is, the service state for switching the destination service is master state, when renewal first moment is current
To carve, renewal described first is identified as second mark, wherein, when second preset duration is default not less than described first
It is long.
Preferably, the service state switching device also includes:
Second judge module, for the service state according to local record, judging the service state of the destination service is
No is master state;
3rd judge module, in the case of being in the judged result of second judge module, judge the mesh
Whether mark service and the network connection of the target database disconnect;If do not disconnected, the read module is triggered;As resolutely
Open, contrast the second moment and current time of local record, if the time difference at second moment and current time is more than described
First preset duration, the service state for switching the destination service are stand-by state, wherein, second moment is in primary
The present service period initial time of the service of state;
Judge the time difference at first moment and current time whether more than first described in the first processing module
When the judged result of preset duration is no, or first moment and current time are judged described in the Second processing module
Time difference whether more than the second preset duration judged result for be when, described device also includes:
Update module, it is current time for updating second moment.
Preferably, second judge module, is specifically used for:
According to the default cycle very first time and the service state of local record, the destination service is periodically judged
Whether service state is master state;Wherein, the cycle very first time is less than first preset duration, and described second is default
Duration is not less than first preset duration and the cycle very first time sum.
Preferably, the read module, is specifically used for:
Based on default second time cycle, periodically read the first mark for being recorded in the target database and
First moment, wherein, second time cycle is less than first preset duration, and second preset duration is not less than described
First preset duration and the second time cycle sum.
Preferably, when the first mark and the first moment of main service are not recorded in the target database, the clothes
Business state switching device also includes:
Writing module, for using described second mark as described first identify, will current time as described first when
Carve, write the target database;
Handover module, the service state for switching the destination service are master state.
Preferably, first mark and second mark include:The port information and equipment of corresponding with service
IP address information.
As seen from the above, in scheme provided in an embodiment of the present invention, the first mark recorded in target database is read first
Knowledge and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, target is judged
The service state of service is master state, and judge the first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If
Differ, the service state for judging destination service is stand-by state, and judge the first moment and current time time difference whether
More than the second preset duration;If it is, the service state of switching destination service is master state, when the first moment of renewal is current
Carve, renewal first is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed;Moreover, need not between the equipment at two service difference places of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
Certainly, any product or method for implementing the present invention must be not necessarily required to reach all the above excellent simultaneously
Point.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing
There is the required accompanying drawing used in technology description to be briefly described, it should be apparent that, drawings in the following description are only this
Some embodiments of invention, for those of ordinary skill in the art, on the premise of not paying creative work, can be with
Other accompanying drawings are obtained according to these accompanying drawings.
Fig. 1 is a kind of the first schematic flow sheet of service state switching method provided in an embodiment of the present invention;
Fig. 2 is a kind of second of schematic flow sheet of service state switching method provided in an embodiment of the present invention;
Fig. 3 is the first mark and for not recording current main service in the embodiment of the present invention in target database
In the case of one moment, the schematic flow sheet corresponding to the method for destination service switching service state;
Fig. 4 is a kind of the first structural representation of service state switching device provided in an embodiment of the present invention;
Fig. 5 is a kind of second of structural representation of service state switching device provided in an embodiment of the present invention.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out clear, complete
Site preparation describes, it is clear that described embodiment is only part of the embodiment of the present invention, rather than whole embodiments.It is based on
Embodiment in the present invention, those of ordinary skill in the art are obtained every other under the premise of creative work is not made
Embodiment, belong to the scope of protection of the invention.
The present invention is simply introduced from the angle being compared with the prior art first below.
In the prior art, in order to complete the switching of the service state of service, two except configuring corresponding with service content
Service is outer, can also dispose a ZooKeeper, and corresponding two equipment is required to being somebody's turn to do respectively for two services herein
ZooKeeper keeps connection, to ensure two services and the network connection of the ZooKeeper herein.
Sayed as foregoing, prior art is used as lock by creating znode nodes on ZooKeeper, gets the clothes of lock
Business turns into main service, does not obtain the service of lock as active service.Main service regularly updates znode nodes, continues holder lock, when
When main service the failures such as the machine of delaying occurs and disconnected with ZooKeeper, znode nodes are no longer updated, then active service obtains
Lock and the own services state that automatically switches are got, turns into new main service.
As seen from the above, the switching of the service state serviced in the prior art needs to rely on the ZooKeeper disposed in advance,
Otherwise the switching of service state can not be realized, and the waste of resource will certainly be caused by disposing extra ZooKeeper.
During using scheme provided in an embodiment of the present invention, the first mark and the recorded in target database is read first
One moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, the clothes of destination service are judged
Whether business state is master state, and judge the time difference at the first moment and current time more than the first preset duration;If it is,
The service state for switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If it is not the same, sentence
The service state of service of setting the goal is stand-by state, and judges whether the time difference at the first moment and current time is pre- more than second
If duration;If it is, the service state of switching destination service be master state, the first moment of renewal is current time, updates the
One is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed.
The present invention is described in detail by specific embodiment again below.
A kind of service state switching method provided in an embodiment of the present invention, the equipment applied to destination service is configured with.Should
The explanation, destination service herein can refer to the software with service function, in addition, this is configured with setting for destination service
Standby can directly be server, and service content is provided from server to client.
It is emphasized that the embodiment of the present invention is to be applied to be provided with the equipment of the destination service, and configure active and standby
Switch mode just has to two services of configuration, that is to say, that, it is necessary to two equipment for being configured with destination service, herein two
Destination service can be a main service of conduct, another is as active service during work.
A kind of the first schematic flow sheet of service state switching method provided in an embodiment of the present invention as shown in Figure 1,
This method includes:
S101:Read the first mark recorded in target database and the first moment.Wherein, this first is identified as and is in
The mark of the service of master state, first moment are the present service period initial time of the service in master state.
It is stored with the target database on the above-mentioned first mark and the record at the first moment, such as in the number of targets
According to creating a database table in storehouse, and with the entitled major key of service content, above-mentioned first is identified and is engraved when first
Record is in the database table.When the equipment accesses the target database, corresponding data can be found based on the title of service content
Storehouse table, and then read above-mentioned first mark and the first moment.
In embodiments of the present invention, the corresponding service for being currently at master state of the first mark;And the first moment is then right
Answer the initial time of the present service period of current time main service, it should illustrate, the starting of the seeervice cycle of a certain main service
Moment includes:At the time of the main service corresponds to when switching to master state by stand-by state, in addition, a certain service of the main service
Before end cycle, at the time of the main service corresponds to when entering next seeervice cycle.
For example, the said equipment when reading target database, recorded in the target database first be identified as X, first
20 divide 30 seconds when moment is September in 2016 1 day 10, show to be identified as X corresponding to the main service at current time, and the main service
Present service period at the beginning of between 20 to divide 30 seconds during September in 2016 1 day 10.
S102:It is identical to judge that the first mark identifies whether with the second of destination service.
Two services each are both provided with identifying, in embodiments of the present invention, in order to ensure the uniqueness of mark, the first mark
Know and the second mark may each comprise:The port information of corresponding with service and the IP address information of equipment, it will be understood that work as mesh
The service of marking is when having the software of service end function, and when starting the destination service in corresponding equipment, the destination service can account for
With a port, the port numbers can think above-mentioned port information.For example, IP address and port corresponding to a certain destination service
Number be respectively:36.7.72.139 and 8888, then now the second identification information of the destination service can be
“36.7.72.139:8888”.
If first mark is identical with second mark, S103 is performed:The service state for judging destination service is primary
State, and judge the time difference at the first moment and current time whether more than the first preset duration.
When first mark is identical with second mark, show to service based on the destination service, in the embodiment of the present invention
In, when destination service and the database keep normal communication connection, if what is recorded in database table in target database should
First mark is identical with second mark, and then judges after servicing based on the destination service, directly judges the first moment and currently
Whether the time difference at moment is more than the first preset duration.
It should be noted that the first preset duration herein can correspond to the duration of a lease, the service of above-mentioned main service
Cycle can correspond to a lease, and the embodiment of the present invention is exactly to be realized by the first mark recorded in the target database
The function of lock, period of validity corresponding to lock are exactly to be limited according to the lease.
For example, first preset duration is 1 minute, the first moment recorded in the current time target database is:
0 divides 40 seconds during August in 2016 30 days 1, if 1 dividing 45 seconds when current time is August in 2016 30 days 1, represents for the first moment with working as
The time difference at preceding moment has exceeded the first preset duration;In other words, that is, a lease of main service is set as August in 2016 30 days
01 divides 40 seconds when dividing 40 seconds to 2016 on Augusts 30,1 when 1, if 1 dividing 45 seconds when current time is August in 2016 30 days 1, represents
Current lease is crossed.
If the time difference at first moment and current time more than the first preset duration, performs S1031:Switch target clothes
The service state of business is stand-by state.
If the time difference at first moment and current time not less than the first preset duration, performs S1032:Update this
One moment was current time.
Now, although destination service did not terminate, can entered as main service, its current corresponding seeervice cycle
Row step S1032, so that winner, which services, enters next seeervice cycle, the destination service does not change the service state of itself.Example
Such as:The first moment recorded in the target database is:1 divides 25 seconds during August in 2014 10 days 9, and the first preset duration is 2 points
Clock, current time be:2 divide 25 seconds during August in 2014 10 days 9, and now the time difference at first moment and current time is not less than 2
Minute, then the first moment for only needing to update in the target database is:2 divide 25 seconds during August in 2014 10 days 9.
If first mark differs with second mark, S104 is performed:The service state for judging destination service is standby
With state, and judge the time difference at the first moment and current time whether more than the second preset duration;Wherein, this second it is default when
Length is not less than first preset duration.
It is obvious, if the time difference at first moment and current time not less than the second preset duration, do not do any
Operation, keeps the service state of destination service to remain as stand-by state.
If the time difference at first moment and current time more than the second preset duration, performs S1041:Switch target clothes
The service state of business is master state, and it is current time to update first moment, update this first be identified as this second mark.
For example, the first moment recorded in target database is:54 divide 0 second during September in 2016 10 days 2, and the first of record
It is identified as 36.7.72.148:6666, the second preset duration is 1 minute, and current time is:55 divide 30 during September in 2016 10 days 2
Second, the second of destination service is identified as 36.7.72.139:8888, now the time difference at the first moment and current time exceeded
Second preset duration, then it is master state that the destination service switches own services state first, is then updated in target database
The first moment be:55 divide 30 seconds during September in 2016 10 days 2, and renewal first is identified as:36.7.72.139:8888.
Additionally it should illustrate, in active-standby switch pattern, two services corresponding to same service content can not be simultaneously
In master state, if so the second preset duration is less than first preset duration, it is more likely that current main service occur
Still in normal operation, active service but switches to another main service.
For example, the first moment recorded in the target database is:24 divide 8 seconds during August in 2015 18 days 8, and first is default
Shi Changwei 2 minutes, the second preset duration are 1 minute, it is assumed that current time is:25 divide 38 seconds during August in 2015 18 days 8, currently
Main the service x and active service y that moment corresponds to same service content have read the target database simultaneously, due to the first moment
With time difference at current time not less than the first preset duration 2 minutes, but the second preset duration is exceeded 1 minute, has now led
It is only that can update the first moment stored in target database to service x, does not change own services state, but active service y meetings
It is master state to switch own services state, and now, two services corresponding to same service content are in master state simultaneously.
In the embodiment of the present invention, in order to ensure that destination service can switch the service state of itself, above-mentioned reading in time
The first mark recorded in target database and the first moment (S101), it can include:
Based on default second time cycle, the first mark and first recorded in target database is periodically read
Moment, wherein, the second time cycle was less than the first preset duration, when the second preset duration is not less than the first preset duration and second
Between cycle sum.
It is understood that if current main service is broken down, network connection is disconnected with above-mentioned target database,
Client can not be continued as simultaneously service content is provided, do not read in time as equipment where the destination service of active service
Database is taken, the main service that the destination service turns into new would not be switched in time, and then carried for client by new main service
For service content.
But if this as active service destination service where equipment with the second time less than the first preset duration
In the cycle, the step of periodically carrying out foregoing S101, it can just switch the main service that the destination service turns into new in time, and then by new
Main service provide service content for client.
Such as:35 divide 20 seconds when the first moment recorded in target database is 18 days 2 January in 2013, first it is default when
A length of 2 minutes, it is assumed that main service is disconnected the network connection with target database when 36 divided 30 seconds at 18 days 2 January in 2013,
Client can not be continued as simultaneously, and service content is provided;But as equipment where the destination service of active service in 2013
0 divides and just performs within 30 seconds step S101 during 18 days 3 January, and is serviced based on the successful switch destination service, it will be understood that
36 0 divide client in 30 seconds this periods not get when dividing 30 seconds to 2013 on January 18,3 during 18 days 2 January in 2013
Service content.
But if if this as active service destination service where equipment with 1 minute for time interval, periodically
Ground performs the step of foregoing S101, the second preset duration be 2 points 5 seconds, ibid example, it is assumed that the equipment was at 18 days 2 January in 2013
The step of foregoing S101 being performed at 36 points and 20 seconds, when now being preset due to the time difference at the first moment and the moment not less than second
Long, the destination service remains as active service, and interval is after 1 minute, and 37 divide 20 seconds when current time is 18 days 2 January in 2013, this
When the first moment and current time time difference more than the second preset duration, the destination service is switching to new main service,
It is appreciated that 36 37 divide 20 seconds this shorter time periods when dividing 30 seconds to 2013 on January 18,2 only at 18 days 2 January in 2013
Interior client can not get service content.
On the other hand, it is normal with the network connection of target database if main service does not occur any failure, while also may be used
Normally to provide service content to client, still, due to no the first moment updated in time in target database, have
It is likely to occur:From first moment after the second preset duration, service, caused corresponding to same based on active service switching
Two services of service content are in master state.
For example, 35 divide 20 seconds when the first moment recorded in target database is 18 days 2 January in 2013, first it is default when
A length of 1 minute, the second preset duration be 1 point 10 seconds, it is assumed that to January 18 in 2013 after dividing 20 seconds from during 18 days 2 January in 2013 35
37 divided in the time of 00 second during day 2, and the equipment where main service is not carried out step S101 all the time, then during no renewal first
Carve, and the main service can provide service content to service end all the time;At 18 days 2 January in 2013,37 when dividing 00 second, currently
Active service where equipment perform step S101, and carry out subsequent step, it is clear that, the first moment and current time when
Between difference exceeded the second preset duration, then the active service can equally switch to main service, now, corresponding to same service content
Two services be in master state.
But if if this as main service destination service where equipment with 40 seconds for time interval, periodically
The step of performing foregoing S101, that is to say, that in the case that main service is not broken down, equipment was at interval of 40 seconds where main service
Carry out the operation for once updating that the first moment was current time, it will be understood that in the case, ensure active service place
When equipment reads the target database every time, first moment with the time difference at corresponding current time not over 40 seconds, i.e.,
Divide 10 seconds no more than foregoing second preset duration 1, so it is master state that the active service, which will not switch oneself state,.
In addition, it is to be noted that even if main service is not broken down, above-mentioned renewal first moment still can be performed
For current time (S1032), it is not intended that it is current time that main service, which necessarily can successfully change first moment,.
Assuming that main service does not have successful execution S1032, main service in the first preset duration since the first moment
Inevitable also be stand-by state without switching own services state, it is further assumed that main service is preset beginning to pass through first from the first moment
After duration corresponding to the 3rd moment perform step S1032, still, be not updated successfully, it is clear that main service will not switch from
The service state of body, now, the time for performing step S101 next time would is that after the 3rd moment by the second predetermined period
The 4th corresponding moment, and just to switch oneself state be stand-by state for main service at four moment, if the
Three moment, it was master state, now, same service content that active service, which performs switching oneself state, between the 4th moment
Two services are in master state.
It can be said that from the period at the 3rd moment to the 4th moment be a grace period, within the grace period, by two service structures
Into system be in a kind of jeopardy (danger) state, within this period, it is possible that two services are in primary shape
The phenomenon of state.
So the second preset duration herein is not less than the first preset duration and the second time cycle sum, also for
Guarantee will not be in the phenomenon of master state in synchronization corresponding to two services of same service content, it is, of course, preferable to
, the second default preset duration is directly equal to the first preset duration and the second time cycle sum.
For example, first moment 10 divides 5 seconds when being 2015 9 and 3 days 7, the first preset duration is 1 minute, second round
For 20 seconds, it is assumed that 11 divided in the period of 5 seconds when dividing 5 seconds to 2015 9 and 3 days 7 from 2015 9 and 3 days 7 10, and main service is held
Row step S1032, but be not successfully completed renewal operation, and 11 divided 5 seconds at 2015 9 and 3 days 7 and perform step
S1032, but be not updated successfully still, it is clear that, then after 20 seconds, it is standby that main service, which can just perform switching oneself state,
With the operation of state, so, corresponding active service 11 should divide 5 seconds in 20 seconds after starting at 2015 9 and 3 days 7, no
The operation that switching oneself state is master state can be performed, thus the second default preset duration be no less than the first preset duration with
Second time cycle sum.
It should be noted that two services of corresponding same service content, when arrangement is most started, two services are all
In stand-by state, meanwhile, the first mark and the first moment of current main service are not recorded in the target database yet, such as
Shown in Fig. 3, now this method also includes:
S301:Using the second of destination service the mark as first mark, will current time as first moment, write
Target database.
First mark is not recorded in target database and in the case of first moment, it is necessary in the number of targets
According to write-in in storehouse on the first mark and the record at first moment, while the second mark is assigned to first mark, will
Current time is assigned to first moment.
S302:The service state for switching destination service is master state.
It is appreciated that in the embodiment of the present invention, do not recorded in target database first mark and this first when
In the case of quarter, two services in stand-by state simultaneously, the second of destination service is identified as first mark at first,
And the service of target database is write using current time as first moment, it is primary shape that can switch own services state
State.
It is well known by those skilled in the art that when service is in stand-by state, its corresponding port is to close, so main
, it is necessary to close port corresponding to main service when service switching oneself state is stand-by state.It should be noted that in prior art
In, when client is based on domain name access main service, due to itself not having the IP address and port information of main service, so objective
Family end can send to Zookeeper and ask, and get the IP address and port information of current main service, and then access main service
To obtain corresponding service content.
In the embodiment of the present invention, when client is based on domain name access main service, client broadcasts the domain name, net to network-side
Network end group is in IP address and port information corresponding to the domain name lookup, because the port of active service is closed, so
Network-side only can be to client feedback currently IP address and port information corresponding to main service, so that client is based on current main clothes
IP address corresponding to business and port information, access main service, it is clear that, in embodiments of the present invention, client need not appoint
What is changed.
It is appreciated that the embodiment of the present invention make use of Database lock mechanism, target is realized using database table as lock
The switching of the service state of service, obtain and more newly arrive by the lease of lock and realize the switching of active and standby service.People in the art
Member is well known that, database table is locked using SELECT FOR UPDATE (a kind of add handwork lock sentence), to same database
The affairs that table is operated, it is necessary to could be performed after other Transaction Informations COMMIT (release).
The database table is exactly to be stored with the database table at first moment and the first mark, and each lease is exactly from first
Moment start after the first preset duration in corresponding period.The target database can be common database, such as
Mysql databases.
Such as a database table is established in database, specific database table structure is as shown in table 1 below.
Table 1
Filed | Type | Null | Key | Default |
service_name | varchar(36) | NO | PRI | NULL |
active_server_ip_port | varchar(36) | YES | NULL | |
last_active_time | datetime | YES | NULL |
In table, " service_name " represents the title of service content, and its corresponding data type is " varchar (characters
Type) ", maximum character length is 36 bytes, and the title of service content can not think sky, moreover, the entitled number of service content
According to the major key of storehouse table, default value can not think sky corresponding to the title of service content;" active_server_ip_port " is represented
Above-mentioned first mark, can be represented with the IP address and port address of main service in embodiments of the present invention, the first mark
Corresponding data type is " varchar (character type) ", and maximum character length is 36 bytes, and the first mark can be sky, and
And first mark corresponding to default value can be sky;" last_active_time " represents above-mentioned first moment, number corresponding to it
According to type " datetime (date-time) ", the first moment can be sky, and default value corresponding to the first moment can be sky.
In addition, in active-standby switch pattern, corresponding to same service content two services not in the same period all
In master state.Therefore:
In the prior art, in order to prevent original main service be seemingly-dead such as original main service simply with
Zookeeper network connection goes wrong, but original main service still can provide service content to client, now fresh cut
The main service changed needs to carry out original main service fence (fence) operations, it is ensured that it no longer provides service content, ensures two
A main service is only existed in individual service.In order to ensure at most only to deposit a master in two services corresponding to same service content
Service is, it is necessary to which the communication between devices residing for two services respectively connect, to ensure that fence operations can be realized.
And in embodiments of the present invention, need not between the equipment where two services respectively of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
As seen from the above, in scheme provided in an embodiment of the present invention, the first mark recorded in target database is read first
Knowledge and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, target is judged
The service state of service is master state, and judge the first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If
Differ, the service state for judging destination service is stand-by state, and judge the first moment and current time time difference whether
More than the second preset duration;If it is, the service state of switching destination service is master state, when the first moment of renewal is current
Carve, renewal first is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed;Moreover, need not between the equipment at two service difference places of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
Relative to Fig. 1, a kind of second of schematic flow sheet of service state switching method as shown in Figure 2, this method is also
Including:
S201:According to the service state of local record, whether the service state for judging destination service is master state.
It is understood that the equipment for being configured with destination service can be easy to know whether current service is in primary shape
State, for example, whether port corresponding to the destination service is in open mode, or, whether destination service thereon is provided out
Service content, information of the equipment based on the record of itself judge whether the destination service can be by existing in master state
Technology realizes that the embodiment of the present invention will not be repeated here.
In embodiments of the present invention, the above-mentioned service state according to local record, judging the service state of destination service is
No is master state, Ke Yishi:
According to the default cycle very first time and the service state of local record, the service of destination service is periodically judged
Whether state is master state;Wherein, the cycle very first time is less than first preset duration, second preset duration
Not less than first preset duration and the cycle very first time sum.
It should be noted that the effect in the cycle very first time herein is identical with the effect of foregoing second time cycle, and
And, it is preferred that the cycle very first time is arranged to identical value with the second time cycle.
Designed in addition, the above-mentioned cycle very first time and the second time cycle can be based on actual conditions, in equipment performance
In the case of permission, the cycle very first time and the second time cycle should be set as small as possible.
If S201 judged result is no, S101 is performed:Read the first mark and first recorded in target database
Moment.
If S201 judged result is yes, S202 is performed:Judge destination service and target database network connection whether
Disconnect.
If the network connection of destination service and target database disconnects, S203 is performed:When contrasting the second of local record
Carve and current time, if the time difference at second moment and current time more than the first preset duration, switches the clothes of destination service
Business state is stand-by state.Wherein, second moment is the present service period initial time of the service in master state.
It should distinguish, second moment is recorded in destination service, that is, is recorded in the equipment where destination service;
And the first moment was then recorded in the target database.Additionally it should, it is emphasized that in all embodiments of the invention,
One moment and the second moment can use timestamp, and it can directly be renewal pair at current time that the first moment of foregoing renewal, which is,
The timestamp answered.
Obvious, if destination service disconnects as main service and the network connection of target database, also can not just succeed
Step S101 is performed, also just can not necessarily perform the operation at the first moment of renewal, destination service is in main service state all the time, and
Another relative service of destination service services based on will necessarily at a time switching, and two services occurs and is in primary shape
The phenomenon of state.
But in embodiments of the present invention, main service can be switched to by active service by step S201~S203, institute
So that step S201~S203 operation can avoid, in the case where main service disconnects with target database network, occurring two
Service is in the phenomenon of master state.
If the network connection of destination service and target database does not disconnect, perform above-mentioned state and remember in reading target database
First mark of record and the first moment (S101).
In order to ensure upgrading in time for the second moment, whether the above-mentioned time difference for judging the first moment and current time exceedes
The judged result of first preset duration is no, or whether the above-mentioned time difference for judging the first moment and current time is more than second
The judged result of preset duration is when being, this method also includes:
S105:It is current time to update second moment.
Such as:Destination service x is currently at master state, and foregoing the cycle very first time and the second time cycle are 1 point
Clock, 11 divide 5 seconds when the first moment was 2015 9 and 3 days 7, it is clear that and 11 divide 5 seconds when the second moment was also 2015 9 and 3 days 7,
Assuming that the first preset duration is 2 minutes, if destination service x 11 divided 50 seconds and target database at 2015 9 and 3 days 7
Network connection disconnects, that is, represents that hereafter the equipment where destination service x can not read the target database;But destination service x
Whether the equipment at place may determine that the time difference at second moment and current time more than the first preset duration, it is assumed that target takes
Equipment where business x 13 was divided 45 seconds at 2015 9 and 3 days 7 and performs operation:Judge second moment and current time when
Between difference whether more than the first preset duration, now, due to judging that the time difference at second moment and current time is pre- more than first
If duration, so the service state that can switch destination service x is stand-by state.
As seen from the above, in scheme provided in an embodiment of the present invention, the first mark recorded in target database is read first
Knowledge and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, target is judged
The service state of service is master state, and judge the first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If
Differ, the service state for judging destination service is stand-by state, and judge the first moment and current time time difference whether
More than the second preset duration;If it is, the service state of switching destination service is master state, when the first moment of renewal is current
Carve, renewal first is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed;Moreover, need not between the equipment at two service difference places of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
Below by a specific example, simply to be introduced the present invention.
For the service content of one entitled " ABCDEFG ", it is corresponding with two services:X and y, service the corresponding of x
Second is identified as 154.125.2.8:7777, service y corresponding second is identified as 154.125.2.136:8888, foregoing first
Time cycle and the second time cycle are 30 seconds, the first preset duration be 1 minute, the second preset duration be 1 point 30 seconds.
At the beginning of most, service x and y is in stand-by state, and then, service x establishes major key in target database
For " ABCDEFG " database table, and 154.125.2.8 is identified as by itself second:7777 and 2015 current times September 30
1 divides 55 seconds and is written to respectively as the first mark and the first moment in target database when days 14, now service x become based on take
Business.
Assuming that in September in 2015 30 days 14 20 when dividing 55 seconds, the first moment was updated to September in 2015 30 by service x
20 divide 55 seconds when 14, can not then be successfully updated for the first moment all the time, then after dividing 55 seconds to during September in 2015 30 days 14 21,
22 when dividing 05 second such as in September in 2015 30 days 14, and service x again reads off database, now due to the first moment with it is current when
The time difference at quarter, then switching service x service state was stand-by state more than the first preset duration.
Meanwhile when to September in 2015 30 days 14 22 divide 25 seconds after, 22 when dividing 30 seconds such as in September in 2015 30 days 14,
Service titles " ABCDEFG " of the y based on service content finds corresponding database table, then reads the first moment therein and the
One mark, because the time difference at the first moment and current time is more than the service state of the second preset duration, then switching service y
For master state.
It is appreciated that when scheme provided by the invention is applied in two services corresponding to same service content, can be certainly
It is dynamic to realize active-standby switch.
Corresponding to Fig. 1, as shown in figure 4, a kind of service state switching device provided in an embodiment of the present invention, applied to configuration
There is the equipment of destination service, described device includes:
Read module 110, for reading the recorded in target database first mark and the first moment, wherein, it is described
First is identified as the mark of the service in master state, and first moment is the current service of the service in master state
Period start time;
First judge module 120, for judging that it is identical that first mark identifies whether with the second of the destination service;
First processing module 130, in the case of being in the judged result of first judge module, described in judgement
Whether the service state of destination service is master state, and judge the time difference at first moment and current time more than first
Preset duration;If it is, the service state for switching the destination service is stand-by state;If it has not, renewal first moment
For current time;
Second processing module 140, in the case of being no in the judged result of first judge module, described in judgement
Whether the service state of destination service is stand-by state, and judge the time difference at first moment and current time more than second
Preset duration;If it is, the service state for switching the destination service is master state, when renewal first moment is current
To carve, renewal described first is identified as second mark, wherein, when second preset duration is default not less than described first
It is long.
In practical application, specifically, the read module 110, is specifically used for:
Based on default second time cycle, periodically read the first mark for being recorded in the target database and
First moment, wherein, second time cycle is less than first preset duration, and second preset duration is not less than described
First preset duration and the second time cycle sum.
Specifically, first mark and second mark include:The IP address information of the equipment of corresponding with service
And port information.
Additionally it should illustrate, the first mark and the first moment of main service are not recorded in the target database
When, described device also includes writing module and handover module (not shown):
Writing module, for using described second mark as described first identify, will current time as described first when
Carve, write the target database;
Handover module, the service state for switching the destination service are master state.
As seen from the above, in scheme provided in an embodiment of the present invention, the first mark recorded in target database is read first
Knowledge and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, target is judged
The service state of service is master state, and judge the first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If
Differ, the service state for judging destination service is stand-by state, and judge the first moment and current time time difference whether
More than the second preset duration;If it is, the service state of switching destination service is master state, when the first moment of renewal is current
Carve, renewal first is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed;Moreover, need not between the equipment at two service difference places of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
Corresponding to Fig. 2, as shown in figure 5, a kind of service state switching device provided in an embodiment of the present invention, can also be wrapped
Include:
Second judge module 210, for the service state according to local record, judge the service state of the destination service
Whether it is master state.If the judged result of the second judge module 210 is no, above-mentioned read module 110 is directly triggered.
3rd judge module 220, in the case of being in the judged result of second judge module 210, judge
Whether the network connection of the destination service and the target database disconnects;If do not disconnected, the read module is triggered
110;If off the second moment and current time of local record being contrasted, if the time at second moment and current time
Difference exceedes first preset duration, and the service state for switching the destination service is stand-by state, wherein, second moment
For the present service period initial time of the service in master state;
Judge the time difference at first moment and current time whether more than described in the first processing module 130
When the judged result of one preset duration is no, or judge first moment with working as described in the Second processing module 140
The time difference at preceding moment whether more than the second preset duration judged result for be when, described device also includes:
Update module 150, it is current time for updating second moment.
Specifically, second judge module 210, is specifically used for:
According to the default cycle very first time and the service state of local record, the destination service is periodically judged
Whether service state is master state;Wherein, the cycle very first time is less than first preset duration, and described second is default
Duration is not less than first preset duration and the cycle very first time sum.
As seen from the above, in scheme provided in an embodiment of the present invention, the first mark recorded in target database is read first
Knowledge and the first moment;Then it is identical to judge that the first mark identifies whether with the second of destination service;If identical, target is judged
The service state of service is master state, and judge the first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state of switching destination service is stand-by state;If it has not, the first moment of renewal is current time;If
Differ, the service state for judging destination service is stand-by state, and judge the first moment and current time time difference whether
More than the second preset duration;If it is, the service state of switching destination service is master state, when the first moment of renewal is current
Carve, renewal first is identified as the second mark.
Compared with prior art, in scheme provided in an embodiment of the present invention, corresponding to two services of same service content
Stored in the target database first mark the second mark corresponding with itself can be contrasted, and then judge that the target takes
Business is currently main service or active service;When the destination service is in master state, if the first moment and current time
Time difference more than the first preset duration, then destination service switching oneself state is stand-by state, when the destination service is in
During stand-by state, if the time difference at the first moment and current time, more than the second preset duration, destination service switching is certainly
Body state is master state;The switching of the service state of destination service can be according to the respective record in target database, not
Need additionally to dispose Zookeeper, also avoid the need for special keeper and safeguard Zookeeper, reduce extra deployment
The resource that Zookeeper is consumed;Moreover, need not between the equipment at two service difference places of corresponding same service content
It is in communication with each other connection, it is possible to ensure that two services for being directed to same service content will not be within the same period all in primary
State, while reduce this and communicate to connect consumed resource.
It should be noted that herein, such as first and second or the like relational terms are used merely to a reality
Body or operation make a distinction with another entity or operation, and not necessarily require or imply and deposited between these entities or operation
In any this actual relation or order.Moreover, term " comprising ", "comprising" or its any other variant are intended to
Nonexcludability includes, so that process, method, article or equipment including a series of elements not only will including those
Element, but also the other element including being not expressly set out, or it is this process, method, article or equipment also to include
Intrinsic key element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that
Other identical element also be present in process, method, article or equipment including the key element.
Each embodiment in this specification is described by the way of related, identical similar portion between each embodiment
Divide mutually referring to what each embodiment stressed is the difference with other embodiment.It is real especially for device
For applying example, because it is substantially similar to embodiment of the method, so description is fairly simple, related part is referring to embodiment of the method
Part explanation.
Can one of ordinary skill in the art will appreciate that realizing that all or part of step in above method embodiment is
To instruct the hardware of correlation to complete by program, described program can be stored in computer read/write memory medium,
The storage medium designated herein obtained, such as:ROM/RAM, magnetic disc, CD etc..
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the scope of the present invention.It is all
Any modification, equivalent substitution and improvements made within the spirit and principles in the present invention etc., are all contained in protection scope of the present invention
It is interior.
Claims (12)
1. a kind of service state switching method, the equipment applied to destination service is configured with, it is characterised in that methods described bag
Include:
The first mark recorded in target database and the first moment are read, wherein, described first is identified as in primary shape
The mark of the service of state, first moment are the present service period initial time of the service in master state;
It is identical to judge that first mark identifies whether with the second of the destination service;
If identical, the service state for judging the destination service is master state, and judge first moment with it is current when
Whether the time difference at quarter is more than the first preset duration;If it is, the service state for switching the destination service is stand-by state;If
It is no, it is current time to update first moment;
If it is not the same, the service state for judging the destination service is stand-by state, and judge first moment with it is current
Whether the time difference at moment is more than the second preset duration;If it is, the service state for switching the destination service is master state,
It is current time to update first moment, and renewal described first is identified as second mark, wherein, described second it is default when
Length is not less than first preset duration.
2. according to the method for claim 1, it is characterised in that methods described also includes:
According to the service state of local record, whether the service state for judging the destination service is master state;
If it is, judging whether the network connection of the destination service and the target database disconnects;
If off the second moment and current time of local record being contrasted, if the time at second moment and current time
Difference exceedes first preset duration, and the service state for switching the destination service is stand-by state, wherein, second moment
For the present service period initial time of the service in master state;
If do not disconnected, the first mark recorded in the reading target database and the first moment are performed;
The time difference for judging first moment and current time whether more than the first preset duration judged result be it is no,
Or whether the time difference for judging first moment and current time is yes more than the judged result of the second preset duration
When, methods described also includes:
It is current time to update second moment.
3. according to the method for claim 2, it is characterised in that the service state according to local record, described in judgement
Whether the service state of destination service is master state, including:
According to the default cycle very first time and the service state of local record, the service of the destination service is periodically judged
Whether state is master state;Wherein, the cycle very first time is less than first preset duration, second preset duration
Not less than first preset duration and the cycle very first time sum.
4. according to the method for claim 1, it is characterised in that it is described read target database in record first mark with
And first moment, including:
Based on default second time cycle, the first mark and first recorded in the target database is periodically read
Moment, wherein, second time cycle is less than first preset duration, and second preset duration is not less than described first
Preset duration and the second time cycle sum.
5. according to the method for claim 1, it is characterised in that do not record the first of main service in the target database
When mark and the first moment, methods described also includes:
Using described second mark as described first identify, will current time as first moment, write the number of targets
According to storehouse;
The service state for switching the destination service is master state.
6. according to the method described in any one of Claims 1 to 5, it is characterised in that first mark and second mark
Knowledge includes:The port information of corresponding with service and the IP address information of equipment.
7. a kind of service state switching device, the equipment applied to destination service is configured with, it is characterised in that described device bag
Include:
Read module, for reading the recorded in target database first mark and the first moment, wherein, first mark
For the mark of the service in master state, first moment originates for the present service period of the service in master state
Moment;
First judge module, for judging that it is identical that first mark identifies whether with the second of the destination service;
First processing module, in the case of being in the judged result of first judge module, judge the target clothes
The service state of business is master state, and judge first moment and current time time difference it is whether default more than first when
It is long;If it is, the service state for switching the destination service is stand-by state;If it has not, renewal first moment is current
Moment;
Second processing module, in the case of being no in the judged result of first judge module, judge the target clothes
The service state of business is stand-by state, and judge first moment and current time time difference it is whether default more than second when
It is long;If it is, the service state for switching the destination service is master state, it is current time to update first moment, more
New described first is identified as second mark, wherein, second preset duration is not less than first preset duration.
8. device according to claim 7, it is characterised in that described device also includes:
Second judge module, for the service state according to local record, judge the destination service service state whether be
Master state;
3rd judge module, in the case of being in the judged result of second judge module, judge the target clothes
Whether business and the network connection of the target database disconnect;If do not disconnected, the read module is triggered;If off right
Than the second moment of local record and current time, if the time difference at second moment and current time is pre- more than described first
If duration, the service state for switching the destination service is stand-by state, wherein, second moment is in master state
The present service period initial time of service;
Judge whether the time difference at first moment and current time is default more than first described in the first processing module
The judged result of duration for it is no when, or judge described in the Second processing module first moment and current time when
Between difference whether more than the second preset duration judged result for be when, described device also includes:
Update module, it is current time for updating second moment.
9. device according to claim 8, it is characterised in that second judge module, be specifically used for:
According to the default cycle very first time and the service state of local record, the service of the destination service is periodically judged
Whether state is master state;Wherein, the cycle very first time is less than first preset duration, second preset duration
Not less than first preset duration and the cycle very first time sum.
10. device according to claim 7, it is characterised in that the read module, be specifically used for:
Based on default second time cycle, the first mark and first recorded in the target database is periodically read
Moment, wherein, second time cycle is less than first preset duration, and second preset duration is not less than described first
Preset duration and the second time cycle sum.
11. device according to claim 7, it is characterised in that do not record the of main service in the target database
When one mark and the first moment, described device also includes:
Writing module, for using described second mark as described first identify, will current time as first moment, write
Enter the target database;
Handover module, the service state for switching the destination service are master state.
12. according to the device described in any one of claim 7~11, it is characterised in that first mark and described second
Mark includes:The port information of corresponding with service and the IP address information of equipment.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610818126.9A CN107819556B (en) | 2016-09-12 | 2016-09-12 | Service state switching method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610818126.9A CN107819556B (en) | 2016-09-12 | 2016-09-12 | Service state switching method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107819556A true CN107819556A (en) | 2018-03-20 |
CN107819556B CN107819556B (en) | 2020-04-28 |
Family
ID=61601114
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610818126.9A Active CN107819556B (en) | 2016-09-12 | 2016-09-12 | Service state switching method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107819556B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111464580A (en) * | 2019-01-22 | 2020-07-28 | 阿里巴巴集团控股有限公司 | Method and device for selecting main server |
CN112866314A (en) * | 2019-11-27 | 2021-05-28 | 上海哔哩哔哩科技有限公司 | Method for switching slave nodes in distributed master-slave system, master node device and storage medium |
CN112860386A (en) * | 2019-11-27 | 2021-05-28 | 上海哔哩哔哩科技有限公司 | Method for switching nodes in distributed master-slave system |
CN113467953A (en) * | 2021-07-16 | 2021-10-01 | 腾讯科技(深圳)有限公司 | Service state switching method and device, server and storage medium |
WO2023173870A1 (en) * | 2022-03-15 | 2023-09-21 | 苏州浪潮智能科技有限公司 | Control method and apparatus for storage device, electronic device and non-volatile readable storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101888268A (en) * | 2009-05-14 | 2010-11-17 | 中兴通讯股份有限公司 | Method and device for realizing backbone optical fiber protection in Ethernet passive optical network |
CN101945036A (en) * | 2009-07-08 | 2011-01-12 | 中兴通讯股份有限公司 | Judging method for failure of main router of virtual route redundancy protocol and router |
CN103036719A (en) * | 2012-12-12 | 2013-04-10 | 北京星网锐捷网络技术有限公司 | Cross-regional service disaster method and device based on main cluster servers |
US8732832B2 (en) * | 2010-12-02 | 2014-05-20 | Electronics And Telecommunications Research Institute | Routing apparatus and method for detecting server attack and network using the same |
CN103825777A (en) * | 2014-02-14 | 2014-05-28 | 杭州华三通信技术有限公司 | DMZ server switching method and device |
CN104778102A (en) * | 2015-03-27 | 2015-07-15 | 深圳市创梦天地科技有限公司 | Master-slave switching method and system |
-
2016
- 2016-09-12 CN CN201610818126.9A patent/CN107819556B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101888268A (en) * | 2009-05-14 | 2010-11-17 | 中兴通讯股份有限公司 | Method and device for realizing backbone optical fiber protection in Ethernet passive optical network |
CN101945036A (en) * | 2009-07-08 | 2011-01-12 | 中兴通讯股份有限公司 | Judging method for failure of main router of virtual route redundancy protocol and router |
US8732832B2 (en) * | 2010-12-02 | 2014-05-20 | Electronics And Telecommunications Research Institute | Routing apparatus and method for detecting server attack and network using the same |
CN103036719A (en) * | 2012-12-12 | 2013-04-10 | 北京星网锐捷网络技术有限公司 | Cross-regional service disaster method and device based on main cluster servers |
CN103825777A (en) * | 2014-02-14 | 2014-05-28 | 杭州华三通信技术有限公司 | DMZ server switching method and device |
CN104778102A (en) * | 2015-03-27 | 2015-07-15 | 深圳市创梦天地科技有限公司 | Master-slave switching method and system |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111464580A (en) * | 2019-01-22 | 2020-07-28 | 阿里巴巴集团控股有限公司 | Method and device for selecting main server |
CN111464580B (en) * | 2019-01-22 | 2022-04-22 | 阿里巴巴集团控股有限公司 | Method and device for selecting main server |
CN112866314A (en) * | 2019-11-27 | 2021-05-28 | 上海哔哩哔哩科技有限公司 | Method for switching slave nodes in distributed master-slave system, master node device and storage medium |
CN112860386A (en) * | 2019-11-27 | 2021-05-28 | 上海哔哩哔哩科技有限公司 | Method for switching nodes in distributed master-slave system |
CN112866314B (en) * | 2019-11-27 | 2023-04-07 | 上海哔哩哔哩科技有限公司 | Method for switching slave nodes in distributed master-slave system, master node device and storage medium |
CN113467953A (en) * | 2021-07-16 | 2021-10-01 | 腾讯科技(深圳)有限公司 | Service state switching method and device, server and storage medium |
CN113467953B (en) * | 2021-07-16 | 2023-08-04 | 腾讯科技(深圳)有限公司 | Service state switching method and device, server and storage medium |
WO2023173870A1 (en) * | 2022-03-15 | 2023-09-21 | 苏州浪潮智能科技有限公司 | Control method and apparatus for storage device, electronic device and non-volatile readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN107819556B (en) | 2020-04-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107819556A (en) | A kind of service state switching method and device | |
CN103294675B (en) | Data-updating method and device in a kind of distributed memory system | |
CN105095462B (en) | Handle the method and system of webpage repetitive requests | |
CN103793514B (en) | Database synchronization method and database | |
CN103825950B (en) | A kind of method and system based on the synchronous contact person of cloud platform | |
CA3028504C (en) | Data processing method and device | |
CN101300779B (en) | Method and system for providing service to subscribers | |
CN104202440B (en) | A kind of method of marking terminal, server and system | |
CN108234306A (en) | Network equipment, network method and computer readable storage medium | |
CN107220142A (en) | Perform the method and device of data recovery operation | |
CN107391758A (en) | Database switching method, device and equipment | |
CN110147684A (en) | For realizing the method and apparatus of block chain data-privacy protection | |
CN104243472A (en) | Network with MAC table overflow protection | |
CN105162835B (en) | The service registration framework and method of automation system for the power network dispatching | |
CN102202087A (en) | Method for identifying storage equipment and system thereof | |
CN109495202A (en) | A kind of method for synchronizing time and device | |
CN106576232A (en) | System and method for handling inactive sim cards | |
CN101551822B (en) | Method and apparatus for copying database | |
TWI640885B (en) | Data uniqueness control method, information storage method and device | |
CN110535939A (en) | A kind of service discovery and method for pre-emptively, device, computer equipment and storage medium | |
CN102299814A (en) | Method and system for upgrading MIB (management information base) on SNMP (simple network management protocol) agent | |
CN102412984A (en) | Management method and equipment for forwarded table entry | |
CN109710676A (en) | Data capture method, device and the electronic equipment of CMDB model | |
CN109829821A (en) | A kind of abnormal processing method of digital asset address transfer, apparatus and system | |
CN107741994A (en) | A kind of data-updating method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |