CN107819556B - Service state switching method and device - Google Patents

Service state switching method and device Download PDF

Info

Publication number
CN107819556B
CN107819556B CN201610818126.9A CN201610818126A CN107819556B CN 107819556 B CN107819556 B CN 107819556B CN 201610818126 A CN201610818126 A CN 201610818126A CN 107819556 B CN107819556 B CN 107819556B
Authority
CN
China
Prior art keywords
service
time
state
moment
identifier
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.)
Active
Application number
CN201610818126.9A
Other languages
Chinese (zh)
Other versions
CN107819556A (en
Inventor
张樱
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Beijing Kingsoft Cloud Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Beijing Kingsoft Cloud Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd, Beijing Kingsoft Cloud Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN201610818126.9A priority Critical patent/CN107819556B/en
Publication of CN107819556A publication Critical patent/CN107819556A/en
Application granted granted Critical
Publication of CN107819556B publication Critical patent/CN107819556B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/22Arrangements for detecting or preventing errors in the information received using redundant apparatus to increase reliability
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0663Performing the actions predefined by failover planning, e.g. switching to standby network elements

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Telephonic Communication Services (AREA)

Abstract

The embodiment of the invention discloses a service state switching method and a service state switching device, which are applied to equipment configured with target services. The method comprises the following steps: reading a first identifier and a first moment recorded in a target database; then judging whether the first identifier is the same as a second identifier of the target service; if the first time and the current time are the same, judging whether the time difference between the first time and the current time exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier. When the scheme is applied to switching the service state of the service, the Zookeeper does not need to be additionally deployed, and resources consumed by additionally deploying the Zookeeper are reduced.

Description

Service state switching method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for switching service states.
Background
Service (server), which refers to a physically present server from a hardware perspective; from the perspective of software, the software refers to computer software with a server-side function, a service is usually connected with a client (client), and the client obtains corresponding service content by accessing the service, such as accessing a database and the like; when a client acquires a certain service content, in order to prevent a service corresponding to the service content from failing or otherwise failing to provide the service content to the client, in the prior art, at least two services are usually set to provide the same service content, and the states of the services may be: the service in the active state is called a primary service (active server), and the service in the standby state is called a standby service (standby server).
When the client side obtains the service content, the main service provides the service content for the client side in real time, when the main service can not provide the service content continuously, the standby service switches the self state to the main state to become a new main service, and the new main service provides the corresponding service content for the user continuously, wherein the switching of the standby state and the main state is called main-standby switching.
In the prior art, a method for switching between a master and a slave is generally implemented by a ZooKeeper (a Distributed application program coordination service of a Distributed and open source code), such as HDFS (Hadoop Distributed File System), YARN (yeet other Resource coordinator) service; in the prior art, a znode is created on a ZooKeeper as a lock, a service acquiring the lock becomes a main service, and a service not acquiring the lock becomes a standby service. The primary service updates the znode node regularly, continues to hold the lock, and when the primary service fails and the ZooKeeper loses connection, the znode node is not updated any more, and then the standby service acquires the lock and automatically switches the service state of the standby service to become a new primary service.
In the prior art, the switching of the service state of the service needs to depend on the ZooKeeper deployed in advance, otherwise, the switching of the service state cannot be realized. Therefore, it is necessary to design a method for switching service states of a service without deploying ZooKeeper.
Disclosure of Invention
The embodiment of the invention discloses a service state switching method and device, which are used for realizing service state switching of services under the condition that ZooKeeper is not deployed. The technical scheme is as follows:
to achieve the above object, in a first aspect, an embodiment of the present invention provides a service state switching method, which is applied to a device configured with a target service, where the method includes:
reading a first identifier and a first moment recorded in a target database, wherein the first identifier is an identifier of a service in a main state, and the first moment is the starting moment of a current service cycle of the service in the main state;
judging whether the first identifier is the same as a second identifier of the target service or not;
if the first time and the current time are the same, judging that the service state of the target service is a main state, and judging whether the time difference between the first time and the current time exceeds a first preset time length; if so, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment;
if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, switching the service state of the target service to be the main state, updating the first moment to be the current moment, and updating the first identifier to be the second identifier, wherein the second preset duration is not less than the first preset duration.
Preferably, the service state switching method further includes:
judging whether the service state of the target service is a main state or not according to the locally recorded service state;
if so, judging whether the network connection between the target service and the target database is disconnected;
if the service is disconnected, comparing a second moment and a current moment of a local record, and if the time difference between the second moment and the current moment exceeds the first preset time length, switching the service state of the target service to a standby state, wherein the second moment is the initial moment of a current service period of the service in the main state;
if not, executing the first identification and the first moment recorded in the read target database;
when the determination result that whether the time difference between the first time and the current time exceeds a first preset time is no, or the determination result that whether the time difference between the first time and the current time exceeds a second preset time is yes, the service state switching method further includes:
and updating the second moment to be the current moment.
Preferably, the determining whether the service state of the target service is the active state according to the locally recorded service state includes:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
Preferably, the reading the first identifier and the first time recorded in the target database includes:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time period, and the second preset time period is not less than the sum of the first preset time period and the second time period.
Preferably, when the first identifier of the main service and the first time are not recorded in the target database, the service state switching method further includes:
taking the second identifier as the first identifier, taking the current moment as the first moment, and writing the current moment into the target database;
and switching the service state of the target service to be a main state.
Preferably, the first identifier and the second identifier each include: port information of the corresponding service and IP address information of the device.
In a second aspect, an embodiment of the present invention provides a service state switching apparatus, which is applied to a device configured with a target service, where the service state switching apparatus includes:
a reading module, configured to read a first identifier and a first time recorded in a target database, where the first identifier is an identifier of a service in a primary state, and the first time is a start time of a current service period of the service in the primary state;
the first judgment module is used for judging whether the first identifier is the same as a second identifier of the target service;
the first processing module is configured to, if the determination result of the first determining module is yes, determine that the service state of the target service is a main state, and determine whether a time difference between the first time and the current time exceeds a first preset time duration; if so, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment;
the second processing module is used for judging that the service state of the target service is a standby state under the condition that the judgment result of the first judging module is negative, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, switching the service state of the target service to be the main state, updating the first moment to be the current moment, and updating the first identifier to be the second identifier, wherein the second preset duration is not less than the first preset duration.
Preferably, the service state switching device further includes:
the second judgment module is used for judging whether the service state of the target service is a main state or not according to the locally recorded service state;
the third judging module is used for judging whether the network connection between the target service and the target database is disconnected or not under the condition that the judging result of the second judging module is yes; if not, triggering the reading module; if the service is disconnected, comparing a second moment and a current moment of a local record, and if the time difference between the second moment and the current moment exceeds the first preset time length, switching the service state of the target service to a standby state, wherein the second moment is the initial moment of a current service period of the service in the main state;
when the determination result that whether the time difference between the first time and the current time exceeds a first preset time is negative in the first processing module, or when the determination result that whether the time difference between the first time and the current time exceeds a second preset time is positive in the second processing module, the apparatus further includes:
and the updating module is used for updating the second moment to be the current moment.
Preferably, the second determining module is specifically configured to:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
Preferably, the reading module is specifically configured to:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time period, and the second preset time period is not less than the sum of the first preset time period and the second time period.
Preferably, when the first identifier of the main service and the first time are not recorded in the target database, the service state switching device further includes:
the writing module is used for writing the second identifier into the target database as the first identifier and the current time as the first time;
and the switching module is used for switching the service state of the target service to be a main state.
Preferably, the first identifier and the second identifier each include: port information of the corresponding service and IP address information of the device.
As can be seen from the above, in the scheme provided in the embodiment of the present invention, first identifiers and first time recorded in the target database are read; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator does not need to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced; moreover, the devices where the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that the two services aiming at the same service content can not be in the active state in the same time period, and meanwhile, the resources consumed by the communication connection are reduced.
Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a first flowchart illustrating a service status switching method according to an embodiment of the present invention;
fig. 2 is a second flowchart of a service status switching method according to an embodiment of the present invention;
fig. 3 is a schematic flowchart of a corresponding method for switching a service state by a target service when a first identifier and a first time of a current primary service are not recorded in a target database according to an embodiment of the present invention;
fig. 4 is a first structural diagram of a service status switching device according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a service status switching apparatus according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention will first be briefly described in the light of a comparison with the prior art.
In the prior art, in order to complete the switching of the service states of the services, one ZooKeeper is deployed in addition to two services configured for corresponding service contents, and two devices respectively corresponding to the two services herein need to be kept connected with the ZooKeeper, so as to ensure that the two services herein are connected with the network of the ZooKeeper.
As described above, in the prior art, by creating a znode node on the ZooKeeper as a lock, a service that acquires the lock becomes a primary service, and a service that does not acquire the lock becomes a backup service. The primary service updates the znode node regularly, continues to hold the lock, and when the primary service fails to be connected with the ZooKeeper due to a fault such as downtime, the znode node is not updated any more, and the standby service acquires the lock and automatically switches the service state of the standby service to become a new primary service.
As can be seen from the above, in the prior art, the switching of the service state of the service needs to depend on the ZooKeeper deployed in advance, otherwise, the switching of the service state cannot be realized, and the deployment of the extra ZooKeeper inevitably causes waste of resources.
When the scheme provided by the embodiment of the invention is applied, the first identification and the first moment recorded in the target database are read firstly; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator is not needed to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced.
The present invention will be described in detail with reference to specific examples.
The service state switching method provided by the embodiment of the invention is applied to equipment configured with target service. It should be noted that the target service may refer to software having a service function, and the device configured with the target service may be a server directly, and the server provides service content to the client.
It should be emphasized that the embodiment of the present invention is applied to a device provided with the target service, and two services, that is, two devices configured with the target service, are necessarily configured to configure the active/standby switching mode, where one of the two target services may be used as the main service and the other may be used as the standby service during the operation of the two target services.
Fig. 1 shows a first flowchart of a service state switching method according to an embodiment of the present invention, where the method includes:
s101: and reading the first identifier and the first time recorded in the target database. The first identifier is an identifier of a service in the active state, and the first time is a start time of a current service cycle of the service in the active state.
The target database stores records related to the first identifier and the first time, for example, a database table is created in the target database, and the name of the service content is used as a main key to record the first identifier and the first time in the database table. When the device accesses the target database, the device finds a corresponding database table based on the name of the service content, and further reads the first identifier and the first time.
In the embodiment of the invention, the first identifier corresponds to the service currently in the active state; the first time corresponds to a start time of a current service period of a current main service, and it should be noted that the start time of the service period of a certain main service includes: the corresponding time when the main service is switched from the standby state to the main state, and in addition, before a certain service period of the main service is ended, the corresponding time when the main service enters the next service period.
For example, when the device reads the target database, the first identifier recorded in the target database is X, the first time is 2016, 9, month, 1, day, 10, 20, 30 seconds, which indicates that the identifier corresponding to the master service at the current time is X, and the start time of the current service cycle of the master service is 2016, 9, month, 1, day, 10, 20, 30 seconds.
S102: and judging whether the first identifier is the same as the second identifier of the target service.
In the embodiment of the present invention, in order to ensure the uniqueness of the identifier, the first identifier and the second identifier may both include: it can be understood that, when the target service is software having a service end function, and the target service is started on the corresponding device, the target service occupies one port, and the port number may be the port information. For example, the IP address and the port number corresponding to a certain target service are respectively: 36.7.72.139, and 8888, the second identification information of the target service at this time may be "36.7.72.139: 8888".
If the first identifier is the same as the second identifier, S103 is executed: and judging whether the service state of the target service is a main state and whether the time difference between the first moment and the current moment exceeds a first preset time length.
In the embodiment of the present invention, when the first identifier is the same as the second identifier, it indicates that the target service is the main service, and when the target service and the database maintain normal communication connection, if the first identifier and the second identifier recorded in the database table in the target database are the same, and then after determining that the target service is the main service, it is directly determined whether the time difference between the first time and the current time exceeds a first preset duration.
It should be noted that, the first preset duration may correspond to a lease duration, and the service period of the main service may correspond to a lease, in this embodiment of the present invention, the lock function is implemented by the first identifier recorded in the target database, and the validity period corresponding to the lock is defined according to the lease.
For example, the first preset time is 1 minute, and the first time recorded in the target database at the current time is: 0 minute and 40 seconds at 1 hour, 8 months and 30 days in 2016, and if the current time is 1 minute and 45 seconds at 1 hour, 30 days in 8 months and 30 days in 2016, the time difference between the first time and the current time exceeds a first preset time length; in other words, if a lease of the main service is set to 0 minutes 40 seconds at 1 st of 2016 th 8 th 30 th 1 st of 2016 th, then the current lease is over if the current time is 1 minute 45 seconds at 1 st of 2016 th 8 th 30 th 1 st of 2016 th.
If the time difference between the first time and the current time exceeds a first preset time, executing S1031: and switching the service state of the target service to the standby state.
If the time difference between the first time and the current time does not exceed the first preset time, executing S1032: and updating the first time as the current time.
At this time, although the target service is the main service and the service cycle corresponding to the target service does not end, step S1032 may be performed so that the main service enters the next service cycle and the target service does not change its own service state. For example: the first time recorded in the target database is: 8, 10, 9, 1 minute and 25 seconds in 2014, the first preset time is 2 minutes, and the current time is as follows: if the time difference between the first time and the current time does not exceed 2 minutes in 2014, then only the first time in the target database needs to be updated to be: 8/10/9/2 min/25 s in 2014.
If the first identifier is not the same as the second identifier, executing S104: judging whether the service state of the target service is a standby state and judging whether the time difference between the first time and the current time exceeds a second preset time length; and the second preset time length is not less than the first preset time length.
Obviously, if the time difference between the first time and the current time does not exceed the second preset time, no operation is performed, and the service state of the target service is still kept in the standby state.
If the time difference between the first time and the current time exceeds a second preset time, executing S1041: and the service state of the switching target service is a main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
For example, the first time recorded in the target database is: 54 minutes 0 seconds at 2/10/2016, the first identification recorded is 36.7.72.148: 6666, the second preset time is 1 minute, and the current time is: a second identification of target service 36.7.72.139, 55 minutes 30 seconds at 2/10/2016: 8888, at this time, the time difference between the first time and the current time exceeds a second preset time, the target service first switches its own service state to the active state, and then updates the first time in the target database as: when 2016, 9, 10, 2, 55 minutes and 30 seconds, the first identifier is updated as follows: 36.7.72.139: 8888.
in addition, it should be noted that in the active-standby switching mode, two services corresponding to the same service content cannot be in the active state at the same time, so if the second preset time duration is shorter than the first preset time duration, it is likely that the current main service is still operating normally, and the standby service is switched to another main service.
For example, the first time recorded in the target database is: 24 minutes and 8 seconds at 8 months, 18 days and 8 days in 2015, wherein the first preset time period is 2 minutes, the second preset time period is 1 minute, and the current time is assumed as follows: 25 minutes and 38 seconds at 8, 18, 8 days in 2015, the main service x and the standby service y corresponding to the same service content at the current moment read the target database at the same time, and because the time difference between the first moment and the current moment does not exceed the first preset time for 2 minutes but exceeds the second preset time for 1 minute, the main service x only updates the first moment stored in the target database at the moment, the service state of the main service x is not changed, but the standby service y switches the service state of the standby service y to be the main state, and at the moment, the two services corresponding to the same service content are in the main state at the same time.
In this embodiment of the present invention, in order to ensure that the target service can switch its service state in time, the reading the first identifier and the first time recorded in the target database (S101) may include:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the second time period.
It can be understood that, if the current main service fails, the network connection with the target database is disconnected, and meanwhile, the service content cannot be continuously provided for the client, and the device where the target service serving as the standby service is located does not read the database in time, the target service cannot be timely switched to become a new main service, and the new main service provides the service content for the client.
However, if the device in which the target service is located is periodically performing the aforementioned step S101 for a second time period less than the first preset time period, the target service can be timely switched to be a new main service, and the new main service provides service content for the client.
For example: the first time recorded in the target database is 35 minutes and 20 seconds at 1 month, 18 months and 2 days in 2013, the first preset time duration is 2 minutes, and the main service is supposed to disconnect the network connection with the target database at 36 minutes and 30 seconds at 1 month, 18 months and 2 days in 2013, and meanwhile, the service content cannot be continuously provided for the client; however, the device serving as the target of the standby service executes step S101 only when the device is 0 min 30S at 1/18/3 in 2013, and successfully switches the target service to the primary service, and it can be understood that the client cannot acquire the service content during a period from 36 min 30S at 1/18/2 in 2013 to 0 min 30S at 1/18/3 in 2013.
However, if the device of the target service as the standby service periodically executes the step of S101 at a time interval of 1 minute, and the second preset time is 2 minutes and 5 seconds, similarly to the above example, it is assumed that the device executes the step of S101 at a time interval of 36 minutes and 20 seconds at 1 month, 18 days and 2 days of 2013, and at this time, since the time difference between the first time and the time does not exceed the second preset time, the target service is still the standby service, and after the time interval of 1 minute, the current time is 37 minutes and 20 seconds at 1 month, 18 days and 2 of 2013, and at this time, the time difference between the first time and the current time exceeds the second preset time, the target service switches to the new main service, and it can be understood that the client cannot acquire the service content only in a short time interval of 36 minutes and 30 seconds at 1 month, 18 days and 2 of 2013 to 37 minutes and 20 seconds at 1 month, 18 days and 2 of 2013.
On the other hand, if the main service does not have any failure, the network connection with the target database is normal, and the service content can be provided to the client normally, but since the first time in the target database is not updated in time, there is a possibility that: after a second preset time period from the first moment, the standby service is switched to the main service, so that the two services corresponding to the same service content are both in the main state.
For example, the first time recorded in the target database is 35 minutes and 20 seconds at 1 month and 18 months and 2 hours in 2013, the first preset time is 1 minute, the second preset time is 1 minute and 10 seconds, and it is assumed that the device where the main service is located does not always execute step S101 and then does not update the first time from 35 minutes and 20 seconds at 1 month and 18 months and 2 hours at 2 days at 18 months and 2 hours at 37 minutes and 00 seconds at 1 month and 18 days and 2 hours at 2013, and the main service can always provide service content to the service end; when the time difference between the first time and the current time exceeds a second preset time, the standby service is also switched to the main service, and at this time, two services corresponding to the same service content are both in a main state.
However, if the device of the target service as the main service periodically executes the step of S101 at a time interval of 40 seconds, that is, if the main service does not fail, the device of the main service will execute an operation of updating the first time to be the current time every 40 seconds, and it can be understood that in this case, it is ensured that the time difference between the first time and the corresponding current time does not exceed 40 seconds, that is, does not exceed 1 minute 10 seconds of the second preset time length, every time the device of the standby service reads the target database, so the standby service will not switch its own state to the active state.
In addition, it should be noted that even if the master service does not fail, the above-mentioned updating of the first time to the current time may be performed (S1032), but does not indicate that the master service may certainly successfully change the first time to the current time.
Assuming that the main service does not successfully execute the step S1032 within a first preset time period from a first time, the main service does not necessarily switch the service state of the main service to the standby state, and assuming that the main service executes the step S1032 at a corresponding third time period after the first preset time period from the first time, but the updating is not successful, the obvious main service does not switch the service state of the main service, at this time, the next time of executing the step S101 will be a fourth time period corresponding to a second preset period after the third time period, and the main service will switch the service state to the standby state at the fourth time, and if the standby service executes the switching of the service state to the main state between the third time period and the fourth time period, at this time, both services of the same service content are in the main state.
It can be said that the time period from the third time to the fourth time is a grace period, in which the system composed of the two services is in a jeopardy state, and in this time period, a phenomenon that both services are in the active state may occur.
Therefore, the second preset duration is not less than the sum of the first preset duration and the second time period, which is also to ensure that the phenomenon that two services corresponding to the same service content are both in the active state at the same time is avoided.
For example, the first time is 2015 year 9, 3 days 7, 10 minutes and 5 seconds, the first preset time period is 1 minute, and the second period is 20 seconds, assuming that the main service performs step S1032 from 2015 year 9, 3 days 7, 10 minutes and 5 seconds to 2015 year 9, 3 days 7, 11 minutes and 5 seconds, but the main service does not successfully complete the updating operation, and performs step S1032 at 2015 year 9, 3 days 7, 11 minutes and 5 seconds, but still does not successfully update, it is obvious that after 20 seconds, the main service performs the operation of switching the self state to the standby state, so the corresponding standby service should not perform the operation of switching the self state to the standby state within 20 seconds after the beginning of the main 2015 year 9 and 3 days 7, 11 minutes and 5 seconds, and therefore the second preset time period should not be less than the sum of the first preset time period and the second time period.
It should be noted that, when two services corresponding to the same service content are initially deployed, both services are in a standby state, and at the same time, the target database does not record the first identifier of the current primary service and the first time, as shown in fig. 3, where the method further includes:
s301: and taking the second identifier of the target service as the first identifier, taking the current time as the first time, and writing the current time into a target database.
When the first identifier and the first time are not recorded in the target database, a record about the first identifier and the first time needs to be written in the target database, and meanwhile, the second identifier is assigned to the first identifier, and the current time is assigned to the first time.
S302: and switching the service state of the target service to be the main state.
It can be understood that, in the embodiment of the present invention, when the first identifier and the first time are not recorded in the target database, two services that are in a standby state at the same time may first use the second identifier of the target service as the first identifier, and use the current time as the service written into the target database at the first time, so as to switch the service state of the two services to the active state.
As known to those skilled in the art, when a service is in a standby state, a corresponding port is closed, so when the main service switches its own state to the standby state, the port corresponding to the main service needs to be closed. It should be noted that, in the prior art, when a client accesses a main service based on a domain name, since the client does not have an IP address and port information of the main service, the client sends a request to the Zookeeper to obtain the current IP address and port information of the main service, and then accesses the main service to obtain corresponding service content.
In the embodiment of the present invention, when the client accesses the main service based on the domain name, the client broadcasts the domain name to the network, and the network searches for the corresponding IP address and port information based on the domain name, and since the port of the standby service is in a closed state, the network only feeds back the IP address and port information corresponding to the current main service to the client, so that the client accesses the main service based on the IP address and port information corresponding to the current main service.
It can be understood that the embodiment of the present invention utilizes a database lock mechanism, uses a database table as a lock to implement the switching of the service state of the target service, and implements the switching of the active/standby service by lease acquisition and update of the lock. As is well known to those skilled in the art, locking a database table using a SELECT FOR UPDATE (a manual locking statement) requires that transactions that operate on the same database table must wait until the COMMIT (release) of other transaction data is complete before execution.
The database table is a database table in which the first time and the first identifier are stored, and each lease is a time period corresponding to a first preset time length after the first time. The target database may be a common database, such as a mysql database.
For example, a database table is built in the database, and the specific structure of the database table is 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 the table, "service _ name" represents the name of the service content, the corresponding data type is "varchar (character type)", the maximum character length is 36 bytes, the name of the service content cannot be null, moreover, the name of the service content is the main key of the database table, and the default value corresponding to the name of the service content cannot be null; the "active _ server _ IP _ port" indicates the first identifier, and may be represented by an IP address and a port address of a host service in the embodiment of the present invention, where a data type corresponding to the first identifier is "varchar (character type)", a maximum character length is 36 bytes, the first identifier may be null, and a default value corresponding to the first identifier may be null; "last _ active _ time" indicates the first time, and the corresponding data type "datetime", the first time may be null, and the default value for the first time may be null.
In addition, in the active/standby switching mode, two services corresponding to the same service content are not allowed to be in the active state in the same time period. Therefore, the method comprises the following steps:
in the prior art, in order to prevent the original main service from being falsely dead, for example, the original main service is only in network connection with Zookeeper, but the original main service still can provide service content to the client, and at this time, the newly switched main service needs to perform an fencing operation on the original main service to ensure that the original main service does not provide service content any more, and only one main service exists in the two services. In order to ensure that at most only one main service exists in two services corresponding to the same service content, communication connection between devices where the two services are respectively located is required to ensure that the lancet operation can be realized.
In the embodiment of the present invention, the devices in which the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that it is ensured that the two services corresponding to the same service content are not in the active state in the same time period, and the resources consumed by the communication connection are reduced.
As can be seen from the above, in the scheme provided in the embodiment of the present invention, first identifiers and first time recorded in the target database are read; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator does not need to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced; moreover, the devices where the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that the two services aiming at the same service content can not be in the active state in the same time period, and meanwhile, the resources consumed by the communication connection are reduced.
With respect to fig. 1, a second flowchart of the service status switching method shown in fig. 2 further includes:
s201: and judging whether the service state of the target service is a main state or not according to the locally recorded service state.
It can be understood that, the device configured with the target service may easily know whether the current service is in the active state, for example, whether a port corresponding to the target service is in an open state, or whether the target service provides service content to the outside, and the device may determine whether the target service is in the active state based on the recorded information of the device itself by using the prior art, which is not described herein again in the embodiments of the present invention.
In this embodiment of the present invention, the determining whether the service state of the target service is the active state according to the locally recorded service state may be:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
It should be noted that the first time period herein has the same function as the second time period described above, and it is preferable that the first time period and the second time period are set to the same value.
In addition, the first time period and the second time period may be designed based on actual conditions, and the first time period and the second time period should be set as small as possible when the device performance allows.
If the determination result in S201 is no, execute S101: and reading the first identifier and the first time recorded in the target database.
If the determination result in S201 is yes, execute S202: and judging whether the network connection between the target service and the target database is disconnected.
If the network connection between the target service and the target database is disconnected, executing S203: and comparing the second time and the current time recorded locally, and switching the service state of the target service to a standby state if the time difference between the second time and the current time exceeds a first preset time. The second time is the starting time of the current service cycle of the service in the active state.
It should be distinguished that this second moment is recorded in the target service, i.e. in the device in which the target service is located; and the first time is recorded in the target database. In addition, it should be emphasized that, in all embodiments of the present invention, the first time and the second time may adopt timestamps, and the updating of the first time as the current time may be directly updating the corresponding timestamp.
Obviously, if the network connection between the target service as the master service and the target database is disconnected, step S101 cannot be successfully executed, and the operation of updating the first time cannot be necessarily executed, the target service is always in the master service state, and another service opposite to the target service is inevitably switched to the master service at a certain time, so that both services are in the master state.
However, in the embodiment of the present invention, the main service may be switched to the standby service through steps S201 to S203, so that the operations in steps S201 to S203 may avoid a phenomenon that both services are in the main state when the main service is disconnected from the target database network.
If the network connection between the target service and the target database is not disconnected, the reading of the first identifier and the first time recorded in the target database is performed (S101).
In order to ensure that the second time is updated in time, if the determination result of determining whether the time difference between the first time and the current time exceeds the first preset time is negative, or the determination result of determining whether the time difference between the first time and the current time exceeds the second preset time is positive, the method further includes:
s105: and updating the second time as the current time.
For example: the target service x is currently in a master state, the first time period and the second time period are both 1 minute, the first time is 2015 year 9, 3 days 7, 11 minutes and 5 seconds, obviously, the second time is 2015 year 9, 3 days 7, 11 minutes and 5 seconds, assuming that the first preset time is 2 minutes, if the target service x is disconnected from the network of the target database in 2015 year 9, 3 days 7, 11 minutes and 50 seconds, that is, the device where the target service x is located cannot read the target database; however, the device of the target service x may determine whether the time difference between the second time and the current time exceeds a first preset time, assuming that the device of the target service x performs the operations in 2015, 9, and 3 days 7, 13 minutes and 45 seconds: and judging whether the time difference between the second moment and the current moment exceeds a first preset time, wherein at the moment, the service state of the target service x is switched to a standby state because the time difference between the second moment and the current moment is judged to exceed the first preset time.
As can be seen from the above, in the scheme provided in the embodiment of the present invention, first identifiers and first time recorded in the target database are read; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator does not need to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced; moreover, the devices where the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that the two services aiming at the same service content can not be in the active state in the same time period, and meanwhile, the resources consumed by the communication connection are reduced.
The invention will be briefly described below by way of a specific example.
For a service content named "ABCDEFG", there are two services: x and y, the corresponding second identification of service x is 154.125.2.8: 7777, service y has a corresponding second identity of 154.125.2.136: 8888, the first time period and the second time period are both 30 seconds, the first preset time period is 1 minute, and the second preset time period is 1 minute and 30 seconds.
Initially, service x and y are both in standby state, and then service x establishes a primary key "ABCDEFG" database table in the target database, and identifies itself as 154.125.2.8: 7777 and current time 2015, 9, 30, 14, 1 min, 55 sec are written into the target database as the first identifier and first time, respectively, when service x becomes the primary service.
Assuming that the service x updates the first time to 20 minutes and 55 seconds at 14 hours and 20 minutes and 55 seconds at 9, 30 and 30 months in 2015, and then the first time cannot be successfully updated all the time, the service x reads the database again by 21 minutes and 55 seconds at 14 hours and 21 minutes and 55 seconds at 14 days and 30 months in 2015, such as 22 minutes and 05 seconds at 14 hours and 14 days and 30 months in 2015, and at this time, the service state of the service x is switched to the standby state because the time difference between the first time and the current time exceeds a first preset time.
Meanwhile, after 22 minutes and 25 seconds from 14 days of 9, 30 and 2015, for example, after 22 minutes and 30 seconds from 14 days of 9, 30 and 2015, service y finds a corresponding database table based on the name "ABCDEFG" of the service content, and then reads a first time and a first identifier in the database table, and because the time difference between the first time and the current time exceeds a second preset time, the service state of service y is switched to the master state.
It can be understood that when both services corresponding to the same service content are applied with the scheme provided by the present invention, the active/standby switching can be automatically realized.
Corresponding to fig. 1, as shown in fig. 4, a service state switching apparatus provided in an embodiment of the present invention is applied to a device configured with a target service, and the apparatus includes:
a reading module 110, configured to read a first identifier and a first time recorded in a target database, where the first identifier is an identifier of a service in a primary state, and the first time is a start time of a current service period of the service in the primary state;
a first determining module 120, configured to determine whether the first identifier is the same as the second identifier of the target service;
a first processing module 130, configured to, if a determination result of the first determining module is yes, determine that a service state of the target service is a primary state, and determine whether a time difference between the first time and the current time exceeds a first preset time duration; if so, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment;
a second processing module 140, configured to, if the determination result of the first determining module is negative, determine that the service state of the target service is a standby state, and determine whether a time difference between the first time and the current time exceeds a second preset time; if so, switching the service state of the target service to be the main state, updating the first moment to be the current moment, and updating the first identifier to be the second identifier, wherein the second preset duration is not less than the first preset duration.
In practical applications, specifically, the reading module 110 is specifically configured to:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time period, and the second preset time period is not less than the sum of the first preset time period and the second time period.
Specifically, the first identifier and the second identifier both include: IP address information and port information of the corresponding service's device.
In addition, it should be noted that, when the first identifier and the first time of the main service are not recorded in the target database, the apparatus further includes a writing module and a switching module (not shown in the figure):
the writing module is used for writing the second identifier into the target database as the first identifier and the current time as the first time;
and the switching module is used for switching the service state of the target service to be a main state.
As can be seen from the above, in the scheme provided in the embodiment of the present invention, first identifiers and first time recorded in the target database are read; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator does not need to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced; moreover, the devices where the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that the two services aiming at the same service content can not be in the active state in the same time period, and meanwhile, the resources consumed by the communication connection are reduced.
Corresponding to fig. 2, as shown in fig. 5, a service state switching apparatus provided in an embodiment of the present invention may further include:
the second determining module 210 is configured to determine whether the service state of the target service is the active state according to the locally recorded service state. If the determination result of the second determining module 210 is negative, the reading module 110 is directly triggered.
A third determining module 220, configured to determine whether the network connection between the target service and the target database is disconnected if the determination result of the second determining module 210 is yes; if not, triggering the reading module 110; if the service is disconnected, comparing a second moment and a current moment of a local record, and if the time difference between the second moment and the current moment exceeds the first preset time length, switching the service state of the target service to a standby state, wherein the second moment is the initial moment of a current service period of the service in the main state;
when the determination result that determines whether the time difference between the first time and the current time exceeds a first preset time is negative in the first processing module 130, or the determination result that determines whether the time difference between the first time and the current time exceeds a second preset time is positive in the second processing module 140, the apparatus further includes:
and the updating module 150 is configured to update the second time to be the current time.
Specifically, the second determining module 210 is specifically configured to:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
As can be seen from the above, in the scheme provided in the embodiment of the present invention, first identifiers and first time recorded in the target database are read; then judging whether the first identifier is the same as a second identifier of the target service; if the service state of the target service is the main state, judging whether the time difference between the first moment and the current moment exceeds a first preset time length; if yes, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment; if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, the service state of the switching target service is the main state, the first moment is updated to be the current moment, and the first identifier is updated to be the second identifier.
Compared with the prior art, in the scheme provided by the embodiment of the invention, two services corresponding to the same service content can compare the first identifier stored in the target database with the second identifier corresponding to the two services, so as to judge whether the target service is a main service or a standby service currently; when the target service is in a main state, if the time difference between the first moment and the current moment exceeds a first preset time length, the target service switches the self state to a standby state, and when the target service is in the standby state, if the time difference between the first moment and the current moment exceeds a second preset time length, the target service switches the self state to the main state; the switching of the service state of the target service can be carried out according to the corresponding record in the target database, and the Zookeeper does not need to be additionally deployed, so that a special administrator does not need to maintain the Zookeeper, and the resources consumed by additionally deploying the Zookeeper are reduced; moreover, the devices where the two services corresponding to the same service content are respectively located do not need to be in communication connection with each other, so that the two services aiming at the same service content can not be in the active state in the same time period, and meanwhile, the resources consumed by the communication connection are reduced.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Those skilled in the art will appreciate that all or part of the steps in the above method embodiments may be implemented by a program to instruct relevant hardware to perform the steps, and the program may be stored in a computer-readable storage medium, which is referred to herein as a storage medium, such as: ROM/RAM, magnetic disk, optical disk, etc.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (12)

1. A service state switching method is applied to a device configured with a target service, and is characterized by comprising the following steps:
reading a first identifier and a first moment recorded in a target database, wherein the first identifier is an identifier of a service in a main state, and the first moment is the starting moment of a current service cycle of the service in the main state;
judging whether the first identifier is the same as a second identifier of the target service or not;
if the first time and the current time are the same, judging that the service state of the target service is a main state, and judging whether the time difference between the first time and the current time exceeds a first preset time length; if so, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment;
if not, judging that the service state of the target service is a standby state, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, switching the service state of the target service to be the main state, updating the first moment to be the current moment, and updating the first identifier to be the second identifier, wherein the second preset duration is not less than the first preset duration.
2. The method of claim 1, further comprising:
judging whether the service state of the target service is a main state or not according to the locally recorded service state;
if so, judging whether the network connection between the target service and the target database is disconnected;
if the service is disconnected, comparing a second moment and a current moment of a local record, and if the time difference between the second moment and the current moment exceeds the first preset time length, switching the service state of the target service to a standby state, wherein the second moment is the initial moment of a current service period of the service in the main state;
if not, executing the first identification and the first moment recorded in the read target database;
when the judgment result of judging whether the time difference between the first time and the current time exceeds a first preset time length is no, or the judgment result of judging whether the time difference between the first time and the current time exceeds a second preset time length is yes, the method further comprises the following steps:
and updating the second moment to be the current moment.
3. The method of claim 2, wherein the determining whether the service state of the target service is the active state according to the locally recorded service state comprises:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
4. The method of claim 1, wherein reading the first identifier and the first time of day recorded in the target database comprises:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time period, and the second preset time period is not less than the sum of the first preset time period and the second time period.
5. The method of claim 1, wherein when the first identifier of the primary service and the first time are not recorded in the target database, the method further comprises:
taking the second identifier as the first identifier, taking the current moment as the first moment, and writing the current moment into the target database;
and switching the service state of the target service to be a main state.
6. The method according to any one of claims 1 to 5, wherein the first identifier and the second identifier each comprise: port information of the corresponding service and IP address information of the device.
7. A service state switching apparatus applied to a device configured with a target service, the apparatus comprising:
a reading module, configured to read a first identifier and a first time recorded in a target database, where the first identifier is an identifier of a service in a primary state, and the first time is a start time of a current service period of the service in the primary state;
the first judgment module is used for judging whether the first identifier is the same as a second identifier of the target service;
the first processing module is configured to, if the determination result of the first determining module is yes, determine that the service state of the target service is a main state, and determine whether a time difference between the first time and the current time exceeds a first preset time duration; if so, switching the service state of the target service to a standby state; if not, updating the first moment to be the current moment;
the second processing module is used for judging that the service state of the target service is a standby state under the condition that the judgment result of the first judging module is negative, and judging whether the time difference between the first time and the current time exceeds a second preset time length; if so, switching the service state of the target service to be the main state, updating the first moment to be the current moment, and updating the first identifier to be the second identifier, wherein the second preset duration is not less than the first preset duration.
8. The apparatus of claim 7, further comprising:
the second judgment module is used for judging whether the service state of the target service is a main state or not according to the locally recorded service state;
the third judging module is used for judging whether the network connection between the target service and the target database is disconnected or not under the condition that the judging result of the second judging module is yes; if not, triggering the reading module; if the service is disconnected, comparing a second moment and a current moment of a local record, and if the time difference between the second moment and the current moment exceeds the first preset time length, switching the service state of the target service to a standby state, wherein the second moment is the initial moment of a current service period of the service in the main state;
when the determination result that whether the time difference between the first time and the current time exceeds a first preset time is negative in the first processing module, or when the determination result that whether the time difference between the first time and the current time exceeds a second preset time is positive in the second processing module, the apparatus further includes:
and the updating module is used for updating the second moment to be the current moment.
9. The apparatus of claim 8, wherein the second determining module is specifically configured to:
periodically judging whether the service state of the target service is a main state or not according to a preset first time period and the locally recorded service state; the first time period is less than the first preset time, and the second preset time is not less than the sum of the first preset time and the first time period.
10. The apparatus according to claim 7, wherein the reading module is specifically configured to:
and periodically reading the first identifier and the first moment recorded in the target database based on a preset second time period, wherein the second time period is less than the first preset time period, and the second preset time period is not less than the sum of the first preset time period and the second time period.
11. The apparatus of claim 7, wherein when the first identifier of the primary service and the first time are not recorded in the target database, the apparatus further comprises:
the writing module is used for writing the second identifier into the target database as the first identifier and the current time as the first time;
and the switching module is used for switching the service state of the target service to be a main state.
12. The apparatus according to any one of claims 7 to 11, wherein the first mark and the second mark each comprise: port information of the corresponding service and IP address information of the device.
CN201610818126.9A 2016-09-12 2016-09-12 Service state switching method and device Active CN107819556B (en)

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 CN107819556A (en) 2018-03-20
CN107819556B true 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)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111464580B (en) * 2019-01-22 2022-04-22 阿里巴巴集团控股有限公司 Method and device for selecting main server
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
CN113467953B (en) * 2021-07-16 2023-08-04 腾讯科技(深圳)有限公司 Service state switching method and device, server and storage medium
CN114328034B (en) * 2022-03-15 2022-06-03 苏州浪潮智能科技有限公司 Control method and device of storage equipment, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
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

Patent Citations (6)

* Cited by examiner, † Cited by third party
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

Also Published As

Publication number Publication date
CN107819556A (en) 2018-03-20

Similar Documents

Publication Publication Date Title
CN107819556B (en) Service state switching method and device
WO2017140131A1 (en) Data writing and reading method and apparatus, and cloud storage system
US7197632B2 (en) Storage system and cluster maintenance
CN108228814B (en) Data synchronization method and device
US9146839B2 (en) Method for pre-testing software compatibility and system thereof
US9753954B2 (en) Data node fencing in a distributed file system
US20180307569A1 (en) Data retracement method, apparatus, and system
CN112463448B (en) Distributed cluster database synchronization method, device, equipment and storage medium
CN109361525B (en) Method, device, control terminal and medium for restarting distributed deployment of multiple services
CN107870982B (en) Data processing method, system and computer readable storage medium
CN111045745A (en) Method and system for managing configuration information
CN110597918A (en) Account management method and device and computer readable storage medium
WO2017028375A1 (en) Version upgrading method and system
CN102937955A (en) Main memory database achieving method based on My structured query language (SQL) double storage engines
CN110677280A (en) Service node switching method, device, equipment and computer readable storage medium
CN112865992A (en) Method and device for switching master nodes in distributed master-slave system and computer equipment
CN112860386A (en) Method for switching nodes in distributed master-slave system
CN106533751B (en) SDN controller cluster merging method and device
CN110635941A (en) Database node cluster fault migration method and device
CN112860787A (en) Method for switching master nodes in distributed master-slave system, master node device and storage medium
US20120324279A1 (en) Method and Apparatus of Backing up Subversion Repository
EP2416526B1 (en) Task switching method, server node and cluster system
CN110737670A (en) cluster data consistency guarantee method, device and system
CN107463390B (en) Software upgrading method and upgrading server
CN107786650B (en) Storage medium and management strategy synchronization method, device and system

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