MASTER-SLAVE SERVER SWITCHING METHOD, APPARATUS AND STORAGE MEDIUM
The present disclosure relates to the field of data processing technology, in particular to a method and an apparatus for a primary-backup server switching and a storage medium. In a distributed storage system, in order to ensure that services can be quickly restored after a server failure, a backup server may be set up in the system. Once a primary server fails, the backup server may be switched to be as a primary server to continue to provide services. Specifically, as shown in Stateful service is a commonly used service method. After receiving a request from a client, a server may determine how to respond to the request based on its current working state. In the distributed storage system with stateful service, the control server 130 monitors whether the primary server 110 fails, and in response to a failure of the primary server 110, the backup server 120 must be quickly restored to a state of the primary server 110 before the primary server 110 fails, so as to provide services. Therefore, the backup server 120 may perform the same operations as the primary server 110 in real time. For example, taking the operation of creating a file as an example, the primary server 110 receives an operation request for creating the file, and stores an operation record of the operation into a log after executing the operation of creating the file; and then, the log is read and asynchronously transmitted to the backup server 120, and the backup server 120 performs the same operation of creating a file to reach the same state as the primary server 110. However, due to the limitation of the memory capacity, the Least Recently Used (LRU) algorithm of a virtual page storage management service adopted by the primary server 110 may store some logs in the memory or a hard disk, which results in a time-consuming process of reading operation records therefrom. When the primary server 110 fails, there may be a case where the operation records cannot be transmitted to the backup server 120 in time, which results in that the backup server 120 is not able to perform the same operation and cannot maintain the same state of the original primary server 110 before the failure of the original primary server 110 after the backup server 120 is switched to be as a primary server. In order to overcome problems in the related art, the present disclosure provides a method for primary-backup server switching, an apparatus and a storage medium. The invention is set out in the appended set of claims 1-9. The technical solution provided by the embodiments of the present disclosure can include the following beneficial effects: whether the primary server fails is monitored, wherein the primary server is provided with the primary memory database, and the primary memory database is configured to save in real time the state information of the primary server each time after the operation is executed by the primary serve so that the state information can be read and saved in real time by the backup memory database disposed in the backup server; and if it is determined that the primary server fails, the primary-backup switching command will be sent to the backup server so that the backup server can be upgraded as the new primary server according to the state information saved in the backup memory database. Since the state information of the primary server is written into the primary memory database in real time, and the backup memory database in the backup server reads the state information from the primary memory database in real time, when the primary server fails, the backup server can quickly keep the state consistent with the state of the primary server before the failure, which effectively solves the problem that it takes a long time for the primary server to read operation records from a memory or a hard disk. It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. Accompanying drawings here, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain principles of the present disclosure.
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numerals in different drawings indicate the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the present disclosure as detailed in the appended claims. In S201, whether the primary server fails is monitored. The primary server is provided with a primary memory database. The primary memory database is configured to save in real time state information of the primary server each time after an operation is executed by the primary server. The state information is read and saved in real time by a backup memory database disposed in the backup server. In embodiments of the present disclosure, the operations executed by the primary server may include file editing operations such as file creation and file deletion. The state information includes a result of each operation executed by the primary server. A failure of the primary server may include crash of the primary server caused by various reasons. As shown in In S202, in response to a failure of the primary server, a primary-backup switching command is sent to the backup server. The primary-backup switching command is configured to instruct the backup server to be upgraded as a new primary server according to the state information saved in the backup memory database. In some embodiments, since the state information in the primary memory database 320 is read and saved in real time by the backup memory database 340, when receiving the primary-backup switching command sent by the control server 350 after the control server 350 monitors out the failure of the primary server 310, the backup server may change its own role from the original backup server to a primary server, that is, upgrading to be as the new primary server based on the saved state information, and continues to provide services. The technical solution provided by the embodiment of the present disclosure can include the following beneficial effects: whether the primary server fails is monitored, wherein the primary server is provided with the primary memory database, and the primary memory database is configured to save in real time the state information of the primary server each time after the operation is executed by the primary server so that the state information can be read and saved in real time by the backup memory database disposed in the backup server; and if it is determined that the primary server fails, the primary-backup switching command will be sent to the backup server so that the backup server can be upgraded as the new primary server according to the state information saved in the backup memory database. Since the state information of the primary server is written into the primary memory database in real time, and the backup memory database in the backup server reads the state information from the primary memory database in real time, when the primary server fails, the backup server can quickly keep the state consistent with the state of the primary server before the failure, which effectively solves the problem that it takes a long time for the primary server to read operation records from a memory or a hard disk. In S401, a heartbeat packet is sent to the primary server every a first time period. In embodiments of the present disclosure, when a processed service has a high requirement for real-time performance or when the primary server needs to be monitored in real time as much as possible, the first time period may be set to be shorter, for example, the heartbeat packet is sent to the primary server every 20 seconds. On the contrary, when the requirement of the service for the real-time performance is not high, or when the primary server does not need to be monitored in real time, the first time period may be set to be longer. In S402, whether a response to the heartbeat packet is received within a second time period is determined. If so, it is determined that the primary server is normal, and S401 is executed again. Otherwise, it is determined that the primary server fails, and S403 is executed. In some embodiments, the second time period may also be set according to specific conditions. If the control server does not receive the response of the primary server to the heartbeat packet within the second time period, the primary server is determined to fail. It can be understood that a server failure may result in service interruption, which in turn may have a significant impact on user usage. In embodiments of the present disclosure, the control server monitors a state of the primary server by sending the heartbeat packets regularly, and can know whether the primary server fails in time, and determine its availability. In S403, a primary-backup switching command is sent to the backup server. The primary-backup switching command is configured to instruct the backup server to be upgraded as a new primary server according to state information saved in the backup memory database. In S404, the backup memory database in the backup server is switched to be as a new primary memory database. In some embodiments of the present disclosure, there may be one or more backup servers. When there are multiple backup servers, each backup server contains a backup memory database storing state information. Similar to S201 in the embodiment shown in It can be seen from the embodiment shown in The monitoring module 510 is configured to monitor whether a primary server fails. The primary server is provided with a primary memory database. The primary memory database is configured to save in real time state information of the primary server each time after an operation is executed by the primary server. The state information is read and saved in real time by a backup memory database disposed in a backup server. The server switching module 520 is configured to send a primary-backup switching command to the backup server in response to a failure of the primary server. The primary-backup switching command is configured to instruct the backup server to be upgraded as a new primary server according to the state information saved in the backup memory database. The technical solution provided by the embodiment of the present disclosure can include the following beneficial effects: whether the primary server fails is monitored, wherein the primary server is provided with the primary memory database, and the primary memory database is configured to save in real time the state information of the primary server each time after the operation is executed by the primary server so that the state information can be read and saved in real time by the backup memory database disposed in the backup server; and if it is determined that the primary server fails, the primary-backup switching command will be sent to the backup server so that the backup server can be upgraded as the new primary server according to the state information saved in the backup memory database. Since the state information of the primary server is written into the primary memory database in real time, and the backup memory database in the backup server reads the state information from the primary memory database in real time, when the primary server fails, the backup server can quickly keep the state consistent with the state of the primary server before the failure, which effectively solves the problem that it takes a long time for the backup server to read operation records from a memory or a hard disk. With regard to the apparatus in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment of the method, and will not be described in detail here. The primary memory database and the backup memory database are Redis memory databases. The apparatus further includes a database switching module 530. The database switching module 530 is configured to switch the backup memory database in the backup server to be as a new primary memory database after the server switching module sends the primary-backup switching command to the backup server in response to the failure of the primary server. In some embodiments, there are a plurality of backup servers, each of the plurality of backup servers includes a backup memory database configured to store the state information. The state information is read in real time from the primary memory database by the backup memory database in each of the plurality of backup servers. The server switching module 520 may include a selecting unit and a command sending unit. The selecting unit is configured to select one backup server from the plurality of backup servers as a target backup server. The command sending unit is configured to send the primary-backup switching command to the target backup server. The primary-backup switching command is configured to instruct the target backup server to be upgraded as a new primary server according to the state information saved in the backup memory database. In some embodiments of the present disclosure, the server switching module 520 further includes a switching unit. The switching unit is configured to switch the backup memory database in the target backup server to be as a new primary memory database after the command sending unit sends the primary-salve switching command to the target backup server. In some embodiments of the present disclosure, the monitoring module 510 may include a heartbeat sending unit and a determining unit. The heartbeat sending unit is configured to send a heartbeat packet to the primary server every first time period. The determining unit is configured to determine whether a response to the heartbeat packet is received within a second time period. If so, the primary server does not fail, otherwise, the primary server fails. Referring to The processing component 602 generally controls the overall operations of the apparatus 600, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 620 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 602 may include one or more modules to facilitate the interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate the interaction between the multimedia component 608 and the processing component 602. The memory 604 is configured to store various types of data to support the operations of the apparatus 600. Examples of such data include instructions for any application or method operating on the apparatus 600, contact data, phone book data, messages, pictures, videos, etc. The memory 604 may be implemented by any type of volatile or non-volatile storage device or their combination, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk. The power component 606 provides power for various components of the apparatus 600. The power component 606 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the apparatus 600. The multimedia component 608 includes a screen that provides an output interface between the apparatus 600 and a user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes the touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, swiping, and gestures on the touch panel. The touch sensor may not only sense the boundary of the touch or swiping action, but also detect the duration and pressure related to the touch or swiping operation. In some embodiments, the multimedia component 608 includes a front camera and/or a rear camera. When the apparatus 600 is in an operation mode, for example, a shooting mode or a video mode, the front camera and/or the rear camera may receive external multimedia data. Each of the front camera and the rear camera may be a fixed optical lens system or has a focal length and optical zoom capabilities. The audio component 610 is configured to output and/or input audio signals. For example, the audio component 610 includes a microphone (MIC), and when the apparatus 600 is in an operation mode, for example, a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive external audio signals. The received audio signals may be further stored in the memory 604 or transmitted via the communication component 616. In some embodiments, the audio component 610 further includes a loudspeaker configured to output audio signals. The I/O interface 612 provides an interface between the processing component 602 and a peripheral interface module. The peripheral interface module may be a keyboard, a click wheel, buttons, and the like. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button. The sensor component 614 includes one or more sensors configured to provide the apparatus 600 with various aspects of state assessment. For example, the sensor component 614 may detect the on/off state of the apparatus 600, and the relative positioning of components, such as a display and a keypad of the apparatus 600. The sensor component 614 may also detect the position change of the apparatus 600 or a component of the apparatus 600, the presence or absence of contact between the user and the apparatus 600, the orientation or acceleration/deceleration of the apparatus 600, and the temperature change of the apparatus 600. The sensor component 614 may include a proximity sensor configured to detect the presence of nearby objects when there is no physical contact. The sensor component 614 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor component 614 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor. The communication component 616 is configured to facilitate wired or wireless communications between the apparatus 600 and other devices. The apparatus 600 may access a wireless network based on a communication standard, such as WiFi, a service provider's network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 616 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 616 further includes a near field communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on a radio frequency identification (RFID) technology, an infrared data association (IrDA) technology, an ultra-wideband (UWB) technology, a Bluetooth (BT) technology and other technologies. In an exemplary embodiment, the apparatus 600 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to execute the above primary-backup server switching method. In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is further provided, such as the memory 604 including the instructions, and the above instructions may be executed by the processor 620 of the apparatus 600 to complete the above method. For example, the non-transitory computer-readable storage medium may be an ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc. The apparatus 700 may also include a power component 726 configured to perform power management of the apparatus 700, a wired or wireless network interface 750 configured to connect the apparatus 700 to a network, and an input/output (I/O) interface 758. The apparatus 700 may operate an operating system stored in the memory 732, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM or the similar. As shown in The processor 801 is configured to:
In some embodiments, the primary memory database and the backup memory database are Redis memory databases. In some embodiments, the processor 801 is further configured to switch the backup memory database in the backup server to be as a new primary memory database after the primary-backup switching command is sent to the backup server in response to the failure of the primary server. In some embodiments, there are a plurality of backup servers, each of the plurality of backup servers includes a backup memory database configured to store the state information. The state information is read in real time from the primary memory database by the backup memory database in each of the plurality of backup servers. The processor 801 is further configured to:
In some embodiments, the processor 801 is further configured to switch the backup memory database in the target backup server to be as a new primary memory database after the primary-backup switching command is sent to the target backup server when there are the plurality of backup servers. In some embodiments, the processor 801 is further configured to:
Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure following the general principles of the present disclosure and including common general knowledge or customary technical means in the art not disclosed herein. It is intended that the specification and embodiments be considered as exemplary only, with a true scope of the present disclosure being indicated by the following claims. A method for primary-backup server switching, applied to a control server in communication connection with a primary server and a backup server, and comprising:
monitoring (S201) whether the primary server fails, wherein the primary server is provided with a primary memory database, the primary memory database is configured to save in real time state information of the primary server each time after an operation is executed by the primary server, and the state information is configured to be read and saved in real time by a backup memory database disposed in the backup server; wherein the primary memory database and the backup memory database are Redis memory databases, and the state information of the primary server is read from the primary memory database in real time by the backup memory database and is saved in the backup memory database in a same key-value form as the primary memory database; and sending (S202) a primary-backup switching command to the backup server in response to a failure of the primary server, wherein the primary-backup switching command is configured to instruct the backup server to be upgraded as a new primary server according to the state information saved in the backup memory database. The method for primary-backup server switching according to claim 1, wherein after said sending (S202) the primary-backup switching command to the backup server in response to the failure of the primary server, the method further comprises: The method for primary-backup server switching according to claim 1, wherein there are a plurality of backup servers, each of the plurality of backup servers comprises a backup memory database configured to store the state information, the state information is read in real time from the primary memory database by the backup memory database in each of the plurality of backup servers; and selecting one backup server from the plurality of backup servers as a target backup server; and sending the primary-backup switching command to the target backup server, wherein the primary-backup switching command is configured to instruct the target backup server to be upgraded as a new primary server according to the state information saved in the backup memory database of the target backup server. The method for primary-backup server switching according to any of claims 1-3, wherein said monitoring (S201) whether the primary server fails comprises:
sending (S401) a heartbeat packet to the primary server every first time period; and determining (S402) whether a response to the heartbeat packet is received within a second time period, and if so, the primary server does not fail, otherwise, the primary server fails. An apparatus for primary-backup server switching, applied to a control server in communication connection with a primary server and a backup server, and comprising:
a monitoring module (510), configured to monitor whether the primary server fails, wherein the primary server is provided with a primary memory database, the primary memory database is configured to save in real time state information of the primary server each time after an operation is executed by the primary server, and the state information is configured to be read and saved in real time by a backup memory database disposed in the backup server; wherein the primary memory database and the backup memory database are Redis memory databases, and the state information of the primary server is read from the primary memory database in real time by the backup memory database and is saved in the backup memory database in a same key-value form as the primary memory database; and a server switching module (520), configured to send a primary-backup switching command to the backup server in response to a failure of the primary server, wherein the primary-backup switching command is configured to instruct the backup server to be upgraded as a new primary server according to the state information saved in the backup memory database. The apparatus for primary-backup server switching according to claim 5, further comprising: The apparatus for primary-backup server switching according to claim 5, wherein there are a plurality of backup servers, each of the plurality of backup servers comprises a backup memory database configured to store the state information, the state information is read in real time from the primary memory database by the backup memory database in each of the plurality of backup servers; and a selecting unit, configured to select one backup server from the plurality of backup servers as a target backup server; and a command sending unit, configured to send the primary-backup switching command to the target backup server, wherein the primary-backup switching command is configured to instruct the target backup server to be upgraded as a new primary server according to the state information saved in the backup memory database of the target backup server. The apparatus for primary-backup server switching according to any of claims 5-7, wherein the monitoring module (510) comprises:
a heartbeat sending unit, configured to send a heartbeat packet to the primary server every first time period; and a determining unit, configured to determine whether a response to the heartbeat packet is received within a second time period, and if so, the primary server does not fail, otherwise, the primary server fails. A non-transitory computer-readable storage medium, wherein instructions in the non-transitory computer-readable storage medium are configured to cause an electronic device to implement the method according to any of claims 1-4 when the instructions are executed by a processor of the electronic device.Field
Background
The patent
The patent Summary
Brief Description of the Drawings
Detailed Description of the Embodiments
switching the backup memory database in the backup server to be as a new primary memory database.
said sending (S202) the primary-backup switching command to the backup server in response to the failure of the primary server comprises:
a database switching module (530), configured to switch the backup memory database in the backup server to be as a new primary memory database after the server switching module (520) sends the primary-backup switching command to the backup server in response to the failure of the primary server.
the server switching module (520) comprises:
![](/ipEP3937426B1/0.png)
![](/ipEP3937426B1/1.png)
![](/ipEP3937426B1/2.png)
![](/ipEP3937426B1/3.png)
CPC - классификация
GG0G06G06FG06F1G06F11G06F11/G06F11/1G06F11/14G06F11/145G06F11/1451G06F11/2G06F11/20G06F11/202G06F11/2028G06F11/203G06F11/2038G06F11/204G06F11/2048G06F11/209G06F11/2097G06F2G06F22G06F220G06F2201G06F2201/G06F2201/8G06F2201/80G06F2201/805HH0H04H04LH04L4H04L41H04L41/H04L41/0H04L41/06H04L41/066H04L41/0663H04L41/08H04L41/084H04L41/0846H04L6H04L67H04L67/H04L67/1H04L67/10H04L67/109H04L67/1097H04L69H04L69/H04L69/4H04L69/40IPC - классификация
GG0G06G06FG06F1G06F11G06F11/G06F11/1G06F11/14G06F11/2G06F11/20HH0H04H04LH04L4H04L41H04L41/H04L41/0H04L41/06H04L41/066H04L41/0663H04L41/08H04L41/084H04L6H04L65H04L65/H04L65/4H04L65/40H04L67H04L67/H04L67/1H04L67/10H04L67/109H04L67/1097H04L69H04L69/H04L69/4H04L69/40Цитирование НПИ
US-A1- 2004 193 625US-A1- 2016 132 411