A service providing method and apparatus, a server, and a storage medium
By storing instance information in storage devices and using creation time and active time to determine and confirm primary instance anomalies, the problem of coordinating multi-server business services is solved, enabling fast and accurate primary instance switching and ensuring business continuity.
Patent Information
- Application Number
- CN202111400950.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2041-11-19
AI Technical Summary
There is a lack of effective coordination mechanisms in existing technologies to reasonably coordinate multiple servers to provide business services and avoid business interruptions due to server crashes or instance restarts.
By storing information about each instance in the storage device, the system uses the instance creation time and last active time to determine if the primary instance is abnormal. If an abnormality occurs, a new primary instance is selected to provide business services. The system also uses heartbeat requests to confirm the abnormality, thus avoiding time inconsistencies and the thundering herd effect.
It enables rapid switching of the primary instance without the need for external devices when the primary instance fails, reducing business interruption time and improving the accuracy of exception detection and the continuity of business services.
Smart Images

Figure CN113918390B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of Internet, and particularly relates to a business service providing method and device, a server and a storage medium. BACKGROUND
[0002] In the technical field of Internet, there are often some businesses that need to be continuously run. Generally, a server provides business services through a locally started instance. In order to avoid interrupting the business due to server downtime or instance restart, multiple servers need to be used as backup, and only one server is allowed to run at the same time and other servers are on standby. How to reasonably coordinate multiple servers to provide business services is a problem to be solved. SUMMARY
[0003] The present disclosure provides a business service providing method, device, server and storage medium, which are used to provide a scheme for reasonably coordinating multiple servers to provide business services. The technical scheme of the present disclosure is as follows:
[0004] According to a first aspect of an embodiment of the present disclosure, a business service providing method is provided, which is applied to a business system, the business system includes a storage device and at least two servers, each server starts an instance, the storage device stores instance information of each instance, and the method includes:
[0005] obtaining instance information of each instance from the storage device;
[0006] determining whether a master instance is abnormal according to the instance information of each instance;
[0007] when it is determined that the master instance is abnormal, reselecting a master instance to make the reselected master instance provide business services.
[0008] In some embodiments, the instance information of each instance includes a creation time and a last active time, and determining whether the master instance is abnormal according to the instance information of each instance includes:
[0009] determining whether the locally started instance is the master instance based on the creation time of each instance and the creation time characteristics of the master instance;
[0010] if it is determined that the locally started instance is not the master instance, analyzing whether the master instance is abnormal based on the last active time of the master instance.
[0011] In some embodiments, the business system includes at least three servers, and before analyzing whether the master instance is abnormal based on the last active time of the master instance, the method further includes:
[0012] determining that the creation time of the locally started instance meets the creation time characteristics of the analysis instance.
[0013] In some embodiments, based on the last active time of the master instance, analyzing whether the master instance is abnormal, comprises:
[0014] determining a time difference between a current time and the last active time of the master instance;
[0015] if the time difference is greater than a preset time length, determining that the master instance is abnormal.
[0016] In some embodiments, after determining that the time difference is greater than the preset time length, further comprising:
[0017] waiting for a preset time length;
[0018] obtaining the last active time of the master instance from the storage device;
[0019] if the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, determining that the master instance is abnormal.
[0020] In some embodiments, the storage device also stores communication address information of each instance, and after determining that the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, further comprising:
[0021] based on the communication address information of the master instance obtained from the storage device, sending a heartbeat request to the master instance;
[0022] if the master instance does not respond to the heartbeat request, determining that the master instance is abnormal.
[0023] In some embodiments, when determining that the master instance is abnormal, further comprising:
[0024] deleting the instance information of the master instance from the storage device.
[0025] In some embodiments, further comprising:
[0026] if it is determined that the locally started instance is a master instance, providing a service based on the master instance.
[0027] In some embodiments, further comprising:
[0028] when it is determined that the instance exit condition is met, exiting the locally running instance, and deleting the instance information of the instance from the storage device.
[0029] According to a second aspect of the embodiments of the present disclosure, a service providing apparatus is provided, which is applied to a service system, the service system comprising a storage device and at least two servers, each server having an instance started therein, and the storage device storing instance information of the instance, the apparatus being applied to any server and comprising:
[0030] an obtaining unit configured to obtain the instance information of each instance from the storage device;
[0031] a determining unit configured to determine whether the master instance is abnormal according to the instance information of each instance;
[0032] a reselecting unit configured to reselect a master instance to provide service when it is determined that the master instance is abnormal.
[0033] In some embodiments, the instance information of each instance comprises a creation time and a last active time, and the determining unit is specifically configured to:
[0034] determine whether the locally started instance is the master instance based on the creation time of each instance and the creation time feature of the master instance;
[0035] if it is determined that the locally started instance is not the master instance, analyze whether the master instance is abnormal based on the last active time of the master instance.
[0036] In some embodiments, the service system comprises at least three servers, and the determining unit is further configured to:
[0037] determine that the creation time of the locally started instance meets the creation time feature of the analysis instance before analyzing whether the master instance is abnormal based on the last active time of the master instance.
[0038] In some embodiments, the determining unit is specifically configured to:
[0039] determine a time difference between a current time and the last active time of the master instance;
[0040] if the time difference is greater than a preset time length, determine that the master instance is abnormal.
[0041] In some embodiments, the determining unit is further configured to:
[0042] wait for a preset time length after determining that the time difference is greater than the preset time length;
[0043] obtain the last active time of the master instance from the storage device;
[0044] If the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, it is determined that the master instance is abnormal.
[0045] In some embodiments, the storage device also stores communication address information of each instance, and the determining unit is further configured to perform:
[0046] After determining that the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, a heartbeat request is sent to the master instance based on the communication address information of the master instance obtained from the storage device.
[0047] If the master instance does not respond to the heartbeat request, it is determined that the master instance is abnormal.
[0048] In some embodiments, further comprising:
[0049] A deleting unit configured to perform deleting, from the storage device, instance information of the master instance when it is determined that the master instance is abnormal.
[0050] In some embodiments, further comprising:
[0051] A service unit configured to perform providing a service based on the master instance if it is determined that the locally started instance is the master instance.
[0052] In some embodiments, further comprising:
[0053] A quitting unit configured to perform quitting the locally running instance and deleting, from the storage device, instance information of the instance when it is determined that an instance quitting condition is met.
[0054] According to a third aspect of embodiments of the present disclosure, a server is provided, comprising:
[0055] a processor;
[0056] a memory for storing instructions executable by the processor;
[0057] The processor is configured to execute the instructions to implement any of the above service providing methods.
[0058] According to a fourth aspect of embodiments of the present disclosure, a storage medium is provided, when instructions in the storage medium are executed by a processor of a server, the server is enabled to perform any of the above service providing methods.
[0059] According to a fifth aspect of embodiments of the present disclosure, a computer program product is provided, when the computer program product is invoked and executed by a server, the server performs any of the above service providing methods.
[0060] The technical solutions provided by the embodiments of the present disclosure bring at least the following beneficial effects:
[0061] The business system comprises a storage device and at least two servers, an instance is started in each server, and instance information of the instance is stored in the storage device. Any server can obtain the instance information of each instance from the storage device, determine whether the master instance is abnormal according to the instance information of each instance, and when it is determined that the master instance is abnormal, reselect a master instance, so that the reselected master instance provides a business service. In this way, the activity of the master instance can be monitored, and the master instance can be reselected to provide a business service when the master instance is abnormal, so that the instances in the multiple servers can continuously provide a business service without relying on external devices.
[0062] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0063] The accompanying drawings incorporated in the specification and forming a part of it illustrate embodiments consistent with the present disclosure and together with the description serve to explain the principles of the present disclosure, and are not intended to limit the present disclosure.
[0064] Figure 1 is an architecture schematic diagram of a business service system according to an exemplary embodiment.
[0065] Figure 2 is a flowchart of a business service providing method according to an exemplary embodiment.
[0066] Figure 3 is a flowchart of another business service providing method according to an exemplary embodiment.
[0067] Figure 4 is an activity flowchart of an example provided for the embodiments of the present application.
[0068] Figure 5 is an activity flowchart of another example provided for the embodiments of the present application.
[0069] Figure 6 is a flowchart of a process of determining whether a master instance is abnormal provided for an example of the present application.
[0070] Figure 7 is a block diagram of a business service providing apparatus according to an exemplary embodiment.
[0071] Figure 8 is a block diagram of a server according to an exemplary embodiment. DETAILED DESCRIPTION
[0072] In order for those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings.
[0073] It should be noted that the terms "first", "second", and the like in the specification and claims of the present disclosure and the above-described drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein. The implementation described in the following exemplary embodiments does not represent all implementations consistent with the present disclosure. Rather, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0074] In order to facilitate the understanding of the present disclosure, among the technical terms related to the present disclosure:
[0075] For example, an object providing a service can be represented as a process. A service can correspond to multiple instances, which are usually running in different servers, and each instance can provide the service independently.
[0076] The master instance refers to the instance that actually provides the service.
[0077] The slave instance refers to the instance other than the master instance.
[0078] The analysis instance refers to the instance that monitors whether the master instance is abnormal.
[0079] It should be noted that the role of each instance is not always the same, but will change over time, and an instance can also have the roles of slave and analysis instances.
[0080] Figure 1 is a schematic diagram of an architecture of a service system according to an exemplary embodiment, which includes at least two servers 11 and at least one storage device 12 (such as various types of databases), and each server 11 is connected to the storage device 12 through a communication network. Each server 11 starts an instance that can provide a service, and the identification and creation time of the instance can be stored in the storage device 11, and the active time of the instance can be stored in the storage device 11 periodically. Therefore, the storage device 11 stores instance information of each instance, which can include the identification, creation time and last active time of the instance.
[0081] The following will be described in conjunction with Figure 1 The service providing method provided by the embodiments of the present disclosure will be introduced.
[0082] Figure 2 is a flowchart of a service providing method according to an exemplary embodiment, as Figure 1 shown, the service providing method is used in each server 11, and the flowchart of the method includes the following steps.
[0083] In step S201, instance information of each instance is obtained from a storage device.
[0084] In step S202, whether the master instance is abnormal is determined according to the instance information of each instance.
[0085] Taking an example in which the instance information of each instance includes a creation time and a last active time of the instance.
[0086] In implementation, whether the locally started instance is the master instance can be determined based on the creation time of each instance and the creation time characteristics of the master instance. For example, if the creation time characteristics of the master instance are that the creation time is the earliest, the instance with the earliest creation time among the instances can be determined as the master instance; if the creation time characteristics of the master instance are that the creation time is the latest, the instance with the latest creation time among the instances can be determined as the master instance. In addition, each instance has an identifier, and the identifier of the locally started instance is compared with the identifier of the master instance. If they are the same, it means that the locally started instance is the master instance, and if they are not the same, it means that the locally started instance is not the master instance.
[0087] Then, when it is determined that the locally started instance is not the master instance, whether the master instance is abnormal is analyzed based on the last active time of the master instance.
[0088] In some embodiments, a time difference between a current time and the last active time of the master instance can be determined, and if the time difference is greater than a preset time length, it is determined that the master instance is abnormal. In this way, whether the master instance is abnormal can be quickly determined, which is beneficial to quickly switching the master instance when the master instance is abnormal and shortening the interruption time of the service.
[0089] In some embodiments, a time difference between a current time and the last active time of the master instance can be determined, and after it is determined that the time difference is greater than a preset time length, the preset time length is waited for, and then the last active time of the master instance is obtained from the storage device again. If the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, it is determined that the master instance is abnormal. In this way, the last active time of the master instance is confirmed twice, which can avoid misrecognition caused by different time synchronization between different servers, thereby improving the accuracy of the judgment of the abnormality of the master instance.
[0090] In some embodiments, the storage device also stores communication address information of each instance. At this time, after determining that the last active time of the current acquired master instance is the same as the last active time of the last acquired master instance, the communication address information of the master instance acquired from the storage device is also acquired, and then a heartbeat request is sent to the master instance based on the communication address information of the master instance. If the master instance does not respond to the heartbeat request, it is determined that the master instance is abnormal. In this way, both the last active time of the master instance is confirmed again and communication with the master instance is performed to determine whether the master instance is abnormal, which can further improve the accuracy of the abnormality judgment of the master instance.
[0091] In step S203, when it is determined that the master instance is abnormal, the master instance is reselected so that the reselected master instance provides the service.
[0092] In specific implementation, the instance information of each instance can be reacquired from the storage device, and the master instance is reselected from the instances other than the abnormal master instance based on the creation time of each instance and the creation time characteristics of the master instance, and the service is provided by the reselected master instance.
[0093] In addition, when the service system includes at least three servers, before analyzing whether the master instance is abnormal based on the last active time of the master instance, it can also be determined that the creation time of the locally started instance meets the creation time characteristics of the analysis instance. When the creation time characteristics of the master instance is the earliest creation time, the creation time characteristics of the analysis instance can be the second earliest creation time; when the creation time characteristics of the master instance is the latest creation time, the creation time characteristics of the analysis instance can be the second latest creation time.
[0094] That is, when there are at least three servers, it is not necessary for each slave instance other than the master instance to analyze whether the master instance is abnormal, but only the analysis instance in the slave instances needs to analyze whether the master instance is abnormal. In this way, the thundering herd effect that all slave instances will perceive the abnormality of the master instance and perform abnormal analysis when the master instance is abnormal can be avoided.
[0095] In the embodiments of the present disclosure, the instances other than the master instance can monitor the activity of the master instance, and the master instance is reselected to provide the service when the master instance is abnormal, so that the instances in the multiple servers can continuously provide the service without relying on external devices.
[0096] Figure 3 is a flowchart of another service providing method according to an example embodiment, as shown in Figure 1 The service providing method is used in any server 11, and the flowchart of the method includes the following steps.
[0097] In step S301, instance information of each instance is obtained from the storage device, and the instance information of each instance includes a creation time and a last active time.
[0098] In step S302, whether the locally started instance is the master instance is determined based on the creation time of each instance and the creation time feature of the master instance, if yes, step S303 is entered, and if no, step S304 is entered.
[0099] In step S303, the master instance provides a service.
[0100] In step S304, if it is determined that the creation time of the locally started instance meets the analysis of the creation time feature of the instance, whether the master instance is abnormal is analyzed based on the last active time of the master instance.
[0101] In step S305, when it is determined that the master instance is abnormal, the instance information of the master instance is deleted from the storage device.
[0102] In order to avoid selecting an abnormal master instance as a new master instance, the instance information of the master instance is deleted from the storage device when it is determined that the master instance is abnormal, considering that the instance information of each instance obtained from the storage device is also needed when the master instance is reselected.
[0103] In step S306, the master instance is reselected, so that the reselected master instance provides a service.
[0104] In specific implementation, the instance information of each instance can be reobtained from the storage device, the master instance is reselected from each instance based on the creation time of each instance and the creation time feature of the master instance, and the service is provided by the newly selected master instance.
[0105] In addition, in any of the above embodiments, when it is determined that the instance exit condition is met, the locally running instance can be exited, and the instance information of the instance can be deleted from the storage device, so as to avoid that the instance information of the exited instance remains in the storage device and affects the selection of the subsequent master instance.
[0106] The scheme of the embodiment of the present disclosure is described below taking the storage device mysql as an example.
[0107] Figure 4 An activity flowchart of an instance provided by the embodiment of the present application includes the following steps:
[0108] In step S401, the server starts an instance.
[0109] In step S402, a universally unique identifier (uuid) corresponding to the instance is generated as its identifier.
[0110] In step S403, the uuid and the creation time creat_time of the instance are saved into the mysql.
[0111] In step S404, a preset time length is waited.
[0112] The preset time length is, for example, 1 second.
[0113] In step S405, if it is determined that the instance is still alive, the update time update_time corresponding to the uuid in the mysql is updated as the current time.
[0114] The update_time is used for recording the last active time of the instance.
[0115] In step S406, it is judged whether the instance exit condition is met, if not, it returns to S404, and if yes, it enters S407.
[0116] In step S407, the instance information of the instance is deleted from the mysql.
[0117] The instance information includes the uuid, creat_time and update_time of the instance.
[0118] In step S408, the instance is exited.
[0119] Figure 5 An activity flowchart of another instance provided by the embodiment of the present application includes the following steps:
[0120] In step S501, the uuid, creat_time and update_time of all instances in the mysql are acquired.
[0121] In step S502, it is judged whether the uuid of the self is the uuid of the earliest main instance of the creat_time, if yes, it enters S507, and if not, it enters S503.
[0122] In step S503, it is judged whether the uuid of the self is the uuid of the second earliest analysis instance of the creat_time, if yes, it enters S504, and if not, it enters S505.
[0123] In step S504, it is judged whether the earliest main instance of the creat_time is abnormal, if yes, it enters S505, and if not, it enters S506.
[0124] Figure 6 A flowchart for judging whether the main instance is abnormal provided by the instance of the present application includes the following steps:
[0125] In step S601a, it is judged whether the time difference between the current time and the acquired update_time of the master instance is greater than t seconds, if yes, it goes to S608a, if not, it goes to S602a.
[0126] In step S602a, it waits for t seconds.
[0127] In step S603a, the update_time of the master instance is re-acquired.
[0128] In step S604a, it is judged whether the update_time of the master instance acquired this time is the same as the update_time of the master instance acquired last time, if yes, it goes to S605a, if not, it goes to S608a.
[0129] In step S605a, based on the communication address information of the master instance acquired from the mysql, a heartbeat request is sent to the master instance.
[0130] The communication address information is, for example, a network address and a port.
[0131] In step S606a, it is judged whether the heartbeat request is normally responded, if yes, it goes to S608a, if not, it goes to S607a.
[0132] In step S607a, it is determined that the master instance is abnormal.
[0133] In step S608a, it is determined that the master instance is normal.
[0134] In step S505, it waits for 1 second.
[0135] In step S506, the instance information of the master instance is deleted from the mysql.
[0136] In step S507, it is determined that itself is the master instance, and based on the master instance, a service is provided.
[0137] In step S508, it is judged whether the instance exit condition is met, if yes, it goes to S509, if not, it goes to S501.
[0138] In step S509, the instance running locally is exited.
[0139] The disclosed example has the following advantages:
[0140] 1. The decentralized master instance switching is realized by the instance in each server sharing the instance information in the storage device;
[0141] 2. The abnormality misjudgment of the master instance caused by the time inconsistency of different servers or the Network Time Protocol (NTP) jump can be avoided by the delayed confirmation, and the accuracy of the abnormality judgment of the master instance can be further improved by the point-to-point heartbeat confirmation.
[0142] 3. The stampede effect that all the remaining instances perceive and perform the abnormality judgment when the master instance is abnormal can be avoided by limiting that only the second early created instance performs the abnormality judgment.
[0143] Based on the same technical concept, the disclosure also provides a service providing apparatus. The principle of the service providing apparatus for solving the problem is similar to the above-mentioned service providing method, and therefore the implementation of the service providing apparatus can be referred to the implementation of the service providing method, and the repeated parts will not be described herein. Figure 7 is a block diagram of a service providing apparatus according to an exemplary embodiment. The service providing apparatus is applied to a service system, and the service system includes a storage device and at least two servers. An instance is started in each server, and the instance information of each instance is stored in the storage device. The apparatus is applied to any server and includes an obtaining unit 701, a determining unit 702, and a reselecting unit 703.
[0144] The obtaining unit 701 is configured to obtain the instance information of each instance from the storage device.
[0145] The determining unit 702 is configured to determine whether the master instance is abnormal according to the instance information of each instance.
[0146] The reselecting unit 703 is configured to reselect the master instance to make the reselected master instance provide the service when it is determined that the master instance is abnormal.
[0147] In some embodiments, the instance information of each instance includes the creation time and the last active time, and the determining unit 702 is specifically configured to:
[0148] Determine whether the locally started instance is the master instance based on the creation time of each instance and the creation time characteristics of the master instance.
[0149] If it is determined that the locally started instance is not the master instance, analyze whether the master instance is abnormal based on the last active time of the master instance.
[0150] In some embodiments, the service system includes at least three servers, and the determining unit 702 is further configured to:
[0151] Before analyzing whether the master instance is abnormal based on the last active time of the master instance, it is determined that the creation time of the locally started instance meets the creation time feature of the analysis instance.
[0152] In some embodiments, the determining unit 702 is specifically configured to perform:
[0153] determining a time difference between a current time and the last active time of the master instance;
[0154] if the time difference is greater than a preset time length, determining that the master instance is abnormal.
[0155] In some embodiments, the determining unit 702 is further configured to perform:
[0156] after determining that the time difference is greater than the preset time length, waiting for the preset time length;
[0157] obtaining the last active time of the master instance from the storage device;
[0158] if the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, determining that the master instance is abnormal.
[0159] In some embodiments, the storage device also stores communication address information of each instance, and the determining unit 702 is further configured to perform:
[0160] after determining that the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, sending a heartbeat request to the master instance based on the communication address information of the master instance obtained from the storage device;
[0161] if the master instance does not respond to the heartbeat request, determining that the master instance is abnormal.
[0162] In some embodiments, further comprising:
[0163] a deleting unit 704 configured to perform deleting instance information of the master instance from the storage device when it is determined that the master instance is abnormal.
[0164] In some embodiments, further comprising:
[0165] a service unit 705 configured to perform providing service based on the master instance if it is determined that the locally started instance is the master instance.
[0166] In some embodiments, further comprising:
[0167] The exiting unit 706 is configured to, when it is determined that the instance exit condition is met, exit the locally running instance and delete the instance information of the instance from the storage device.
[0168] As to the apparatus in the above-described embodiments, in which various units perform the specific functions as requested, the detailed description has been given in the embodiments about the method, and thus will not be repeated here.
[0169] After introducing the service providing method and apparatus of the exemplary embodiments of the present disclosure, next, a server according to another exemplary embodiment of the present disclosure is introduced.
[0170] In some possible embodiments, the server according to the present disclosure can include at least one processor and at least one memory. The memory stores program codes which, when executed by the processor, cause the processor to perform the method according to various exemplary embodiments of the present disclosure described above in the specification. For example, the processor can perform the steps in the service providing method.
[0171] The server 130 according to this embodiment of the present disclosure is described below with reference to Figure 8 . Figure 8 The server 130 shown is merely an example, and should not bring any limitation to the functions and usage range of the embodiments of the present disclosure.
[0172] As shown in Figure 8 , the server 130 is in the form of a general-purpose server. The components of the server 130 can include, but are not limited to, the above-mentioned at least one processor 131, the above-mentioned at least one memory 132, and a bus 133 connecting different system components, including the memory 132 and the processor 131.
[0173] The bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor or local bus using any of a variety of bus structures.
[0174] The memory 132 can include a readable medium in the form of volatile memory, such as a random access memory (RAM) 1321 and / or a cache memory 1322, and can further include a read-only memory (ROM) 1323.
[0175] The memory 132 can further include a program / utility 1325 having a set of program modules 1324, including but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which can include an implementation of a network environment, or a combination of some of these examples.
[0176] The server 130 can also be in communication with one or more external devices 134 such as a keyboard, a pointing device, etc.; can also be in communication with one or more devices that enable a user to interact with the server 130; and / or can be in communication with any devices (such as routers, modems, etc.) that enable the server 130 to communicate with one or more other servers. Such communication can be via Input / Output (I / O) interface 135. Still yet, the server 130 can be in communication with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or the Internet) through network adapter 136. As an example, the network adapter 136 can be capable of communicating with the other modules of the server 130 through bus 133. It should be appreciated that although not shown, other hardware and / or software modules could be used in conjunction with the server 130. For example, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data archival storage systems, etc. can be used with the server 130.
[0177] The embodiments of the present disclosure further provide a storage medium including instructions, which, when executed by a processor of a server, enable the server to perform any of the above-mentioned business service providing methods. Optionally, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0178] The embodiments of the present disclosure further provide a computer program product, which, when invoked to execute by a server, enables the server to perform any of the above-mentioned business service providing methods.
[0179] Other embodiments of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the aspects of the present disclosure disclosed herein. It is intended that the present disclosure cover any and all variations of the present disclosure including combinations of features falling within the general scope of the disclosure. The specification and examples given are intended as illustrative only and not restrictive of the true scope and spirit of the present disclosure, which is set forth in the following claims.
[0180] It should be understood that the present disclosure is not limited to the precise structures herein described and illustrated, and that various modifications and changes can be made without departing from the scope of the present disclosure. The scope of the present disclosure is limited only by the claims that follow.
Claims
1. A method for providing business services, characterized in that, The method is applied to a business system, which includes a storage device and at least three servers, each server running an instance. The storage device stores instance information for each instance, including its creation time and last active time. Each of the servers obtains instance information for each instance from the storage device; Based on the creation time of each instance and the creation time characteristics of the primary instance, it is determined whether the locally started instance is the primary instance; wherein, the creation time characteristics of the primary instance are the earliest or latest creation time; If it is determined that the locally started instance is not the primary instance, then it is determined whether the creation time of the locally started instance matches the creation time characteristics of the analysis instance; wherein, if the creation time characteristic of the primary instance is the earliest creation time, and the creation time characteristic of the analysis instance is the second earliest creation time, then it matches the creation time characteristics of the analysis instance; or, if the creation time characteristic of the primary instance is the latest creation time, and the creation time characteristic of the analysis instance is the second latest creation time, then it matches the creation time characteristics of the analysis instance. If the creation time of the locally started instance matches the creation time characteristics of the analyzed instance, then analyze whether the main instance has an anomaly based on the last active time of the main instance. When it is determined that the primary instance is abnormal, a new primary instance is selected so that the newly selected primary instance can provide business services. When the instance exit conditions are met, the locally running instance is exited, and the instance information of the instance is deleted from the storage device to avoid the instance information of the exited instance remaining in the storage device and affecting the selection of the subsequent primary instance.
2. The method according to claim 1, characterized in that, Based on the last active time of the primary instance, analyze whether the primary instance has experienced any abnormalities, including: Determine the time difference between the current time and the last active time of the main instance; If the time difference is greater than the preset duration, it is determined that the main instance has malfunctioned.
3. The method according to claim 2, characterized in that, After determining that the time difference is greater than a preset duration, the process further includes: Waiting for the preset time; Obtain the last active time of the primary instance from the storage device; If the last active time of the main instance obtained this time is the same as the last active time of the main instance obtained last time, then it is determined that the main instance is abnormal.
4. The method according to claim 3, characterized in that, The storage device also stores the communication address information of each instance. After determining that the last active time of the main instance obtained this time is the same as the last active time of the main instance obtained last time, the method further includes: Based on the communication address information of the primary instance obtained from the storage device, a heartbeat request is sent to the primary instance; If the primary instance does not respond to the heartbeat request, it is determined that the primary instance is abnormal.
5. The method according to claim 1, characterized in that, When it is determined that the main instance has encountered an anomaly, the following is also included: Delete the instance information of the primary instance from the storage device.
6. The method according to claim 1, characterized in that, Also includes: If it is determined that the locally started instance is the primary instance, then business services are provided based on the primary instance.
7. A service provisioning apparatus, characterized in that, The device is applied to a business system, which includes a storage device and at least three servers, each server running an instance. The storage device stores instance information for each instance, including its creation time and last active time. The device is applied to any one of the servers and includes: The acquisition unit is configured to acquire instance information of each instance from the storage device; The determining unit is configured to determine whether a locally started instance is a primary instance based on the creation time of each instance and the creation time characteristics of the primary instance; wherein the creation time characteristics of the primary instance are the earliest or latest creation time. If it is determined that the locally started instance is not the primary instance, then it is determined whether the creation time of the locally started instance matches the creation time characteristics of the analysis instance; wherein, if the creation time characteristic of the primary instance is the earliest creation time, and the creation time characteristic of the analysis instance is the second earliest creation time, then it matches the creation time characteristics of the analysis instance; or, if the creation time characteristic of the primary instance is the latest creation time, and the creation time characteristic of the analysis instance is the second latest creation time, then it matches the creation time characteristics of the analysis instance. If the creation time of the locally started instance matches the creation time characteristics of the analyzed instance, then analyze whether the main instance has an anomaly based on the last active time of the main instance. The reselection unit is configured to reselect a primary instance when it is determined that the primary instance has encountered an error, so that the reselected primary instance can provide business services. The exit unit is configured to exit the locally running instance and delete the instance information from the storage device when it is determined that the instance exit conditions are met, so as to avoid the instance information of the exited instance remaining in the storage device and affecting the selection of the subsequent primary instance.
8. The apparatus according to claim 7, characterized in that, The determining unit is specifically configured to execute: Determine the time difference between the current time and the last active time of the main instance; If the time difference is greater than the preset duration, it is determined that the main instance has malfunctioned.
9. The apparatus according to claim 8, characterized in that, The determining unit is also configured to perform: After determining that the time difference is greater than a preset duration, wait for the preset duration; Obtain the last active time of the primary instance from the storage device; If the last active time of the main instance obtained this time is the same as the last active time of the main instance obtained last time, then it is determined that the main instance is abnormal.
10. The apparatus according to claim 9, characterized in that, The storage device also stores the communication address information of each instance, and the determining unit is further configured to execute: After determining that the last active time of the master instance obtained this time is the same as the last active time of the master instance obtained last time, a heartbeat request is sent to the master instance based on the communication address information of the master instance obtained from the storage device. If the primary instance does not respond to the heartbeat request, it is determined that the primary instance is abnormal.
11. The apparatus according to claim 7, characterized in that, Also includes: The deletion unit is configured to delete the instance information of the primary instance from the storage device when it is determined that the primary instance has encountered an error.
12. The apparatus according to claim 8, characterized in that, Also includes: The service unit is configured to perform business services based on the primary instance if the locally started instance is determined to be the primary instance based on the creation time of each instance and the creation time of the primary instance.
13. A server, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the service provision method as described in any one of claims 1 to 6.
14. A storage medium, characterized in that, When the instructions in the storage medium are executed by the server's processor, the server is able to perform the service provision method as described in any one of claims 1 to 6.
15. A computer program product, characterized in that, When a computer program product is invoked and executed by a server, the server performs the business service provision method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Micro-service instance exit method and device, equipment and storage medium
CN112799786A
Service state switching method and device, server and storage medium
CN113467953A